Class BinaryReader

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. BinaryInputStream is also extended to provide support for reading from other "chunked" byte sources.
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected long
    The total number of bytes read
    protected byte[]
    The current token value
    protected int
    The offset of the next byte to read in the token
    protected int
    The size of the current token
    protected InputStream
    The 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 an InputStream with a byte-oriented reader having extended function.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
     
    final void
    Closes the wrapped port and releases any allocated resources.
    protected int
    Fills the working buffer
    final long
    Gets the current position in the underlying data.
    boolean
    Indicates whether the byte stream for reading has been exhausted.
    protected boolean
     
    final void
    mark(int readlimit)
    Marking the stream is not a supported operation.
    final boolean
     
    int
     
    final int
    read(byte[] b)
     
    final int
    read(byte[] b, int off, int len)
     
    int
    Reads a base-128 encoded int value from the stream.
    long
    Reads a base-128 encoded long value from the stream.
    byte
    Reads a single byte from the stream.
    byte[]
    readBytes(int len)
    Reads a specified number of bytes from the stream.
    char
    Reads a character value from the stream.
    char[]
    readChars(int count)
    Reads a specified number of character values from the stream.
    double
    Reads a double value from the stream.
    float
    Reads a float value from the stream.
    int
    Reads an int value from the stream.
    long
    Reads a long value from the stream.
    char[]
    Reads a specified number of character values from the stream, assuming the bytes are the least-significant bytes of the values.
    int
    Reads a base-128 encoded int value from the stream, assuming an unsigned encoding.
    long
    Reads a base-128 encoded long value from the stream, assuming an unsigned encoding.
    final void
    Resetting the stream is not a supported operation.
    long
    skip(long n)
     
    void
    skipBytes(long count)
    Advances the read position in the stream the specified number of bytes.
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • 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 Details

    • BinaryReader

      public BinaryReader(InputStream source, int bufferSize)
      Wraps an InputStream with a byte-oriented reader having extended function. If an IOException is 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 wrap
      bufferSize - 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

      protected int fillBuffer() throws IOException
      Fills the working buffer
      Throws:
      IOException
    • loadNextBuffer

      protected boolean loadNextBuffer() throws IOException
      Throws:
      IOException
    • read

      public int read() throws IOException
      Specified by:
      read in class InputStream
      Throws:
      IOException
    • read

      public final int read(byte[] b) throws IOException
      Overrides:
      read in class InputStream
      Throws:
      IOException
    • read

      public final int read(byte[] b, int off, int len) throws IOException
      Overrides:
      read in class InputStream
      Throws:
      IOException
    • skip

      public long skip(long n) throws IOException
      Overrides:
      skip in class InputStream
      Throws:
      IOException
    • available

      public int available()
      Overrides:
      available in class InputStream
    • 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:
      markSupported in class InputStream
    • mark

      public final void mark(int readlimit)
      Marking the stream is not a supported operation.
      Overrides:
      mark in class InputStream
      Throws:
      UnsupportedOperationException - always
    • reset

      public final void reset()
      Resetting the stream is not a supported operation.
      Overrides:
      reset in class InputStream
      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:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class InputStream
    • isEmpty

      public boolean isEmpty()
      Indicates whether the byte stream for reading has been exhausted.
      Returns:
      true if no more bytes are available to be read, false otherwise.
    • 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 len bytes 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 count characters 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 count characters 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 using Float.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 using Double.longBitsToDouble(long).
      Returns:
      the double value encoded at the current position
    • toString

      public String toString()
      Overrides:
      toString in class Object