Package nl.tno.imb

Class TByteBuffer


  • public class TByteBuffer
    extends Object
    General buffer for use within the IMB framework to standardize byte order and data exchange.
    IMB is always little-endian within the framework (and over the network). IMB defines the following types: byte, boolean, int32, int64, single, double, string. string is defined as a byte array with UTF-8 characters prefixed with length as int32.
    Class is to be extended with Google Protocol Buffers to store data compressed and compatible with Protocol Buffers.
    Standard Java ByteBuffers are not used because of performance issues.
    Java 1.7 defines DirectByteBuffer which looks promising but for now is not widely used.
    All reads advance the read cursor. All qreads advance the read cursor and read without any checking. All writes advance the write cursor. All qwrites advance the write cursor and write without any checking. All prepares advance the prepare cursor.
    Prepares are to be used to optimize the buffer memory allocations. prepareApply closes the prepares and allocates the newly needed buffer size.
    Author:
    hans.cornelissen@tno.nl
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int SIZE_OF_BOOLEAN
      uncompressed size of boolean within IMB framework
      static int SIZE_OF_BYTE
      uncompressed size of byte within IMB framework
      static int SIZE_OF_DOUBLE
      uncompressed size of double within IMB framework
      static int SIZE_OF_INT32
      uncompressed size of 32 bit integer within IMB framework
      static int SIZE_OF_INT64
      uncompressed size of 64 bit integer within IMB framework
      static int SIZE_OF_SINGLE
      uncompressed size of single within IMB framework
    • Constructor Summary

      Constructors 
      Constructor Description
      TByteBuffer()
      Constructor: create empty byte buffer
      TByteBuffer​(byte[] aBuffer)
      Constructor: create byte buffer as copy of the specified byte array
      TByteBuffer​(int aLength)
      Constructor: create byte buffer of the specified length
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      Clear the byte buffer to zero length and reset all cursors
      void clear​(int aLength)
      Clear the byte buffer to the specified length and reset all cursors.
      boolean compare​(byte[] aValue, int aOffset)
      Compare the contents of this byte buffer at the read cursor to a given byte array
      byte[] getBuffer()
      Retrieve reference to internal byte buffer
      int getLength()
      length of the byte buffer in bytes
      int getReadAvailable()
      Retrieve the bytes that still can be read from the byte buffer
      int getReadCursor()
      Retrieve the current reading (cursor) position
      int getwriteAvailable()
      Returns the room still available in the byte buffer to write data to without reallocating memory.
      int getWriteCursor()
      Retrieve the current writing (cursor) position
      boolean isEmpty()
      Check if the byte buffer is empty
      boolean peekBoolean​(int aOffset)
      Read a boolean from the byte buffer at an offset to the read cursor without advancing the read cursor.
      boolean peekBoolean​(int aOffset, boolean aDefaultValue)
      Read a boolean from the byte buffer at an offset to the read cursor without advancing the read cursor.
      byte peekByte​(int aOffset)
      Read a byte from the byte buffer at an offset to the read cursor without advancing the read cursor.
      byte peekByte​(int aOffset, byte aDefaultValue)
      Read a byte from the byte buffer at an offset to the read cursor without advancing the read cursor.
      double peekDouble​(int aOffset)
      Read a double from the byte buffer at an offset to the read cursor without advancing the read cursor.
      double peekDouble​(int aOffset, double aDefaultValue)
      Read a double from the byte buffer at an offset to the read cursor without advancing the read cursor.
      int peekInt32​(int aOffset)
      Read an 32 bit integer from the byte buffer at an offset to the read cursor without advancing the read cursor.
      int peekInt32​(int aOffset, int aDefaultValue)
      Read an 32 bit integer from the byte buffer at an offset to the read cursor without advancing the read cursor.
      long peekInt64​(int aOffset)
      Read an 64 bit integer (long) from the byte buffer at an offset to the read cursor without advancing the read cursor.
      long peekInt64​(int aOffset, long aDefaultValue)
      Read an 64 bit integer (long) from the byte buffer at an offset to the read cursor without advancing the read cursor.
      float peekSingle​(int aOffset)
      Read a single (32 bit float) from the byte buffer at an offset to the read cursor without advancing the read cursor.
      float peekSingle​(int aOffset, float aDefaultValue)
      Read a single (32 bit float) from the byte buffer at an offset to the read cursor without advancing the read cursor.
      String peekString​(int aOffset)
      Read a string from the byte buffer at an offset to the read cursor without advancing the read cursor.
      String peekString​(int aOffset, String aDefaultValue)
      Read a string from the byte buffer at an offset to the read cursor without advancing the read cursor.
      void prepare​(boolean aValue)
      Prepares the byte buffer for later writing of a boolean.
      void prepare​(byte aValue)
      Prepares the byte buffer for later writing of a byte.
      void prepare​(byte[] aValue)
      Prepares the byte buffer for later writing of a byte array (without size).
      void prepare​(double aValue)
      Prepares the byte buffer for later writing of a double.
      void prepare​(float aValue)
      Prepares the byte buffer for later writing of a 32 bit single (float).
      void prepare​(int aValue)
      Prepares the byte buffer for later writing of an 32 bit integer.
      void prepare​(long aValue)
      Prepares the byte buffer for later writing of an 64 bit integer (long).
      void prepare​(String aValue)
      Prepares the byte buffer for later writing of a string.
      void prepare​(TByteBuffer aValue)
      Prepares the byte buffer for later writing of an other byte buffers readable data.
      void prepareApply()
      Adjusts the length of the byte buffer to accommodate at a minimum all prepared data
      void prepareApplyAndTrim()
      Adjusts the length of the byte buffer to accommodate exactly all prepared data
      int prepareSize​(int aValueSize)
      Prepares the byte buffer for later writing of the specified number of bytes.
      int prepareStart()
      Start prepare sequence.
      boolean qReadBoolean()
      Read a boolean from the byte buffer without any checks
      byte qReadByte()
      Read a byte from the byte buffer without any checks
      TByteBuffer qReadByteBuffer()
      Read a byte buffer this byte buffer without any checks Read size and data and store as a whole WITHOUT size (size=length buffer)
      double qReadDouble​(double aDefaultValue)
      Read a double from the byte buffer without any checks
      int qReadInt32()
      Read an 32 bit integer from the byte buffer without any checks
      long qReadInt64()
      Read an 64 bit integer from the byte buffer without any checks
      float qReadSingle()
      Read a single (32 bit float) from the byte buffer without any checks
      String qReadString​(String aDefaultValue)
      Read a string from the byte buffer without any checks
      void qWrite​(boolean aValue)
      write a boolean to the buffer; the QWrite methods do not check for room in the buffer
      void qWrite​(byte aValue)
      write a single byte to the buffer; the QWrite methods do not check for room in the buffer
      void qWrite​(byte[] aValue)
      write array of byte WITHOUT size; the QWrite methods do not check for room in the buffer
      void qWrite​(double aValue)
      write a single double (64 bit) to the buffer; the QWrite methods do not check for room in the buffer
      void qWrite​(float aValue)
      write a single float (32 bit) to the buffer; the QWrite methods do not check for room in the buffer
      void qWrite​(int aValue)
      write a single integer (32 bit) to the buffer; the QWrite methods do not check for room in the buffer
      void qWrite​(long aValue)
      write a single integer (64 bit) to the buffer; the QWrite methods do not check for room in the buffer
      void qWrite​(String aValue)
      Write a string to the buffer, prefixed with the size as a 32 bit integer.
      void qWrite​(TByteBuffer aValue)
      write, with no checking, all readable data from the given byte buffer to this prefixed WITH size
      boolean readBoolean()
      Read a boolean from the byte buffer
      boolean readBoolean​(boolean aDefaultValue)
      Read a boolean from the byte buffer
      byte readByte()
      Read a byte from the byte buffer
      byte readByte​(byte aDefaultValue)
      Read a byte from the byte buffer
      TByteBuffer readByteBuffer()
      Read new byte buffer contents from this byte buffer.
      void readByteBuffer​(TByteBuffer aValue)
      Read size and data and store as a whole WITHOUT size (size=length buffer)
      double readDouble()
      Read a double float from the byte buffer
      double readDouble​(double aDefaultValue)
      Read a double float from the byte buffer
      int readInt32()
      Read an integer (32 bit) from the byte buffer
      int readInt32​(int aDefaultValue)
      Read an integer (32 bit) from the byte buffer
      long readInt64()
      Read an integer (64 bit) from the byte buffer
      long readInt64​(long aDefaultValue)
      Read an integer (64 bit) from the byte buffer
      byte[] readRest()
      Read all data available from the read cursor
      TByteBuffer readRestToByteBuffer()
      Read all data available from the read cursor in this byte buffer to a newly created byte buffer
      float readSingle()
      Read a single float from the byte buffer
      float readSingle​(float aDefaultValue)
      Read a single float from the byte buffer
      void ReadStart()
      Reset the reading cursor
      String readString()
      Read a string from the byte buffer.
      String readString​(String aDefaultValue)
      Read a string from the byte buffer.
      void shiftLeftOneByte​(byte aRightByte)
      Shift all bytes in the byte buffer to the left and insert a new byte to the right (end of byte buffer)
      void skipReading​(int aValueSize)
      Skip the specified amount of bytes for reading Advances the read cursor the specified amount of bytes
      void write​(boolean aValue)
      Write the specified boolean to the byte buffer.
      void write​(byte aValue)
      Write the specified byte to the byte buffer.
      void write​(byte[] aValue)
      Write the specified byte array WITHOUT the size to the byte buffer.
      void write​(double aValue)
      Write the specified double to the byte buffer.
      void write​(float aValue)
      Write the specified single (float) to the byte buffer.
      void write​(int aValue)
      Write the specified 32 bit integer to the byte buffer.
      void write​(long aValue)
      Write the specified 64 bit integer (long) to the byte buffer.
      void write​(String aValue)
      Write the specified string to the byte buffer in UTF-8 format.
      void write​(TByteBuffer aValue)
      Write the readable data in the specified byte buffer to this byte buffer.
      void writeApply()
      apply written data (trim extra buffer space)
      void writeStart​(int aIndex)
      Start writing at the specified 0-based index.
      boolean written​(int aValueSize)
      signal number of bytes directly written to buffer without using class methods update write cursor and return if it fitted into buffer (should trigger exception ?)
    • Field Detail

      • SIZE_OF_BOOLEAN

        public static final int SIZE_OF_BOOLEAN
        uncompressed size of boolean within IMB framework
        See Also:
        Constant Field Values
      • SIZE_OF_BYTE

        public static final int SIZE_OF_BYTE
        uncompressed size of byte within IMB framework
        See Also:
        Constant Field Values
      • SIZE_OF_INT32

        public static final int SIZE_OF_INT32
        uncompressed size of 32 bit integer within IMB framework
        See Also:
        Constant Field Values
      • SIZE_OF_INT64

        public static final int SIZE_OF_INT64
        uncompressed size of 64 bit integer within IMB framework
        See Also:
        Constant Field Values
      • SIZE_OF_SINGLE

        public static final int SIZE_OF_SINGLE
        uncompressed size of single within IMB framework
        See Also:
        Constant Field Values
      • SIZE_OF_DOUBLE

        public static final int SIZE_OF_DOUBLE
        uncompressed size of double within IMB framework
        See Also:
        Constant Field Values
    • Constructor Detail

      • TByteBuffer

        public TByteBuffer​(int aLength)
        Constructor: create byte buffer of the specified length
        Parameters:
        aLength - int; length in bytes of the buffer to create
      • TByteBuffer

        public TByteBuffer()
        Constructor: create empty byte buffer
      • TByteBuffer

        public TByteBuffer​(byte[] aBuffer)
        Constructor: create byte buffer as copy of the specified byte array
        Parameters:
        aBuffer - byte[];
    • Method Detail

      • getLength

        public int getLength()
        length of the byte buffer in bytes
        Returns:
        length of the allocated buffer in bytes
      • getBuffer

        public byte[] getBuffer()
        Retrieve reference to internal byte buffer
        Returns:
        reference to internal byte buffer
      • clear

        public void clear()
        Clear the byte buffer to zero length and reset all cursors
      • clear

        public void clear​(int aLength)
        Clear the byte buffer to the specified length and reset all cursors.
      • isEmpty

        public boolean isEmpty()
        Check if the byte buffer is empty
        Returns:
        true if the byte buffer is empty
      • getReadCursor

        public int getReadCursor()
        Retrieve the current reading (cursor) position
        Returns:
        cursor position for reading: index into byte buffer in bytes starting at 0
      • getWriteCursor

        public int getWriteCursor()
        Retrieve the current writing (cursor) position
        Returns:
        cursor position for writing: index into byte buffer in bytes starting at 0
      • ReadStart

        public void ReadStart()
        Reset the reading cursor
      • getReadAvailable

        public int getReadAvailable()
        Retrieve the bytes that still can be read from the byte buffer
        Returns:
        bytes available for reading
      • readBoolean

        public boolean readBoolean()
        Read a boolean from the byte buffer
        Returns:
        boolean read from byte buffer (default is false)
      • readBoolean

        public boolean readBoolean​(boolean aDefaultValue)
        Read a boolean from the byte buffer
        Parameters:
        aDefaultValue - boolean; in case of a read error this value is returned
        Returns:
        boolean read from byte buffer
      • readByte

        public byte readByte()
        Read a byte from the byte buffer
        Returns:
        byte read from the byte buffer
      • readByte

        public byte readByte​(byte aDefaultValue)
        Read a byte from the byte buffer
        Parameters:
        aDefaultValue - byte; in case of a read error this value is returned
        Returns:
        byte read from the byte buffer
      • readInt32

        public int readInt32()
        Read an integer (32 bit) from the byte buffer
        Returns:
        integer (32 bit) read from the byte buffer
      • readInt32

        public int readInt32​(int aDefaultValue)
        Read an integer (32 bit) from the byte buffer
        Parameters:
        aDefaultValue - int; in case of a read error this value is returned
        Returns:
        integer (32 bit) read from the byte buffer
      • readInt64

        public long readInt64()
        Read an integer (64 bit) from the byte buffer
        Returns:
        integer (64 bit) read from the byte buffer
      • readInt64

        public long readInt64​(long aDefaultValue)
        Read an integer (64 bit) from the byte buffer
        Parameters:
        aDefaultValue - long; in case of a read error this value is returned
        Returns:
        integer (64 bit) read from the byte buffer
      • readSingle

        public float readSingle()
        Read a single float from the byte buffer
        Returns:
        single float read from the byte buffer
      • readSingle

        public float readSingle​(float aDefaultValue)
        Read a single float from the byte buffer
        Parameters:
        aDefaultValue - float; in case of a read error this value is returned
        Returns:
        single float read from the byte buffer
      • readDouble

        public double readDouble()
        Read a double float from the byte buffer
        Returns:
        double float read from the byte buffer
      • readDouble

        public double readDouble​(double aDefaultValue)
        Read a double float from the byte buffer
        Parameters:
        aDefaultValue - double; in case of a read error this value is returned
        Returns:
        double float read from the byte buffer
      • readString

        public String readString()
        Read a string from the byte buffer. The string is converted from UTF-8 to a standard string.
        Returns:
        the string read from the byte buffer
      • readString

        public String readString​(String aDefaultValue)
        Read a string from the byte buffer. The string is converted from UTF-8 to a standard string.
        Parameters:
        aDefaultValue - String; in case of a read error this value is returned
        Returns:
        the string read from the byte buffer
      • readByteBuffer

        public TByteBuffer readByteBuffer()
        Read new byte buffer contents from this byte buffer. Decode a size prefixed number of bytes from the byte buffer into a newly created byte buffer. The size part is not transfered to the new byte buffer but used as the length.
        Returns:
        a new byte buffer containing the data read from this byte buffer
      • readByteBuffer

        public void readByteBuffer​(TByteBuffer aValue)
        Read size and data and store as a whole WITHOUT size (size=length buffer)
        Parameters:
        aValue - TByteBuffer; byte buffer to store the read data in
      • qReadBoolean

        public boolean qReadBoolean()
        Read a boolean from the byte buffer without any checks
        Returns:
        the boolean read from the byte buffer
      • qReadByte

        public byte qReadByte()
        Read a byte from the byte buffer without any checks
        Returns:
        the byte read from the byte buffer
      • qReadInt32

        public int qReadInt32()
        Read an 32 bit integer from the byte buffer without any checks
        Returns:
        the 32 bit integer read from the byte buffer
      • qReadInt64

        public long qReadInt64()
        Read an 64 bit integer from the byte buffer without any checks
        Returns:
        the 64 bit integer read from the byte buffer
      • qReadSingle

        public float qReadSingle()
        Read a single (32 bit float) from the byte buffer without any checks
        Returns:
        the single (32 bit float) read from the byte buffer
      • qReadDouble

        public double qReadDouble​(double aDefaultValue)
        Read a double from the byte buffer without any checks
        Returns:
        the double read from the byte buffer
      • qReadString

        public String qReadString​(String aDefaultValue)
        Read a string from the byte buffer without any checks
        Returns:
        the string read from the byte buffer
      • qReadByteBuffer

        public TByteBuffer qReadByteBuffer()
        Read a byte buffer this byte buffer without any checks Read size and data and store as a whole WITHOUT size (size=length buffer)
        Returns:
        the new byte buffer read from the byte buffer
      • readRestToByteBuffer

        public TByteBuffer readRestToByteBuffer()
        Read all data available from the read cursor in this byte buffer to a newly created byte buffer
        Returns:
        a newly created byte buffer that contains all data read
      • readRest

        public byte[] readRest()
        Read all data available from the read cursor
        Returns:
        a byte array containing all data read
      • skipReading

        public void skipReading​(int aValueSize)
        Skip the specified amount of bytes for reading Advances the read cursor the specified amount of bytes
        Parameters:
        aValueSize - int; number of bytes to skip for reading
      • peekBoolean

        public boolean peekBoolean​(int aOffset)
        Read a boolean from the byte buffer at an offset to the read cursor without advancing the read cursor. If the value could not be read the default 'false' is returned.
        Parameters:
        aOffset - int; 0-based offset to the read cursor to peek at for the boolean
        Returns:
        the value read from the byte buffer at the specified offset
      • peekBoolean

        public boolean peekBoolean​(int aOffset,
                                   boolean aDefaultValue)
        Read a boolean from the byte buffer at an offset to the read cursor without advancing the read cursor.
        Parameters:
        aOffset - int; 0-based offset to the read cursor to peek at for the boolean
        aDefaultValue - boolean; if the value could not be read this default is returned
        Returns:
        the value read from the byte buffer at the specified offset
      • peekByte

        public byte peekByte​(int aOffset)
        Read a byte from the byte buffer at an offset to the read cursor without advancing the read cursor. If the value could not be read the default '0' is returned.
        Parameters:
        aOffset - int; 0-based offset to the read cursor to peek at for the byte
        Returns:
        the value read from the byte buffer at the specified offset
      • peekByte

        public byte peekByte​(int aOffset,
                             byte aDefaultValue)
        Read a byte from the byte buffer at an offset to the read cursor without advancing the read cursor.
        Parameters:
        aOffset - int; 0-based offset to the read cursor to peek at for the byte
        aDefaultValue - byte; if the value could not be read this default is returned
        Returns:
        the value read from the byte buffer at the specified offset
      • peekInt32

        public int peekInt32​(int aOffset)
        Read an 32 bit integer from the byte buffer at an offset to the read cursor without advancing the read cursor. If the value could not be read the default '0' is returned.
        Parameters:
        aOffset - int; 0-based offset to the read cursor to peek at for the integer
        Returns:
        the value read from the byte buffer at the specified offset
      • peekInt32

        public int peekInt32​(int aOffset,
                             int aDefaultValue)
        Read an 32 bit integer from the byte buffer at an offset to the read cursor without advancing the read cursor.
        Parameters:
        aOffset - int; 0-based offset to the read cursor to peek at for the integer
        aDefaultValue - int; if the value could not be read this default is returned
        Returns:
        the value read from the byte buffer at the specified offset
      • peekInt64

        public long peekInt64​(int aOffset)
        Read an 64 bit integer (long) from the byte buffer at an offset to the read cursor without advancing the read cursor. If the value could not be read the default '0' is returned.
        Parameters:
        aOffset - int; 0-based offset to the read cursor to peek at for the long
        Returns:
        the value read from the byte buffer at the specified offset
      • peekInt64

        public long peekInt64​(int aOffset,
                              long aDefaultValue)
        Read an 64 bit integer (long) from the byte buffer at an offset to the read cursor without advancing the read cursor.
        Parameters:
        aOffset - int; 0-based offset to the read cursor to peek at for the long
        aDefaultValue - long; if the value could not be read this default is returned
        Returns:
        the value read from the byte buffer at the specified offset
      • peekSingle

        public float peekSingle​(int aOffset)
        Read a single (32 bit float) from the byte buffer at an offset to the read cursor without advancing the read cursor. If the value could not be read the default 'NaN' is returned.
        Parameters:
        aOffset - int; 0-based offset to the read cursor to peek at for the float
        Returns:
        the value read from the byte buffer at the specified offset
      • peekSingle

        public float peekSingle​(int aOffset,
                                float aDefaultValue)
        Read a single (32 bit float) from the byte buffer at an offset to the read cursor without advancing the read cursor.
        Parameters:
        aOffset - int; 0-based offset to the read cursor to peek at for the float
        aDefaultValue - float; if the value could not be read this default is returned
        Returns:
        the value read from the byte buffer at the specified offset
      • peekDouble

        public double peekDouble​(int aOffset)
        Read a double from the byte buffer at an offset to the read cursor without advancing the read cursor. If the value could not be read the default 'NaN' is returned.
        Parameters:
        aOffset - int; 0-based offset to the read cursor to peek at for the double
        Returns:
        the value read from the byte buffer at the specified offset
      • peekDouble

        public double peekDouble​(int aOffset,
                                 double aDefaultValue)
        Read a double from the byte buffer at an offset to the read cursor without advancing the read cursor.
        Parameters:
        aOffset - int; 0-based offset to the read cursor to peek at for the double
        aDefaultValue - double; if the value could not be read this default is returned
        Returns:
        the value read from the byte buffer at the specified offset
      • peekString

        public String peekString​(int aOffset)
        Read a string from the byte buffer at an offset to the read cursor without advancing the read cursor. If the value could not be read the default "" is returned.
        Parameters:
        aOffset - int; 0-based offset to the read cursor to peek at for the string
        Returns:
        the value read from the byte buffer at the specified offset
      • peekString

        public String peekString​(int aOffset,
                                 String aDefaultValue)
        Read a string from the byte buffer at an offset to the read cursor without advancing the read cursor.
        Parameters:
        aOffset - int; 0-based offset to the read cursor to peek at for the string
        aDefaultValue - String; if the value could not be read this default is returned
        Returns:
        the value read from the byte buffer at the specified offset
      • compare

        public boolean compare​(byte[] aValue,
                               int aOffset)
        Compare the contents of this byte buffer at the read cursor to a given byte array
        Parameters:
        aValue - byte[]; byte array to compare with this byte buffer
        aOffset - int; offset to the read cursor to start comparing
        Returns:
        if the byte buffer data equals the byte array contents true is returned
      • shiftLeftOneByte

        public void shiftLeftOneByte​(byte aRightByte)
        Shift all bytes in the byte buffer to the left and insert a new byte to the right (end of byte buffer)
        Parameters:
        aRightByte - byte; the byte to insert at the right side of the byte buffer after the shift
      • prepareStart

        public int prepareStart()
        Start prepare sequence. This should be called before prepare calls. Resets the prepare cursor to the current writing cursor position.
        Returns:
        the new prepare cursor position. This can be used to calls of writeStart to reuse a byte buffer with partial deviating data.
      • prepare

        public void prepare​(boolean aValue)
        Prepares the byte buffer for later writing of a boolean. Advances the prepare cursor for the correct amount of bytes to write a boolean.
        Parameters:
        aValue - boolean; the boolean to be written later in a call to qWrite
      • prepare

        public void prepare​(byte aValue)
        Prepares the byte buffer for later writing of a byte. Advances the prepare cursor for the correct amount of bytes to write a byte.
        Parameters:
        aValue - byte; the byte to be written later in a call to qWrite
      • prepare

        public void prepare​(int aValue)
        Prepares the byte buffer for later writing of an 32 bit integer. Advances the prepare cursor for the correct amount of bytes to write an 32 bit integer.
        Parameters:
        aValue - int; the 32 bit integer to be written later in a call to qWrite
      • prepare

        public void prepare​(long aValue)
        Prepares the byte buffer for later writing of an 64 bit integer (long). Advances the prepare cursor for the correct amount of bytes to write an 64 bit integer (long).
        Parameters:
        aValue - long; the 64 bit integer (long) to be written later in a call to qWrite
      • prepare

        public void prepare​(float aValue)
        Prepares the byte buffer for later writing of a 32 bit single (float). Advances the prepare cursor for the correct amount of bytes to write a 32 bit single (float).
        Parameters:
        aValue - float; the 32 bit single (float) to be written later in a call to qWrite
      • prepare

        public void prepare​(double aValue)
        Prepares the byte buffer for later writing of a double. Advances the prepare cursor for the correct amount of bytes to write a double.
        Parameters:
        aValue - double; the double to be written later in a call to qWrite
      • prepare

        public void prepare​(String aValue)
        Prepares the byte buffer for later writing of a string. Advances the prepare cursor for the correct amount of bytes to write a string (including its size).
        Parameters:
        aValue - String; the string to be written later in a call to qWrite
      • prepare

        public void prepare​(byte[] aValue)
        Prepares the byte buffer for later writing of a byte array (without size). Advances the prepare cursor for the correct amount of bytes to write a byte array (without size).
        Parameters:
        aValue - byte[]; the byte array to be written later in a call to qWrite
      • prepare

        public void prepare​(TByteBuffer aValue)
        Prepares the byte buffer for later writing of an other byte buffers readable data. Advances the prepare cursor for the correct amount of bytes to write a byte buffers readable data.
        Parameters:
        aValue - TByteBuffer; the byte buffers readable data to be written later in a call to qWrite
      • prepareSize

        public int prepareSize​(int aValueSize)
        Prepares the byte buffer for later writing of the specified number of bytes. Advances the prepare cursor for the correct amount of bytes to write the specified number of bytes.
        Parameters:
        aValueSize - int; the number of bytes to be written later in a call to qWrite
      • prepareApply

        public void prepareApply()
        Adjusts the length of the byte buffer to accommodate at a minimum all prepared data
      • prepareApplyAndTrim

        public void prepareApplyAndTrim()
        Adjusts the length of the byte buffer to accommodate exactly all prepared data
      • writeStart

        public void writeStart​(int aIndex)
        Start writing at the specified 0-based index. Resets the write cursor to the specified 0-based index
        Parameters:
        aIndex - int; the new value for the write cursor
      • getwriteAvailable

        public int getwriteAvailable()
        Returns the room still available in the byte buffer to write data to without reallocating memory.
        Returns:
        the room still left in the byte buffer to write
      • write

        public void write​(boolean aValue)
        Write the specified boolean to the byte buffer. Buffer space is allocated if needed.
        Parameters:
        aValue - boolean; the boolean to be written to the byte buffer
      • write

        public void write​(byte aValue)
        Write the specified byte to the byte buffer. Buffer space is allocated if needed.
        Parameters:
        aValue - byte; the byte to be written to the byte buffer
      • write

        public void write​(int aValue)
        Write the specified 32 bit integer to the byte buffer. Buffer space is allocated if needed.
        Parameters:
        aValue - int; the 32 bit integer to be written to the byte buffer
      • write

        public void write​(long aValue)
        Write the specified 64 bit integer (long) to the byte buffer. Buffer space is allocated if needed.
        Parameters:
        aValue - long; the 64 bit integer (long) to be written to the byte buffer
      • write

        public void write​(float aValue)
        Write the specified single (float) to the byte buffer. Buffer space is allocated if needed.
        Parameters:
        aValue - float; the single (float) to be written to the byte buffer
      • write

        public void write​(double aValue)
        Write the specified double to the byte buffer. Buffer space is allocated if needed.
        Parameters:
        aValue - double; the double to be written to the byte buffer
      • write

        public void write​(String aValue)
        Write the specified string to the byte buffer in UTF-8 format. Buffer space is allocated if needed.
        Parameters:
        aValue - String; the string to be written to the byte buffer
      • write

        public void write​(byte[] aValue)
        Write the specified byte array WITHOUT the size to the byte buffer. Buffer space is allocated if needed.
        Parameters:
        aValue - byte[]; the byte buffer to be written to the byte buffer
      • write

        public void write​(TByteBuffer aValue)
        Write the readable data in the specified byte buffer to this byte buffer. Buffer space is allocated if needed.
        Parameters:
        aValue - TByteBuffer; the byte buffer who's readable data is to be written to this byte buffer
      • qWrite

        public void qWrite​(boolean aValue)
        write a boolean to the buffer; the QWrite methods do not check for room in the buffer
        Parameters:
        aValue - boolean; the boolean value to be written to the buffer
      • qWrite

        public void qWrite​(byte aValue)
        write a single byte to the buffer; the QWrite methods do not check for room in the buffer
        Parameters:
        aValue - byte; the byte value to be written to the buffer
      • qWrite

        public void qWrite​(int aValue)
        write a single integer (32 bit) to the buffer; the QWrite methods do not check for room in the buffer
        Parameters:
        aValue - int; the integer (32 bit) value to be written to the buffer
      • qWrite

        public void qWrite​(long aValue)
        write a single integer (64 bit) to the buffer; the QWrite methods do not check for room in the buffer
        Parameters:
        aValue - long; the integer (64 bit) value to be written to the buffer
      • qWrite

        public void qWrite​(float aValue)
        write a single float (32 bit) to the buffer; the QWrite methods do not check for room in the buffer
        Parameters:
        aValue - float; the float (32 bit) value to be written to the buffer
      • qWrite

        public void qWrite​(double aValue)
        write a single double (64 bit) to the buffer; the QWrite methods do not check for room in the buffer
        Parameters:
        aValue - double; the float (64 bit) value to be written to the buffer
      • qWrite

        public void qWrite​(String aValue)
        Write a string to the buffer, prefixed with the size as a 32 bit integer. The characters are UTF-8 encoded, every char is 1 byte in size The QWrite methods do not check for room in the buffer
        Parameters:
        aValue - String; the float (32 bit) value to be written to the buffer
      • qWrite

        public void qWrite​(byte[] aValue)
        write array of byte WITHOUT size; the QWrite methods do not check for room in the buffer
        Parameters:
        aValue - byte[]; the byte array written to the buffer (without prefixed size)
      • qWrite

        public void qWrite​(TByteBuffer aValue)
        write, with no checking, all readable data from the given byte buffer to this prefixed WITH size
        Parameters:
        aValue - TByteBuffer; readable data in byte buffer to be written to the buffer
      • written

        public boolean written​(int aValueSize)
        signal number of bytes directly written to buffer without using class methods update write cursor and return if it fitted into buffer (should trigger exception ?)
        Parameters:
        aValueSize - int; number of bytes directly written into buffer
        Returns:
        true if all written data fitted into buffer
      • writeApply

        public void writeApply()
        apply written data (trim extra buffer space)