Class ParserPipe
- All Implemented Interfaces:
Closeable
,AutoCloseable
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.
See Also:
-
Constructor Summary
ConstructorDescriptionParserPipe
(Object input) Shortcut constructor, typically for straight string input.ParserPipe
(Object input, boolean debug, boolean strict, boolean autoCloseStreams, boolean unbuffered, Charset streamCharset, Charset fileCharset) Constructor for reader-based parsers.ParserPipe
(Object input, boolean debug, boolean autoCloseStreams, boolean unbuffered, BinaryFormat binaryFormat) Constructor for stream-based parsers. -
Method Summary
Modifier and TypeMethodDescriptionasString()
Returns the contents of this pipe as a string.void
close()
Returns the contents of this pipe as a buffered reader.Returns the input to this parser as a plain string.Wraps the specified input object inside an input stream.Converts this pipe into aParserReader
.Wraps the specified input object inside a reader.boolean
isString()
Returnstrue if the contents passed into this pipe was aCharSequence
.void
setPositionable
(Positionable positionable) Sets the ParserReader/ParserInputStream/XmlReader constructed from this pipe.
-
Constructor Details
-
ParserPipe
public ParserPipe(Object input, boolean debug, boolean strict, boolean autoCloseStreams, boolean unbuffered, Charset streamCharset, Charset fileCharset) Constructor for reader-based parsers.- Parameters:
input
- The parser input object.debug
- Iftrue , the input contents will be copied locally and accessible via thegetInputAsString()
method. This allows the contents of the pipe to be accessed when a problem occurs.strict
- Iftrue , setsCodingErrorAction.REPORT
onCharsetDecoder.onMalformedInput(CodingErrorAction)
andCharsetDecoder.onUnmappableCharacter(CodingErrorAction)
. Otherwise, sets them toCodingErrorAction.REPLACE
.autoCloseStreams
- Automatically closeInputStreams
andReaders
when passed in as input.unbuffered
- Iftrue , we read one character at a time from underlying readers when the readers are expected to be parsed multiple times.
Otherwise, we read character data into a reusable buffer.fileCharset
- The charset to expect when reading fromFiles
.streamCharset
- The charset to expect when reading fromInputStreams
.
-
ParserPipe
public ParserPipe(Object input, boolean debug, boolean autoCloseStreams, boolean unbuffered, BinaryFormat binaryFormat) Constructor for stream-based parsers.- Parameters:
input
- The parser input object.debug
- Iftrue , the input contents will be copied locally and accessible via thegetInputAsString()
method. This allows the contents of the pipe to be accessed when a problem occurs.autoCloseStreams
- Automatically closeInputStreams
andReaders
when passed in as input.unbuffered
- Iftrue , we read one character at a time from underlying readers when the readers are expected to be parsed multiple times.
Otherwise, we read character data into a reusable buffer.binaryFormat
- The binary format of input strings when converted to bytes.
-
ParserPipe
Shortcut constructor, typically for straight string input.Equivalent to calling
new ParserPipe(input,false ,false ,null ,null );- Parameters:
input
- The input object.
-
-
Method Details
-
getInputStream
Wraps the specified input object inside an input stream.Subclasses can override this method to implement their own input streams.
- Returns:
- The input object wrapped in an input stream, or
null if the object is null. - Throws:
IOException
- If object could not be converted to an input stream.
-
getReader
Wraps the specified input object inside a reader.Subclasses can override this method to implement their own readers.
- Returns:
- The input object wrapped in a Reader, or
null if the object is null. - Throws:
IOException
- If object could not be converted to a reader.
-
getBufferedReader
Returns the contents of this pipe as a buffered reader.If the reader passed into this pipe is already a buffered reader, that reader will be returned.
- Returns:
- The contents of this pipe as a buffered reader.
- Throws:
IOException
- Thrown by underlying stream.
-
getInputAsString
Returns the input to this parser as a plain string.This method only returns a value if
Context.Builder.debug()
is enabled.- Returns:
- The input as a string, or
null if debug mode not enabled.
-
asString
Returns the contents of this pipe as a string.- Returns:
- The contents of this pipe as a string.
- Throws:
IOException
- If thrown from inner reader.
-
getParserReader
Converts this pipe into aParserReader
.- Returns:
- The converted pipe.
- Throws:
IOException
- Thrown by underlying stream.
-
isString
Returnstrue if the contents passed into this pipe was aCharSequence
.- Returns:
true if the contents passed into this pipe was aCharSequence
.
-
setPositionable
Sets the ParserReader/ParserInputStream/XmlReader constructed from this pipe.Used for gathering the failure position when
ParseException
is thrown.- Parameters:
positionable
- The ParserReader/ParserInputStream/XmlReader constructed from this pipe.
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-