Class ByteBuffer

    • Constructor Detail

      • ByteBuffer

        public ByteBuffer()
        construct new java.nio.ByteBuffer-based ByteBuffer with DEFAULT_INITIAL_CAPACITY
      • ByteBuffer

        public ByteBuffer​(int nCapacity)
        construct new java.nio.ByteBuffer-based ByteBuffer with DEFAULT_INITIAL_CAPACITY
        Parameters:
        nCapacity - initial capacity
    • Method Detail

      • clear

        public IoBuffer clear()
        Description copied from interface: IoBufferHeader
        Clears this buffer. The position is set to zero amd the limit is set to the capacity.

        Invoke this method before using a sequence of channel-read or put operations to fill this buffer. For example:

         buf.clear(); // Prepare buffer for reading
         in.read(buf); // Read data
         

        This method does not actually erase the data in the buffer, but it is named as if it did because it will most often be used in situations in which that might as well be the case.

        Specified by:
        clear in interface IoBufferHeader<IoBuffer>
        Returns:
        itself (fluent design)
      • forceCapacity

        public IoBuffer forceCapacity​(long length,
                                      long preserve)
        Description copied from interface: IoBufferHeader
        Forces buffer to contain the given number of entries, preserving just a part of the array.
        Specified by:
        forceCapacity in interface IoBufferHeader<IoBuffer>
        Parameters:
        length - the new minimum length for this array.
        preserve - the number of elements of the old buffer that shall be preserved in case a new allocation is necessary.
        Returns:
        itself (fluent design)
      • getBoolean

        public boolean getBoolean()
        Specified by:
        getBoolean in interface IoBuffer
      • getBooleanArray

        public boolean[] getBooleanArray​(boolean[] dst,
                                         long offset,
                                         int length)
        Specified by:
        getBooleanArray in interface IoBuffer
      • getByte

        public byte getByte()
        Specified by:
        getByte in interface IoBuffer
      • getByteArray

        public byte[] getByteArray​(byte[] dst,
                                   long offset,
                                   int length)
        Specified by:
        getByteArray in interface IoBuffer
      • getChar

        public char getChar()
        Specified by:
        getChar in interface IoBuffer
      • getCharArray

        public char[] getCharArray​(char[] dst,
                                   long offset,
                                   int length)
        Specified by:
        getCharArray in interface IoBuffer
      • getDouble

        public double getDouble()
        Specified by:
        getDouble in interface IoBuffer
      • getDoubleArray

        public double[] getDoubleArray​(double[] dst,
                                       long offset,
                                       int length)
        Specified by:
        getDoubleArray in interface IoBuffer
      • getFloat

        public float getFloat()
        Specified by:
        getFloat in interface IoBuffer
      • getFloatArray

        public float[] getFloatArray​(float[] dst,
                                     long offset,
                                     int length)
        Specified by:
        getFloatArray in interface IoBuffer
      • getInt

        public int getInt()
        Specified by:
        getInt in interface IoBuffer
      • getIntArray

        public int[] getIntArray​(int[] dst,
                                 long offset,
                                 int length)
        Specified by:
        getIntArray in interface IoBuffer
      • getLong

        public long getLong()
        Specified by:
        getLong in interface IoBuffer
      • getLongArray

        public long[] getLongArray​(long[] dst,
                                   long offset,
                                   int length)
        Specified by:
        getLongArray in interface IoBuffer
      • getShort

        public short getShort()
        Specified by:
        getShort in interface IoBuffer
      • getShortArray

        public short[] getShortArray​(short[] dst,
                                     long offset,
                                     int length)
        Specified by:
        getShortArray in interface IoBuffer
      • getString

        public java.lang.String getString()
        Specified by:
        getString in interface IoBuffer
      • getStringArray

        public java.lang.String[] getStringArray​(java.lang.String[] dst,
                                                 long offset,
                                                 int length)
        Specified by:
        getStringArray in interface IoBuffer
      • hasRemaining

        public boolean hasRemaining()
        Specified by:
        hasRemaining in interface IoBufferHeader<IoBuffer>
        Returns:
        true if, and only if, there is at least one element remaining in this buffer
      • isReadOnly

        public boolean isReadOnly()
        Specified by:
        isReadOnly in interface IoBufferHeader<IoBuffer>
        Returns:
        true if, and only if, this buffer is read-only
      • limit

        public IoBuffer limit​(int newLimit)
        Description copied from interface: IoBufferHeader
        Sets this buffer's limit. If the position is larger than the new limit then it is set to the new limit. If the mark is defined and larger than the new limit then it is discarded.
        Specified by:
        limit in interface IoBufferHeader<IoBuffer>
        Parameters:
        newLimit - the new limit value; must be non-negative and no larger than this buffer's capacity
        Returns:
        itself (fluent design)
      • lock

        public java.util.concurrent.locks.ReadWriteLock lock()
        Description copied from interface: IoBufferHeader
        For efficiency/performance reasons the buffer implementation is not required to safe-guard each put/get method independently. Thus the user-code should acquire the given lock around a set of put/get appropriately.
        Specified by:
        lock in interface IoBufferHeader<IoBuffer>
        Returns:
        the read-write lock
      • position

        public IoBuffer position​(long newPosition)
        Description copied from interface: IoBufferHeader
        Sets this buffer's position. If the mark is defined and larger than the new position then it is discarded.
        Specified by:
        position in interface IoBufferHeader<IoBuffer>
        Parameters:
        newPosition - the new position value; must be non-negative and no larger than the current limit
        Returns:
        itself (fluent design)
      • putByteArray

        public IoBuffer putByteArray​(byte[] src,
                                     long offset,
                                     int nToCopy)
        Specified by:
        putByteArray in interface IoBuffer
      • putCharArray

        public IoBuffer putCharArray​(char[] src,
                                     long offset,
                                     int nToCopy)
        Specified by:
        putCharArray in interface IoBuffer
      • putIntArray

        public IoBuffer putIntArray​(int[] src,
                                    long offset,
                                    int nToCopy)
        Specified by:
        putIntArray in interface IoBuffer
      • putLongArray

        public IoBuffer putLongArray​(long[] src,
                                     long offset,
                                     int nToCopy)
        Specified by:
        putLongArray in interface IoBuffer
      • putStringArray

        public IoBuffer putStringArray​(java.lang.String[] src,
                                       long offset,
                                       int nToCopy)
        Specified by:
        putStringArray in interface IoBuffer
      • remaining

        public long remaining()
        Specified by:
        remaining in interface IoBufferHeader<IoBuffer>
        Returns:
        the number of elements remaining in this buffer
      • trim

        public IoBuffer trim()
        Description copied from interface: IoBufferHeader
        Trims the internal buffer array so that the capacity is equal to the size.
        Specified by:
        trim in interface IoBufferHeader<IoBuffer>
        Returns:
        itself (fluent design)
        See Also:
        ArrayList.trimToSize()
      • trim

        public IoBuffer trim​(int requestedCapacity)
        Description copied from interface: IoBufferHeader
        Trims the internal buffer array if it is too large. If the current array length is smaller than or equal to n, this method does nothing. Otherwise, it trims the array length to the maximum between requestedCapacity and IoBufferHeader.capacity().

        This method is useful when reusing FastBuffers. Clearing a list leaves the array length untouched. If you are reusing a list many times, you can call this method with a typical size to avoid keeping around a very large array just because of a few large transient lists.

        Specified by:
        trim in interface IoBufferHeader<IoBuffer>
        Parameters:
        requestedCapacity - the threshold for the trimming.
        Returns:
        itself (fluent design)