Class SplitInputStreamImpl

java.lang.Object
java.io.InputStream
com.pervasive.datarush.io.BinaryReader
com.pervasive.datarush.io.SplitInputStreamImpl
All Implemented Interfaces:
SplitInputStream, Closeable, AutoCloseable

public class SplitInputStreamImpl extends BinaryReader implements SplitInputStream
A wrapper for input streams providing windowing behavior. Reads start at the first byte of the window. Readers may continue reading as far as the end of the source, although the stream does keep track of whether the reader has has passed the end of the window.
  • Field Details

    • DEFAULT_BUFFER

      public static final int DEFAULT_BUFFER
      The default size for the read buffer, in bytes.
      See Also:
    • splitStart

      protected final long splitStart
    • splitEnd

      protected final long splitEnd
  • Constructor Details

    • SplitInputStreamImpl

      public SplitInputStreamImpl(InputStream source, long startOffset, long endOffset) throws IOException
      Create a new input stream for the specified split. I/O is performed using buffers of size DEFAULT_BUFFER. The resulting stream will be positioned the beginning of the window.

      As I/O is buffered, it is neither necessary nor preferable to use a BufferedInputStream as the source.

      Parameters:
      source - the stream providing the split data
      startOffset - the position of the first byte in the window; this is relative to the starting position of source.
      endOffset - the position of the last byte in the window, exclusive; this is relative to the starting position of source.
      Throws:
      IOException - if errors occur opening the split data source
    • SplitInputStreamImpl

      public SplitInputStreamImpl(InputStream source, long startOffset, long endOffset, int bufferSize) throws IOException
      Create a new input stream for the specified window. I/O is performed using the specified buffer size. The resulting stream will be positioned the beginning of the window.

      As I/O is buffered, it is neither necessary nor preferable to use a BufferedInputStream as the source.

      Parameters:
      source - the stream providing the split data
      startOffset - the position of the first byte in the window; this is relative to the starting position of source.
      endOffset - the position of the last byte in the window, exclusive; this is relative to the starting position of source.
      bufferSize - the size of the I/O buffer to use for reads, in bytes
      Throws:
      IOException - if errors occur opening the split data source
  • Method Details

    • moveToSplit

      protected void moveToSplit() throws IOException
      Throws:
      IOException
    • fillBuffer

      protected int fillBuffer() throws IOException
      Description copied from class: BinaryReader
      Fills the working buffer
      Overrides:
      fillBuffer in class BinaryReader
      Throws:
      IOException
    • availableInSplit

      public long availableInSplit()
      Gets the number of bytes remaining in the split.
      Specified by:
      availableInSplit in interface SplitInputStream
      Returns:
      the number of bytes left to read in the split. If the split has been completely read, this is 0.
    • overrunPastSplit

      public long overrunPastSplit()
      Gets the number of bytes which have been read beyond the end of the split.
      Returns:
      the number of bytes read which were outside of the split. If there are still available bytes in the split, this is 0.
    • hasOverrun

      public boolean hasOverrun()
      Indicates whether the reader has read past the end of the split.
      Specified by:
      hasOverrun in interface SplitInputStream
      Returns:
      true if all bytes in the split has been read, false if any remain.
    • skipTo

      public boolean skipTo(byte[] bytes) throws IOException
      Advances the position of the stream to the first byte after the specified pattern.
      Parameters:
      bytes - the pattern to find in the stream
      Returns:
      false if end of data is reached, true otherwise.
      Throws:
      IOException - if an I/O error occurs while reading the stream