- 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 Summary
Fields Modifier and Type Field Description static int
DEFAULT_BUFFER
The default size for the read buffer, in bytes.protected long
splitEnd
protected long
splitStart
-
Fields inherited from class com.pervasive.datarush.io.BinaryReader
absolutePosition, buffer, position, size, source
-
-
Constructor Summary
Constructors Constructor Description SplitInputStreamImpl(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
availableInSplit()
Gets the number of bytes remaining in the split.protected int
fillBuffer()
Fills the working bufferboolean
hasOverrun()
Indicates whether the reader has read past the end of the split.protected void
moveToSplit()
long
overrunPastSplit()
Gets the number of bytes which have been read beyond the end of the split.boolean
skipTo(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, toString
-
Methods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, transferTo
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.pervasive.datarush.io.SplitInputStream
close, read
-
-
-
-
Field Detail
-
DEFAULT_BUFFER
public static final int DEFAULT_BUFFER
The default size for the read buffer, in bytes.- See Also:
- Constant Field Values
-
splitStart
protected final long splitStart
-
splitEnd
protected final long splitEnd
-
-
Constructor Detail
-
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
BufferedInputStream
as 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
BufferedInputStream
as 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 Detail
-
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 classBinaryReader
- Throws:
IOException
-
availableInSplit
public long availableInSplit()
Gets the number of bytes remaining in the split.- Specified by:
availableInSplit
in 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:
hasOverrun
in interfaceSplitInputStream
- 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
-
-