Class DataInputByteArray

  • All Implemented Interfaces:
    DataInput

    public class DataInputByteArray
    extends java.lang.Object
    implements DataInput
    This class implements the DataInput interface using a byte buffer as source.
    • Constructor Summary

      Constructors 
      Constructor Description
      DataInputByteArray​(byte[] buffer)
      Constructor.
    • Field Detail

      • inputBuffer

        private final byte[] inputBuffer
      • bufferPosition

        private int bufferPosition
    • Constructor Detail

      • DataInputByteArray

        public DataInputByteArray​(byte[] buffer)
        Constructor.
        Parameters:
        buffer - the buffer to be read
    • Method Detail

      • hasRemaining

        public boolean hasRemaining()
                             throws java.io.IOException
        Determines if there are any bytes left to read or not.
        Specified by:
        hasRemaining in interface DataInput
        Returns:
        true if there are any bytes left to read
        Throws:
        java.io.IOException - if an error occurs during reading
      • getPosition

        public int getPosition()
        Returns the current position.
        Specified by:
        getPosition in interface DataInput
        Returns:
        current position
      • setPosition

        public void setPosition​(int position)
                         throws java.io.IOException
        Sets the current position to the given value.
        Specified by:
        setPosition in interface DataInput
        Parameters:
        position - the given position
        Throws:
        java.io.IOException - if the new position ist out of range
      • readByte

        public byte readByte()
                      throws java.io.IOException
        Read one single byte from the buffer.
        Specified by:
        readByte in interface DataInput
        Returns:
        the byte
        Throws:
        java.io.IOException - if an error occurs during reading
      • readUnsignedByte

        public int readUnsignedByte()
                             throws java.io.IOException
        Read one single unsigned byte from the buffer.
        Specified by:
        readUnsignedByte in interface DataInput
        Returns:
        the unsigned byte as int
        Throws:
        java.io.IOException - if an error occurs during reading
      • peekUnsignedByte

        public int peekUnsignedByte​(int offset)
                             throws java.io.IOException
        Peeks one single unsigned byte from the buffer.
        Specified by:
        peekUnsignedByte in interface DataInput
        Parameters:
        offset - offset to the byte to be peeked
        Returns:
        the unsigned byte as int
        Throws:
        java.io.IOException - if an error occurs during reading
      • readBytes

        public byte[] readBytes​(int length)
                         throws java.io.IOException
        Read a number of single byte values from the buffer.
        Specified by:
        readBytes in interface DataInput
        Parameters:
        length - the number of bytes to be read
        Returns:
        an array with containing the bytes from the buffer
        Throws:
        java.io.IOException - if an error occurs during reading
      • length

        public int length()
                   throws java.io.IOException
        Specified by:
        length in interface DataInput
        Throws:
        java.io.IOException