Package ej.bon

Class ResourceBuffer

  • All Implemented Interfaces:
    Closeable, AutoCloseable

    public class ResourceBuffer
    extends Object
    implements Closeable
    A resource buffer contains a set of data which is compacted to obtain a minimal footprint.

    A data is a 8-bits word (signed or unsigned), a 16-bits word (signed or unsigned), a 32-bits (signed or unsigned), a float, a double, a String or a ResourceArray.

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void align​(int nbBytes)
      Force to align position on given number of bytes.
      int available()
      Returns the available number of bytes that can be read (or skipped over) from this buffer.
      void close()
      Closes this resource and releases any system resources associated with the resource.
      ResourceArray readArray()
      Reads a ResourceArray and increments position in the data.
      boolean readBoolean()
      Reads a boolean and increments position in the data.
      byte readByte()
      Reads a byte and increments position in the data.
      char readChar()
      Reads a char and increments position in the data.
      int readInt()
      Reads an integer and increments position in the data.
      short readShort()
      Reads a short and increments position in the data.
      String readString()
      Reads a String and increments position in the data.
      long readVarLong()
      Reads a 64-bits signed integer and increments position in the data.
      int readVarSInt()
      Reads a 32-bits signed integer and increments position in the data.
      int readVarUInt()
      Reads a 32-bits unsigned integer and increments position in the data.
      void seek​(long offset)
      Sets the buffer position indicator.
    • Method Detail

      • close

        public void close()
                   throws IOException
        Closes this resource and releases any system resources associated with the resource. All next read calls will cause an unknown behavior.
        Specified by:
        close in interface AutoCloseable
        Specified by:
        close in interface Closeable
        Throws:
        IOException - if an I/O error occurs.
      • readVarSInt

        public int readVarSInt()
                        throws IOException
        Reads a 32-bits signed integer and increments position in the data.
        Returns:
        the value read.
        Throws:
        EOFException - when end of file is reached.
        IOException - if an I/O error occurs.
      • readVarUInt

        public int readVarUInt()
                        throws IOException
        Reads a 32-bits unsigned integer and increments position in the data.
        Returns:
        the value read.
        Throws:
        EOFException - when end of file is reached.
        IOException - if an I/O error occurs.
      • readVarLong

        public long readVarLong()
                         throws IOException
        Reads a 64-bits signed integer and increments position in the data.
        Returns:
        the value read.
        Throws:
        EOFException - when end of file is reached.
        IOException - if an I/O error occurs.
      • readBoolean

        public boolean readBoolean()
                            throws IOException
        Reads a boolean and increments position in the data.
        Returns:
        the value read.
        Throws:
        EOFException - when end of file is reached.
        IOException - if an I/O error occurs.
      • readByte

        public byte readByte()
                      throws IOException
        Reads a byte and increments position in the data.
        Returns:
        the value read.
        Throws:
        EOFException - when end of file is reached.
        IOException - if an I/O error occurs.
      • readShort

        public short readShort()
                        throws IOException
        Reads a short and increments position in the data.
        Returns:
        the value read.
        Throws:
        EOFException - when end of file is reached.
        IOException - if an I/O error occurs.
      • readChar

        public char readChar()
                      throws IOException
        Reads a char and increments position in the data.
        Returns:
        the value read.
        Throws:
        EOFException - when end of file is reached.
        IOException - if an I/O error occurs.
      • readInt

        public int readInt()
                    throws IOException
        Reads an integer and increments position in the data.
        Returns:
        the value read.
        Throws:
        EOFException - when end of file is reached.
        IOException - if an I/O error occurs.
      • seek

        public void seek​(long offset)
                  throws IOException
        Sets the buffer position indicator. The new position, measured in bytes, is obtained by adding offset bytes to the start of the buffer.
        Parameters:
        offset - the offset from start of buffer.
        Throws:
        IndexOutOfBoundsException - if there is no position with the given offset.
        EOFException - when end of file is reached.
        IOException - if an I/O error occurs.
      • available

        public int available()
                      throws IOException
        Returns the available number of bytes that can be read (or skipped over) from this buffer.
        Returns:
        the number of bytes that can be read
        Throws:
        IOException - if an I/O error occurs.
      • align

        public void align​(int nbBytes)
                   throws IOException
        Force to align position on given number of bytes. A value lower than 2 is ignored.
        Parameters:
        nbBytes - number of bytes to align
        Throws:
        EOFException - when end of file is reached.
        IOException - if an I/O error occurs.