Package com.drew.lang

Class SequentialReader

    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      abstract int available()
      Returns an estimate of the number of bytes that can be read (or skipped over) from this SequentialReader without blocking by the next invocation of a method for this input stream.
      abstract byte getByte()
      Gets the next byte in the sequence.
      abstract void getBytes​(byte[] buffer, int offset, int count)
      Retrieves bytes, writing them into a caller-provided buffer.
      abstract byte[] getBytes​(int count)
      Returns the required number of bytes from the sequence.
      double getDouble64()  
      float getFloat32()  
      short getInt16()
      Returns a signed 16-bit int calculated from two bytes of data (MSB, LSB).
      int getInt32()
      Returns a signed 32-bit integer from four bytes of data.
      long getInt64()
      Get a signed 64-bit integer from the buffer.
      byte getInt8()
      Returns a signed 8-bit int calculated from the next byte the sequence.
      byte[] getNullTerminatedBytes​(int maxLengthBytes)
      Returns the sequence of bytes punctuated by a \0 value.
      java.lang.String getNullTerminatedString​(int maxLengthBytes, java.nio.charset.Charset charset)
      Creates a String from the stream, ending where byte=='\0' or where length==maxLength.
      StringValue getNullTerminatedStringValue​(int maxLengthBytes, java.nio.charset.Charset charset)
      Creates a String from the stream, ending where byte=='\0' or where length==maxLength.
      abstract long getPosition()  
      float getS15Fixed16()
      Gets a s15.16 fixed point float from the buffer.
      java.lang.String getString​(int bytesRequested)  
      java.lang.String getString​(int bytesRequested, java.lang.String charset)  
      java.lang.String getString​(int bytesRequested, java.nio.charset.Charset charset)  
      StringValue getStringValue​(int bytesRequested, java.nio.charset.Charset charset)  
      int getUInt16()
      Returns an unsigned 16-bit int calculated from the next two bytes of the sequence.
      long getUInt32()
      Get a 32-bit unsigned integer from the buffer, returning it as a long.
      short getUInt8()
      Returns an unsigned 8-bit int calculated from the next byte of the sequence.
      boolean isMotorolaByteOrder()
      Gets the endianness of this reader.
      void setMotorolaByteOrder​(boolean motorolaByteOrder)
      Sets the endianness of this reader.
      abstract void skip​(long n)
      Skips forward in the sequence.
      abstract boolean trySkip​(long n)
      Skips forward in the sequence, returning a boolean indicating whether the skip succeeded, or whether the sequence ended.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SequentialReader

        public SequentialReader()
    • Method Detail

      • getPosition

        public abstract long getPosition()
                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • getByte

        public abstract byte getByte()
                              throws java.io.IOException
        Gets the next byte in the sequence.
        Returns:
        The read byte value
        Throws:
        java.io.IOException
      • getBytes

        public abstract byte[] getBytes​(int count)
                                 throws java.io.IOException
        Returns the required number of bytes from the sequence.
        Parameters:
        count - The number of bytes to be returned
        Returns:
        The requested bytes
        Throws:
        java.io.IOException
      • getBytes

        public abstract void getBytes​(byte[] buffer,
                                      int offset,
                                      int count)
                               throws java.io.IOException
        Retrieves bytes, writing them into a caller-provided buffer.
        Parameters:
        buffer - The array to write bytes to.
        offset - The starting position within buffer to write to.
        count - The number of bytes to be written.
        Throws:
        java.io.IOException
      • skip

        public abstract void skip​(long n)
                           throws java.io.IOException
        Skips forward in the sequence. If the sequence ends, an EOFException is thrown.
        Parameters:
        n - the number of byte to skip. Must be zero or greater.
        Throws:
        java.io.EOFException - the end of the sequence is reached.
        java.io.IOException - an error occurred reading from the underlying source.
      • trySkip

        public abstract boolean trySkip​(long n)
                                 throws java.io.IOException
        Skips forward in the sequence, returning a boolean indicating whether the skip succeeded, or whether the sequence ended.
        Parameters:
        n - the number of byte to skip. Must be zero or greater.
        Returns:
        a boolean indicating whether the skip succeeded, or whether the sequence ended.
        Throws:
        java.io.IOException - an error occurred reading from the underlying source.
      • available

        public abstract int available()
        Returns an estimate of the number of bytes that can be read (or skipped over) from this SequentialReader without blocking by the next invocation of a method for this input stream. A single read or skip of this many bytes will not block, but may read or skip fewer bytes.

        Note that while some implementations of SequentialReader like SequentialByteArrayReader will return the total remaining number of bytes in the stream, others will not. It is never correct to use the return value of this method to allocate a buffer intended to hold all data in this stream.

        Returns:
        an estimate of the number of bytes that can be read (or skipped over) from this SequentialReader without blocking or 0 when it reaches the end of the input stream.
      • setMotorolaByteOrder

        public void setMotorolaByteOrder​(boolean motorolaByteOrder)
        Sets the endianness of this reader.
        • true for Motorola (or big) endianness (also known as network byte order), with MSB before LSB.
        • false for Intel (or little) endianness, with LSB before MSB.
        Parameters:
        motorolaByteOrder - true for Motorola/big endian, false for Intel/little endian
      • isMotorolaByteOrder

        public boolean isMotorolaByteOrder()
        Gets the endianness of this reader.
        • true for Motorola (or big) endianness (also known as network byte order), with MSB before LSB.
        • false for Intel (or little) endianness, with LSB before MSB.
      • getUInt8

        public short getUInt8()
                       throws java.io.IOException
        Returns an unsigned 8-bit int calculated from the next byte of the sequence.
        Returns:
        the 8 bit int value, between 0 and 255
        Throws:
        java.io.IOException
      • getInt8

        public byte getInt8()
                     throws java.io.IOException
        Returns a signed 8-bit int calculated from the next byte the sequence.
        Returns:
        the 8 bit int value, between 0x00 and 0xFF
        Throws:
        java.io.IOException
      • getUInt16

        public int getUInt16()
                      throws java.io.IOException
        Returns an unsigned 16-bit int calculated from the next two bytes of the sequence.
        Returns:
        the 16 bit int value, between 0x0000 and 0xFFFF
        Throws:
        java.io.IOException
      • getInt16

        public short getInt16()
                       throws java.io.IOException
        Returns a signed 16-bit int calculated from two bytes of data (MSB, LSB).
        Returns:
        the 16 bit int value, between 0x0000 and 0xFFFF
        Throws:
        java.io.IOException - the buffer does not contain enough bytes to service the request
      • getUInt32

        public long getUInt32()
                       throws java.io.IOException
        Get a 32-bit unsigned integer from the buffer, returning it as a long.
        Returns:
        the unsigned 32-bit int value as a long, between 0x00000000 and 0xFFFFFFFF
        Throws:
        java.io.IOException - the buffer does not contain enough bytes to service the request
      • getInt32

        public int getInt32()
                     throws java.io.IOException
        Returns a signed 32-bit integer from four bytes of data.
        Returns:
        the signed 32 bit int value, between 0x00000000 and 0xFFFFFFFF
        Throws:
        java.io.IOException - the buffer does not contain enough bytes to service the request
      • getInt64

        public long getInt64()
                      throws java.io.IOException
        Get a signed 64-bit integer from the buffer.
        Returns:
        the 64 bit int value, between 0x0000000000000000 and 0xFFFFFFFFFFFFFFFF
        Throws:
        java.io.IOException - the buffer does not contain enough bytes to service the request
      • getS15Fixed16

        public float getS15Fixed16()
                            throws java.io.IOException
        Gets a s15.16 fixed point float from the buffer.

        This particular fixed point encoding has one sign bit, 15 numerator bits and 16 denominator bits.

        Returns:
        the floating point value
        Throws:
        java.io.IOException - the buffer does not contain enough bytes to service the request
      • getFloat32

        public float getFloat32()
                         throws java.io.IOException
        Throws:
        java.io.IOException
      • getDouble64

        public double getDouble64()
                           throws java.io.IOException
        Throws:
        java.io.IOException
      • getString

        public java.lang.String getString​(int bytesRequested)
                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • getString

        public java.lang.String getString​(int bytesRequested,
                                          java.lang.String charset)
                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • getString

        public java.lang.String getString​(int bytesRequested,
                                          java.nio.charset.Charset charset)
                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • getStringValue

        public StringValue getStringValue​(int bytesRequested,
                                          java.nio.charset.Charset charset)
                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • getNullTerminatedString

        public java.lang.String getNullTerminatedString​(int maxLengthBytes,
                                                        java.nio.charset.Charset charset)
                                                 throws java.io.IOException
        Creates a String from the stream, ending where byte=='\0' or where length==maxLength.
        Parameters:
        maxLengthBytes - The maximum number of bytes to read. If a zero-byte is not reached within this limit, reading will stop and the string will be truncated to this length.
        Returns:
        The read string.
        Throws:
        java.io.IOException - The buffer does not contain enough bytes to satisfy this request.
      • getNullTerminatedStringValue

        public StringValue getNullTerminatedStringValue​(int maxLengthBytes,
                                                        java.nio.charset.Charset charset)
                                                 throws java.io.IOException
        Creates a String from the stream, ending where byte=='\0' or where length==maxLength.
        Parameters:
        maxLengthBytes - The maximum number of bytes to read. If a \0 byte is not reached within this limit, reading will stop and the string will be truncated to this length.
        charset - The Charset to register with the returned StringValue, or null if the encoding is unknown
        Returns:
        The read string.
        Throws:
        java.io.IOException - The buffer does not contain enough bytes to satisfy this request.
      • getNullTerminatedBytes

        public byte[] getNullTerminatedBytes​(int maxLengthBytes)
                                      throws java.io.IOException
        Returns the sequence of bytes punctuated by a \0 value.
        Parameters:
        maxLengthBytes - The maximum number of bytes to read. If a \0 byte is not reached within this limit, the returned array will be maxLengthBytes long.
        Returns:
        The read byte array, excluding the null terminator.
        Throws:
        java.io.IOException - The buffer does not contain enough bytes to satisfy this request.