Class ParserPipe

java.lang.Object
org.apache.juneau.parser.ParserPipe
All Implemented Interfaces:
Closeable, AutoCloseable

public final class ParserPipe extends Object implements Closeable
A wrapper around an object that a parser reads its input from.

For character-based parsers, the input object can be any of the following:

For stream-based parsers, the input object can be any of the following:

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 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 - If true, the input contents will be copied locally and accessible via the getInputAsString() method. This allows the contents of the pipe to be accessed when a problem occurs.
      strict - If true, sets 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 true, 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 from Files.
      streamCharset - The charset to expect when reading from InputStreams.
    • 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 - If true, the input contents will be copied locally and accessible via the 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 true, 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)
      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

      public Reader getReader() throws IOException
      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

      public String asString() throws IOException
      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 a ParserReader.
      Returns:
      The converted pipe.
      Throws:
      IOException - Thrown by underlying stream.
    • isString

      public boolean isString()
      Returns true if the contents passed into this pipe was a CharSequence.
      Returns:
      true if the contents passed into this pipe was a CharSequence.
    • setPositionable

      public void setPositionable(Positionable positionable)
      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

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable