Debian Codegraph @

net/sf/saxon/pull/PullPushCopier.java

raw symbols SCIP
1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2018 Saxonica Limited.
3 // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4 // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
6 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7
8 package net.sf.saxon.pull;
9
10 import net.sf.saxon.event.Receiver;
11 import net.sf.saxon.trans.XPathException;
12
13 /**
14 * This class copies a document by using the pull interface to read the input document,
15 * and the push interface to write the output document.
16 */
17 public class PullPushCopier {
18
19 private PullProvider in;
20 private Receiver out;
21
22 /**
23 * Create a PullPushCopier
24 *
25 * @param in a PullProvider from which events will be read
26 * @param out a Receiver to which copies of the same events will be written
27 */
28
29 public PullPushCopier(PullProvider in, Receiver out) {
30 this.out = out;
31 this.in = in;
32 }
33
34 /**
35 * Copy the input to the output. This method will open the output Receiver before appending to
36 * it, and will close it afterwards.
37 *
38 * @throws XPathException if, for example, the input is not well-formed
39 */
40
41 public void copy() throws XPathException {
42 out.open();
43 PullPushTee tee = new PullPushTee(in, out);
44 new PullConsumer(tee).consume();
45 out.close();
46 }
47
48 /**
49 * Copy the input to the output. This method relies on the caller to open the output Receiver before
50 * use and to close it afterwards.
51 *
52 * @throws XPathException if, for example, the input is not well-formed
53 */
54
55 public void append() throws XPathException {
56 PullPushTee tee = new PullPushTee(in, out);
57 new PullConsumer(tee).consume();
58 }
59 }
60