| 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.trans.XPathException; |
| 11 | |
| 12 | /** |
| 13 | * A PullConsumer consumes all the events supplied by a PullProvider, doing nothing |
| 14 | * with them. The class exists so that PullFilters on the pipeline can produce side-effects. |
| 15 | * For example, this class can be used to validate a document, where the side effects are |
| 16 | * error messages. |
| 17 | */ |
| 18 | |
| 19 | public class PullConsumer { |
| 20 | |
| 21 | private PullProvider in; |
| 22 | |
| 23 | /** |
| 24 | * Create a PullConsumer that swallows the events read from a given pull provider |
| 25 | * |
| 26 | * @param in the PullProvider from which events are to be read and swallowed up |
| 27 | */ |
| 28 | |
| 29 | public PullConsumer(PullProvider in) { |
| 30 | this.in = in; |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Consume the input |
| 35 | * |
| 36 | * @throws net.sf.saxon.trans.XPathException if (for example) the parser input is not well-formed |
| 37 | * |
| 38 | */ |
| 39 | |
| 40 | public void consume() throws XPathException { |
| 41 | while (true) { |
| 42 | if (in.next() == PullProvider.END_OF_INPUT) { |
| 43 | return; |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 |