java.lang.Object
java.io.InputStream
com.pervasive.datarush.io.BinaryReader
- All Implemented Interfaces:
Closeable,AutoCloseable
- Direct Known Subclasses:
SplitInputStreamImpl
Provides extended data access methods on binary data flows. Beyond supporting
a byte-oriented view of the concatenated tokens, a number of methods for
reading primitive type binary formats are provided.
BinaryInputStream
is also extended to provide support for reading from other "chunked" byte
sources.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected longThe total number of bytes readprotected byte[]The current token valueprotected intThe offset of the next byte to read in the tokenprotected intThe size of the current tokenprotected InputStreamThe underlying byte stream -
Constructor Summary
ConstructorsConstructorDescriptionBinaryReader(byte[] bytes) Wraps a byte array with a byte-oriented reader.BinaryReader(InputStream source, int bufferSize) Wraps anInputStreamwith a byte-oriented reader having extended function. -
Method Summary
Modifier and TypeMethodDescriptionintfinal voidclose()Closes the wrapped port and releases any allocated resources.protected intFills the working bufferfinal longGets the current position in the underlying data.booleanisEmpty()Indicates whether the byte stream for reading has been exhausted.protected booleanfinal voidmark(int readlimit) Marking the stream is not a supported operation.final booleanintread()final intread(byte[] b) final intread(byte[] b, int off, int len) intReads a base-128 encoded int value from the stream.longReads a base-128 encoded long value from the stream.bytereadByte()Reads a single byte from the stream.byte[]readBytes(int len) Reads a specified number of bytes from the stream.charreadChar()Reads a character value from the stream.char[]readChars(int count) Reads a specified number of character values from the stream.doubleReads a double value from the stream.floatReads a float value from the stream.intreadInt()Reads an int value from the stream.longreadLong()Reads a long value from the stream.char[]readSingleByteChars(int count) Reads a specified number of character values from the stream, assuming the bytes are the least-significant bytes of the values.intReads a base-128 encoded int value from the stream, assuming an unsigned encoding.longReads a base-128 encoded long value from the stream, assuming an unsigned encoding.final voidreset()Resetting the stream is not a supported operation.longskip(long n) voidskipBytes(long count) Advances the read position in the stream the specified number of bytes.toString()Methods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Field Details
-
source
The underlying byte stream -
buffer
protected byte[] bufferThe current token value -
position
protected int positionThe offset of the next byte to read in the token -
size
protected int sizeThe size of the current token -
absolutePosition
protected long absolutePositionThe total number of bytes read
-
-
Constructor Details
-
BinaryReader
Wraps anInputStreamwith a byte-oriented reader having extended function. If anIOExceptionis thrown by the wrapped source, the provided stream will be closed.The wrapped stream should not be accessed directly after creating the stream. Doing so may result in unexpected or otherwise unpredictable behavior in both the stream and the wrapper.
- Parameters:
source- the stream to wrapbufferSize- the size of the read buffer to use, in bytes. Data will be read in chunks of this size from the wrapped stream.
-
BinaryReader
public BinaryReader(byte[] bytes) Wraps a byte array with a byte-oriented reader.- Parameters:
bytes- the byte array to wrap.
-
-
Method Details
-
fillBuffer
Fills the working buffer- Throws:
IOException
-
loadNextBuffer
- Throws:
IOException
-
read
- Specified by:
readin classInputStream- Throws:
IOException
-
read
- Overrides:
readin classInputStream- Throws:
IOException
-
read
- Overrides:
readin classInputStream- Throws:
IOException
-
skip
- Overrides:
skipin classInputStream- Throws:
IOException
-
available
public int available()- Overrides:
availablein classInputStream
-
getAbsolutePosition
public final long getAbsolutePosition()Gets the current position in the underlying data.- Returns:
- the number of bytes read so far
-
markSupported
public final boolean markSupported()- Overrides:
markSupportedin classInputStream
-
mark
public final void mark(int readlimit) Marking the stream is not a supported operation.- Overrides:
markin classInputStream- Throws:
UnsupportedOperationException- always
-
reset
public final void reset()Resetting the stream is not a supported operation.- Overrides:
resetin classInputStream- Throws:
UnsupportedOperationException- always
-
close
public final void close()Closes the wrapped port and releases any allocated resources. Subsequent reads will behave as if end of data has been reached.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream
-
isEmpty
public boolean isEmpty()Indicates whether the byte stream for reading has been exhausted.- Returns:
trueif no more bytes are available to be read,falseotherwise.
-
skipBytes
public void skipBytes(long count) Advances the read position in the stream the specified number of bytes.- Parameters:
count- the number of bytes to skip
-
readByte
public byte readByte()Reads a single byte from the stream. The read position is advanced one byte as a result.- Returns:
- the byte at the current position
-
readBytes
public byte[] readBytes(int len) Reads a specified number of bytes from the stream. The read position is advanced the specified number of bytes.- Parameters:
len- the number of bytes to read- Returns:
- the next
lenbytes starting at the current position
-
readChar
public char readChar()Reads a character value from the stream. The read position is advanced 2 bytes.- Returns:
- the character value encoded at the current position
-
readChars
public char[] readChars(int count) Reads a specified number of character values from the stream. The read position is advanced 2 bytes for each character requested.- Parameters:
count- the number of characters to read- Returns:
- the next
countcharacters starting at the current position
-
readSingleByteChars
public char[] readSingleByteChars(int count) Reads a specified number of character values from the stream, assuming the bytes are the least-significant bytes of the values. The read position is advanced only one byte for each character requested.- Parameters:
count- the number of characters to read- Returns:
- the next
countcharacters starting at the current position
-
readInt
public int readInt()Reads an int value from the stream. The read position is advanced 4 bytes.- Returns:
- the int value encoded at the current position
-
readUnsignedBase128Int
public int readUnsignedBase128Int()Reads a base-128 encoded int value from the stream, assuming an unsigned encoding. The read position is advanced to the position following the last byte of the encoding.- Returns:
- the int value base-128 encoded at the current position
- See Also:
-
readBase128Int
public int readBase128Int()Reads a base-128 encoded int value from the stream. The read position is advanced to the position following the last byte of the encoding.- Returns:
- the int value base-128 encoded at the current position
- See Also:
-
readLong
public long readLong()Reads a long value from the stream. The read position is advanced 8 bytes.- Returns:
- the long value encoded at the current position
-
readUnsignedBase128Long
public long readUnsignedBase128Long()Reads a base-128 encoded long value from the stream, assuming an unsigned encoding. The read position is advanced to the position following the last byte of the encoding.- Returns:
- the long value base-128 encoded at the current position
- See Also:
-
readBase128Long
public long readBase128Long()Reads a base-128 encoded long value from the stream. The read position is advanced to the position following the last byte of the encoding.- Returns:
- the long value base-128 encoded at the current position
- See Also:
-
readFloat
public float readFloat()Reads a float value from the stream. The read position is advanced 4 bytes. The bytes are interpreted usingFloat.intBitsToFloat(int).- Returns:
- the float value encoded at the current position
-
readDouble
public double readDouble()Reads a double value from the stream. The read position is advanced 8 bytes. The bytes are interpreted usingDouble.longBitsToDouble(long).- Returns:
- the double value encoded at the current position
-
toString
-