- java.lang.Object
-
- java.io.InputStream
-
- com.pervasive.datarush.io.BinaryReader
-
- All Implemented Interfaces:
Closeable,AutoCloseable
- Direct Known Subclasses:
SplitInputStreamImpl
public class BinaryReader extends InputStream
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.BinaryInputStreamis also extended to provide support for reading from other "chunked" byte sources.- See Also:
BinaryBuilder
-
-
Field Summary
Fields Modifier and Type Field Description protected longabsolutePositionThe total number of bytes readprotected byte[]bufferThe current token valueprotected intpositionThe offset of the next byte to read in the tokenprotected intsizeThe size of the current tokenprotected InputStreamsourceThe underlying byte stream
-
Constructor Summary
Constructors Constructor Description BinaryReader(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()voidclose()Closes the wrapped port and releases any allocated resources.protected intfillBuffer()Fills the working bufferlonggetAbsolutePosition()Gets the current position in the underlying data.booleanisEmpty()Indicates whether the byte stream for reading has been exhausted.protected booleanloadNextBuffer()voidmark(int readlimit)Marking the stream is not a supported operation.booleanmarkSupported()intread()intread(byte[] b)intread(byte[] b, int off, int len)intreadBase128Int()Reads a base-128 encoded int value from the stream.longreadBase128Long()Reads 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.doublereadDouble()Reads a double value from the stream.floatreadFloat()Reads 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.intreadUnsignedBase128Int()Reads a base-128 encoded int value from the stream, assuming an unsigned encoding.longreadUnsignedBase128Long()Reads a base-128 encoded long value from the stream, assuming an unsigned encoding.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.StringtoString()-
Methods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, transferTo
-
-
-
-
Field Detail
-
source
protected InputStream source
The underlying byte stream
-
buffer
protected byte[] buffer
The current token value
-
position
protected int position
The offset of the next byte to read in the token
-
size
protected int size
The size of the current token
-
absolutePosition
protected long absolutePosition
The total number of bytes read
-
-
Constructor Detail
-
BinaryReader
public BinaryReader(InputStream source, int bufferSize)
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 Detail
-
fillBuffer
protected int fillBuffer() throws IOExceptionFills the working buffer- Throws:
IOException
-
loadNextBuffer
protected boolean loadNextBuffer() throws IOException- Throws:
IOException
-
read
public int read() throws IOException- Specified by:
readin classInputStream- Throws:
IOException
-
read
public final int read(byte[] b) throws IOException- Overrides:
readin classInputStream- Throws:
IOException
-
read
public final int read(byte[] b, int off, int len) throws IOException- Overrides:
readin classInputStream- Throws:
IOException
-
skip
public long skip(long n) throws IOException- 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:
BinaryBuilder.appendUnsignedBase128(int)
-
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:
BinaryBuilder.appendBase128(int)
-
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:
BinaryBuilder.appendUnsignedBase128(long)
-
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:
BinaryBuilder.appendBase128(int)
-
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
-
-