Class ParserPipe
- All Implemented Interfaces:
Closeable,AutoCloseable
For character-based parsers, the input object can be any of the following:
ReaderCharSequenceInputStreambyte []Filenull
For stream-based parsers, the input object can be any of the following:
InputStreambyte []FileString- 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
ConstructorsConstructorDescriptionParserPipe(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.voidclose()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.booleanisString()Returnstrue if the contents passed into this pipe was aCharSequence.voidsetPositionable(Positionable positionable) Sets the ParserReader/ParserInputStream/XmlReader constructed from this pipe.
-
Constructor Details
-
ParserPipe
Shortcut constructor, typically for straight string input.Equivalent to calling
new ParserPipe(input,false ,false ,null ,null );- Parameters:
input- The input object.
-
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 closeInputStreamsandReaderswhen 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
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.REPORTonCharsetDecoder.onMalformedInput(CodingErrorAction)andCharsetDecoder.onUnmappableCharacter(CodingErrorAction). Otherwise, sets them toCodingErrorAction.REPLACE.autoCloseStreams- Automatically closeInputStreamsandReaderswhen 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.
-
-
Method Details
-
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.
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
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.
-
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.
-
getParserReader
Converts this pipe into aParserReader.- Returns:
- The converted pipe.
- Throws:
IOException- Thrown by underlying 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.
-
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
ParseExceptionis thrown.- Parameters:
positionable- The ParserReader/ParserInputStream/XmlReader constructed from this pipe.
-