Class ByteBufferReadWriteBuf

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      Clears (resets) the buffer so that it can be reused.
      byte[] data()
      Expose ReadBuf as an array of bytes.
      byte get​(int index)
      Read a byte from data.
      boolean getBoolean​(int index)
      Read boolean from data.
      double getDouble​(int index)
      Read a 64-bit float from data.
      float getFloat​(int index)
      Read a 32-bit float from data.
      int getInt​(int index)
      Read a 32-bit int from data.
      long getLong​(int index)
      Read a 64-bit long from data.
      short getShort​(int index)
      Read a short from data.
      java.lang.String getString​(int start, int size)
      Read an UTF-8 string from data.
      int limit()
      Defines the size of the message in the buffer.
      void put​(byte value)
      Write a byte into the buffer at writePosition().
      void put​(byte[] value, int start, int length)
      Put an array of bytes into the buffer at writePosition().
      void putBoolean​(boolean value)
      Put a boolean into the buffer at writePosition() .
      void putDouble​(double value)
      Write a 64-bit float into the buffer at writePosition().
      void putFloat​(float value)
      Write a 32-bit float into the buffer at writePosition().
      void putInt​(int value)
      Write a 32-bit into in the buffer at writePosition().
      void putLong​(long value)
      Write a 64-bit into in the buffer at writePosition().
      void putShort​(short value)
      Write a 16-bit into in the buffer at writePosition().
      boolean requestCapacity​(int capacity)
      Request capacity of the buffer.
      void set​(int index, byte value)
      Read a byte from data.
      void set​(int index, byte[] value, int start, int length)
      Write an array of bytes into the buffer.
      void setBoolean​(int index, boolean value)
      Write boolean into a given position on the buffer.
      void setDouble​(int index, double value)
      Read a 64-bit float from data.
      void setFloat​(int index, float value)
      Read a 32-bit float from data.
      void setInt​(int index, int value)
      Read a 32-bit int from data.
      void setLong​(int index, long value)
      Read a 64-bit long from data.
      void setShort​(int index, short value)
      Read a short from data.
      int writePosition()  
      • Methods inherited from class java.lang.Object

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

      • ByteBufferReadWriteBuf

        public ByteBufferReadWriteBuf​(java.nio.ByteBuffer bb)
    • Method Detail

      • clear

        public void clear()
        Description copied from interface: ReadWriteBuf
        Clears (resets) the buffer so that it can be reused. Write position will be set to the start.
        Specified by:
        clear in interface ReadWriteBuf
      • getBoolean

        public boolean getBoolean​(int index)
        Description copied from interface: ReadBuf
        Read boolean from data. Booleans as stored as single byte
        Specified by:
        getBoolean in interface ReadBuf
        Parameters:
        index - position of the element in ReadBuf
        Returns:
        boolean element
      • get

        public byte get​(int index)
        Description copied from interface: ReadBuf
        Read a byte from data.
        Specified by:
        get in interface ReadBuf
        Parameters:
        index - position of the element in ReadBuf
        Returns:
        a byte
      • getShort

        public short getShort​(int index)
        Description copied from interface: ReadBuf
        Read a short from data.
        Specified by:
        getShort in interface ReadBuf
        Parameters:
        index - position of the element in ReadBuf
        Returns:
        a short
      • getInt

        public int getInt​(int index)
        Description copied from interface: ReadBuf
        Read a 32-bit int from data.
        Specified by:
        getInt in interface ReadBuf
        Parameters:
        index - position of the element in ReadBuf
        Returns:
        an int
      • getLong

        public long getLong​(int index)
        Description copied from interface: ReadBuf
        Read a 64-bit long from data.
        Specified by:
        getLong in interface ReadBuf
        Parameters:
        index - position of the element in ReadBuf
        Returns:
        a long
      • getFloat

        public float getFloat​(int index)
        Description copied from interface: ReadBuf
        Read a 32-bit float from data.
        Specified by:
        getFloat in interface ReadBuf
        Parameters:
        index - position of the element in ReadBuf
        Returns:
        a float
      • getDouble

        public double getDouble​(int index)
        Description copied from interface: ReadBuf
        Read a 64-bit float from data.
        Specified by:
        getDouble in interface ReadBuf
        Parameters:
        index - position of the element in ReadBuf
        Returns:
        a double
      • getString

        public java.lang.String getString​(int start,
                                          int size)
        Description copied from interface: ReadBuf
        Read an UTF-8 string from data.
        Specified by:
        getString in interface ReadBuf
        Parameters:
        start - initial element of the string
        size - size of the string in bytes.
        Returns:
        a String
      • data

        public byte[] data()
        Description copied from interface: ReadBuf
        Expose ReadBuf as an array of bytes. This method is meant to be as efficient as possible, so for a array-backed ReadBuf, it should return its own internal data. In case access to internal data is not possible, a copy of the data into an array of bytes might occur.
        Specified by:
        data in interface ReadBuf
        Returns:
        ReadBuf as an array of bytes
      • putBoolean

        public void putBoolean​(boolean value)
        Description copied from interface: ReadWriteBuf
        Put a boolean into the buffer at writePosition() . Booleans as stored as single byte. Write position will be incremented.
        Specified by:
        putBoolean in interface ReadWriteBuf
      • put

        public void put​(byte[] value,
                        int start,
                        int length)
        Description copied from interface: ReadWriteBuf
        Put an array of bytes into the buffer at writePosition(). Write position will be incremented.
        Specified by:
        put in interface ReadWriteBuf
        Parameters:
        value - the data to be copied
        start - initial position on value to be copied
        length - amount of bytes to be copied
      • put

        public void put​(byte value)
        Description copied from interface: ReadWriteBuf
        Write a byte into the buffer at writePosition(). Write position will be incremented.
        Specified by:
        put in interface ReadWriteBuf
      • putShort

        public void putShort​(short value)
        Description copied from interface: ReadWriteBuf
        Write a 16-bit into in the buffer at writePosition(). Write position will be incremented.
        Specified by:
        putShort in interface ReadWriteBuf
      • putInt

        public void putInt​(int value)
        Description copied from interface: ReadWriteBuf
        Write a 32-bit into in the buffer at writePosition(). Write position will be incremented.
        Specified by:
        putInt in interface ReadWriteBuf
      • putLong

        public void putLong​(long value)
        Description copied from interface: ReadWriteBuf
        Write a 64-bit into in the buffer at writePosition(). Write position will be incremented.
        Specified by:
        putLong in interface ReadWriteBuf
      • putFloat

        public void putFloat​(float value)
        Description copied from interface: ReadWriteBuf
        Write a 32-bit float into the buffer at writePosition(). Write position will be incremented.
        Specified by:
        putFloat in interface ReadWriteBuf
      • putDouble

        public void putDouble​(double value)
        Description copied from interface: ReadWriteBuf
        Write a 64-bit float into the buffer at writePosition(). Write position will be incremented.
        Specified by:
        putDouble in interface ReadWriteBuf
      • setBoolean

        public void setBoolean​(int index,
                               boolean value)
        Description copied from interface: ReadWriteBuf
        Write boolean into a given position on the buffer. Booleans as stored as single byte.
        Specified by:
        setBoolean in interface ReadWriteBuf
        Parameters:
        index - position of the element in buffer
      • set

        public void set​(int index,
                        byte value)
        Description copied from interface: ReadWriteBuf
        Read a byte from data.
        Specified by:
        set in interface ReadWriteBuf
        Parameters:
        index - position of the element in the buffer
      • set

        public void set​(int index,
                        byte[] value,
                        int start,
                        int length)
        Description copied from interface: ReadWriteBuf
        Write an array of bytes into the buffer.
        Specified by:
        set in interface ReadWriteBuf
        Parameters:
        index - initial position of the buffer to be written
        value - the data to be copied
        start - initial position on value to be copied
        length - amount of bytes to be copied
      • setShort

        public void setShort​(int index,
                             short value)
        Description copied from interface: ReadWriteBuf
        Read a short from data.
        Specified by:
        setShort in interface ReadWriteBuf
        Parameters:
        index - position of the element in ReadBuf
      • setInt

        public void setInt​(int index,
                           int value)
        Description copied from interface: ReadWriteBuf
        Read a 32-bit int from data.
        Specified by:
        setInt in interface ReadWriteBuf
        Parameters:
        index - position of the element in ReadBuf
      • setLong

        public void setLong​(int index,
                            long value)
        Description copied from interface: ReadWriteBuf
        Read a 64-bit long from data.
        Specified by:
        setLong in interface ReadWriteBuf
        Parameters:
        index - position of the element in ReadBuf
      • setFloat

        public void setFloat​(int index,
                             float value)
        Description copied from interface: ReadWriteBuf
        Read a 32-bit float from data.
        Specified by:
        setFloat in interface ReadWriteBuf
        Parameters:
        index - position of the element in ReadBuf
      • setDouble

        public void setDouble​(int index,
                              double value)
        Description copied from interface: ReadWriteBuf
        Read a 64-bit float from data.
        Specified by:
        setDouble in interface ReadWriteBuf
        Parameters:
        index - position of the element in ReadBuf
      • limit

        public int limit()
        Description copied from interface: ReadWriteBuf
        Defines the size of the message in the buffer. It also determines last position that buffer can be read or write. Last byte to be accessed is in position limit() -1.
        Specified by:
        limit in interface ReadBuf
        Specified by:
        limit in interface ReadWriteBuf
        Returns:
        indicate last position
      • requestCapacity

        public boolean requestCapacity​(int capacity)
        Description copied from interface: ReadWriteBuf
        Request capacity of the buffer. In case buffer is already larger than the requested, this method will just return true. Otherwise It might try to resize the buffer.
        Specified by:
        requestCapacity in interface ReadWriteBuf
        Returns:
        true if buffer is able to offer the requested capacity