public final class ParserPipe extends Object implements Closeable
For character-based parsers, the input object can be any of the following:
Reader
CharSequence
InputStream
byte []
File
null
For stream-based parsers, the input object can be any of the following:
InputStream
byte []
File
String - Hex-encoded bytes. (not BASE-64!)
null
Note that Readers and InputStreams will NOT be automatically closed when close() is called, but
streams and readers created from other types (e.g. Files) WILL be automatically closed.
| Constructor and Description |
|---|
ParserPipe(Object input)
Shortcut constructor, typically for straight string input.
|
ParserPipe(Object input,
boolean debug,
boolean autoCloseStreams,
boolean unbuffered,
BinaryFormat binaryFormat)
Constructor for stream-based parsers.
|
ParserPipe(Object input,
boolean debug,
boolean strict,
boolean autoCloseStreams,
boolean unbuffered,
Charset streamCharset,
Charset fileCharset)
Constructor for reader-based parsers.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
Reader |
getBufferedReader()
Returns the contents of this pipe as a buffered reader.
|
String |
getInputAsString()
Returns the input to this parser as a plain string.
|
InputStream |
getInputStream()
Wraps the specified input object inside an input stream.
|
ParserReader |
getParserReader()
Converts this pipe into a
ParserReader. |
Reader |
getReader()
Wraps the specified input object inside a reader.
|
boolean |
isString()
Returns
CharSequence. |
void |
setPositionable(Positionable positionable)
Sets the ParserReader/ParserInputStream/XmlReader constructed from this pipe.
|
public ParserPipe(Object input, boolean debug, boolean strict, boolean autoCloseStreams, boolean unbuffered, Charset streamCharset, Charset fileCharset)
input - The parser input object.debug - If getInputAsString()
method.
This allows the contents of the pipe to be accessed when a problem occurs.strict - If CodingErrorAction.REPORT on CharsetDecoder.onMalformedInput(CodingErrorAction)
and CharsetDecoder.onUnmappableCharacter(CodingErrorAction).
Otherwise, sets them to CodingErrorAction.REPLACE.autoCloseStreams - Automatically close InputStreams and Readers when passed in as input.unbuffered - If fileCharset - The charset to expect when reading from Files.streamCharset - The charset to expect when reading from InputStreams.public ParserPipe(Object input, boolean debug, boolean autoCloseStreams, boolean unbuffered, BinaryFormat binaryFormat)
input - The parser input object.debug - If getInputAsString()
method.
This allows the contents of the pipe to be accessed when a problem occurs.autoCloseStreams - Automatically close InputStreams and Readers when passed in as input.unbuffered - If binaryFormat - The binary format of input strings when converted to bytes.public ParserPipe(Object input)
Equivalent to calling
input - The input object.public InputStream getInputStream() throws IOException
Subclasses can override this method to implement their own input streams.
IOException - If object could not be converted to an input stream.public Reader getReader() throws IOException
Subclasses can override this method to implement their own readers.
IOException - If object could not be converted to a reader.public Reader getBufferedReader() throws IOException
If the reader passed into this pipe is already a buffered reader, that reader will be returned.
IOException - Thrown by underlying stream.public String getInputAsString()
This method only returns a value if BeanContext.BEAN_debug is enabled.
public ParserReader getParserReader() throws IOException
ParserReader.IOException - Thrown by underlying stream.public boolean isString()
CharSequence.CharSequence.public void setPositionable(Positionable positionable)
Used for gathering the failure position when ParseException is thrown.
positionable - The ParserReader/ParserInputStream/XmlReader constructed from this pipe.public void close()
close in interface Closeableclose in interface AutoCloseableCopyright © 2016–2019 The Apache Software Foundation. All rights reserved.