java.lang.Object
java.io.InputStream
com.pervasive.datarush.io.BinaryReader
com.pervasive.datarush.io.SplitInputStreamImpl
- All Implemented Interfaces:
SplitInputStream,Closeable,AutoCloseable
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe default size for the read buffer, in bytes.protected final longprotected final longFields inherited from class com.pervasive.datarush.io.BinaryReader
absolutePosition, buffer, position, size, source -
Constructor Summary
ConstructorsConstructorDescriptionSplitInputStreamImpl(InputStream source, long startOffset, long endOffset) Create a new input stream for the specified split.SplitInputStreamImpl(InputStream source, long startOffset, long endOffset, int bufferSize) Create a new input stream for the specified window. -
Method Summary
Modifier and TypeMethodDescriptionlongGets the number of bytes remaining in the split.protected intFills the working bufferbooleanIndicates whether the reader has read past the end of the split.protected voidlongGets the number of bytes which have been read beyond the end of the split.booleanskipTo(byte[] bytes) Advances the position of the stream to the first byte after the specified pattern.Methods inherited from class com.pervasive.datarush.io.BinaryReader
available, close, getAbsolutePosition, isEmpty, loadNextBuffer, mark, markSupported, read, read, read, readBase128Int, readBase128Long, readByte, readBytes, readChar, readChars, readDouble, readFloat, readInt, readLong, readSingleByteChars, readUnsignedBase128Int, readUnsignedBase128Long, reset, skip, skipBytes, toStringMethods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferToMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.pervasive.datarush.io.SplitInputStream
close, read
-
Field Details
-
DEFAULT_BUFFER
public static final int DEFAULT_BUFFERThe 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 sizeDEFAULT_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
BufferedInputStreamas the source.- Parameters:
source- the stream providing the split datastartOffset- the position of the first byte in the window; this is relative to the starting position ofsource.endOffset- the position of the last byte in the window, exclusive; this is relative to the starting position ofsource.- 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
BufferedInputStreamas the source.- Parameters:
source- the stream providing the split datastartOffset- the position of the first byte in the window; this is relative to the starting position ofsource.endOffset- the position of the last byte in the window, exclusive; this is relative to the starting position ofsource.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
- Throws:
IOException
-
fillBuffer
Description copied from class:BinaryReaderFills the working buffer- Overrides:
fillBufferin classBinaryReader- Throws:
IOException
-
availableInSplit
public long availableInSplit()Gets the number of bytes remaining in the split.- Specified by:
availableInSplitin interfaceSplitInputStream- 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:
hasOverrunin interfaceSplitInputStream- Returns:
trueif all bytes in the split has been read,falseif any remain.
-
skipTo
Advances the position of the stream to the first byte after the specified pattern.- Parameters:
bytes- the pattern to find in the stream- Returns:
falseif end of data is reached,trueotherwise.- Throws:
IOException- if an I/O error occurs while reading the stream
-