Class PositionedInputStream

All Implemented Interfaces:
Closeable, AutoCloseable
Direct Known Subclasses:
MolInputStream

@PublicApi public class PositionedInputStream extends BufferedInputStream
Positioned input stream that has the ability to set / get the stream position as well as put back some parts already read.
Since:
Marvin 4.0, 02/25/2005
  • Field Details

    • lineByteBuffer

      protected ByteBuffer lineByteBuffer
      Lines are read into this buffer.
      See Also:
    • lineCurrentColumn

      protected int lineCurrentColumn
      Column position of the next character to read.
    • keeporiginalLineEnding

      protected boolean keeporiginalLineEnding
    • encoding

      protected Encoding encoding
      The encoding.
      Since:
      Marvin 5.0, 11/10/2007
  • Constructor Details

    • PositionedInputStream

      public PositionedInputStream(InputStream is) throws IOException
      Constructor. It tries to read 1024 bytes into the buffer and to recognize the character encoding.
      Parameters:
      is - the original input stream
      Throws:
      IOException
    • PositionedInputStream

      public PositionedInputStream(InputStream is, int size) throws IOException
      Constructor. It tries to read 1024 bytes into the buffer and to recognize the character encoding.
      Parameters:
      is - the original input stream
      size - the buffer size
      Throws:
      IOException
    • PositionedInputStream

      public PositionedInputStream(InputStream is, String enc) throws IOException
      Constructor. It tries to read 1024 bytes into the buffer and to recognize the character encoding if it is not specified (null).
      Parameters:
      is - the original input stream
      enc - the character encoding or null
      Throws:
      IOException
      Since:
      Marvin 3.5.5
    • PositionedInputStream

      public PositionedInputStream(InputStream is, int size, String enc) throws IOException
      Constructor. It tries to read 1024 bytes into the buffer and to recognize the character encoding if it is not specified (null).
      Parameters:
      is - the original input stream
      size - the buffer size
      enc - the character encoding or null
      Throws:
      IOException
      Since:
      Marvin 3.5.5
    • PositionedInputStream

      protected PositionedInputStream(InputStream is, int size, String enc, int initialChunkSize) throws IOException
      Constructor.
      Parameters:
      is - the original input stream
      size - the buffer size
      enc - the character encoding or null
      initialChunkSize - number of bytes to read in advance for encoding recognition
      Throws:
      IOException
      Since:
      Marvin 5.0, 11/10/2007
  • Method Details

    • setDesiredBufferSize

      public void setDesiredBufferSize(int size)
      Sets desired buffer size.
      Parameters:
      size - the desired buffer size
    • read

      public int read() throws IOException
      Reads a character. Warning! This method does not update the line number.
      Overrides:
      read in class BufferedInputStream
      Returns:
      the character
      Throws:
      IOException - read error occurred
    • bufincRead

      protected final int bufincRead() throws IOException
      Reads a character and writes into the buffer. Increases the buffer size if it becomes full.
      Returns:
      the character
      Throws:
      IOException - in case of read error
    • read

      public int read(byte[] b, int off, int len) throws IOException
      Reads a byte array. Warning! This method does not update the line number.
      Overrides:
      read in class BufferedInputStream
      Parameters:
      b - the buffer into which the data is read.
      off - the start offset of the data
      len - maximum number of bytes to read
      Returns:
      the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
      Throws:
      IOException - read error occurred
    • skip

      public long skip(long n) throws IOException
      Skips over and discards n bytes of data. Warning! This method does not update the line number.
      Overrides:
      skip in class BufferedInputStream
      Parameters:
      n - the number of bytes
      Returns:
      the number of skipped bytes
      Throws:
      IOException - read error occurred
    • reset

      public void reset() throws IOException
      Repositions this stream to the position at the time the mark method was last called on this input stream.
      Overrides:
      reset in class BufferedInputStream
      Throws:
      IOException - if this stream has not been marked or if the mark has been invalidated.
    • clearMark

      public void clearMark()
      Disables the mark (if any) on this stream. After calling this method, reset() will fail, unless BufferedInputStream.mark(int) is called before that.
    • startGrabLines

      @Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2026) public final void startGrabLines()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Starts grabbing lines. Lines will be grabbed while reading them at each readLine call. The resulting text will be separated by \n characters (UNIX line separator).
      Since:
      Marvin 4.0, 01/05/2005
      See Also:
    • endGrabLines

      @Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2026) public final String endGrabLines()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Ends grabbing lines.
      Returns:
      the grabbed lines
      Since:
      Marvin 4.0, 01/05/2005
    • getGrabbedLines

      @Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2026) public final String getGrabbedLines()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Gets the grabbed lines.
      Returns:
      the grabbed lines
      Since:
      Marvin 4.0, 01/05/2005
    • readLine

      public String readLine() throws IOException
      Reads a line.
      Returns:
      the line without the line separator character(s)
      Throws:
      IOException - If an I/O error has occurred.
    • skipLine

      public boolean skipLine() throws IOException
      Skips the next line. The skipped line is not stored and cannot be put back into the stream. Moreover, line grabbing is disabled.
      Returns:
      true if a line was skipped successfully, false at end of file
      Throws:
      IOException - If an I/O error has occurred.
      Since:
      Marvin 5.1.3, 10/18/2008
    • getWord

      protected int getWord(ByteBuffer bb, int i)
    • setWord

      protected void setWord(ByteBuffer bb, int i, int c)
    • getLineCount

      public final int getLineCount()
      Gets the current line number. Only lines read with readLine() are counted.
      Returns:
      the line number
    • putBackLine

      public final void putBackLine() throws IOException
      Puts back the last line into the stream. Also repositions the file pointer.
      Throws:
      IOException - If an I/O error has occurred.
      See Also:
    • putBackLine

      public final void putBackLine(int col) throws IOException
      Puts back the last line into the stream. Also repositions the file pointer.
      Parameters:
      col - put back the substring starting at this column
      Throws:
      IOException - If an I/O error has occurred.
      Since:
      Marvin 5.0.1, 01/12/2008
      See Also:
    • resetFilePointer

      protected final void resetFilePointer()
      Resets file pointer to zero.
    • getFilePointer

      public final long getFilePointer()
      Get the file pointer.
      Returns:
      the file pointer
    • isSeekable

      public boolean isSeekable()
      Tests whether the stream is seekable.
      Returns:
      true if the stream is seekable, false otherwise
      Since:
      Marvin 4.1, 04/13/2006
    • seek

      public void seek(long p, int lcount) throws IOException
      Sets the file-pointer offset, measured from the beginning of this file, at which the next read or write occurs.

      Seeking forward is always supported. If the stream is marked, then seeking backward until the marked position is also supported. Seeking further backward is only supported if isSeekable() returns true.

      Parameters:
      p - the offset position
      lcount - the line count at the specified position
      Throws:
      IOException - if pos is less than 0 or if an I/O error occurs.
      Since:
      Marvin 4.1, 04/13/2006
    • length

      public long length() throws IOException
      Gets the file length.
      Returns:
      the file length
      Throws:
      IOException - if the file length cannot be determined
      Since:
      Marvin 4.1, 04/18/2006
    • getEncoding

      public final Encoding getEncoding()
      Gets the encoding.
      Returns:
      the encoding or null
      Since:
      Marvin 5.0, 11/20/2007
    • setEncoding

      public final void setEncoding(Encoding enc)
      Sets the encoding.
      Parameters:
      enc - the encoding
      Since:
      Marvin 5.0, 11/20/2007
    • setEncoding

      public final void setEncoding(String enc)
      Sets the encoding.
      Parameters:
      enc - the encoding
      Throws:
      IllegalCharsetNameException - if the encoding is illegal
      UnsupportedCharsetException - if the encoding is unsupported
    • setByteOrder

      protected void setByteOrder(ByteBuffer bb)
    • getLastEOL

      public String getLastEOL()