Class ByteBufferArray

java.lang.Object
org.apache.hadoop.hbase.util.ByteBufferArray

@Private public class ByteBufferArray extends Object
This class manages an array of ByteBuffers with a default size 4MB. These buffers are sequential and could be considered as a large buffer.It supports reading/writing data from this large buffer with a position and offset
  • Field Details

  • Constructor Details

  • Method Details

    • createBuffers

      private void createBuffers(int threadCount, ByteBufferAllocator alloc) throws IOException
      Throws:
      IOException
    • getBufferSize

      static int getBufferSize(long capacity)
    • getBufferCount

      private static int getBufferCount(long capacity)
    • roundUp

      private static long roundUp(long n, long to)
    • read

      public int read(long offset, ByteBuff dst)
      Transfers bytes from this buffers array into the given destination ByteBuff
      Parameters:
      offset - start position in this big logical array.
      dst - the destination ByteBuff. Notice that its position will be advanced.
      Returns:
      number of bytes read
    • write

      public int write(long offset, ByteBuff src)
      Transfers bytes from the given source ByteBuff into this buffer array
      Parameters:
      offset - start offset of this big logical array.
      src - the source ByteBuff. Notice that its position will be advanced.
      Returns:
      number of bytes write
    • internalTransfer

      private int internalTransfer(long offset, ByteBuff b, BiConsumer<ByteBuffer,ByteBuff> transfer)
      Transferring all remaining bytes from b to the buffers array starting at offset, or transferring bytes from the buffers array at offset to b until b is filled. Notice that position of ByteBuff b will be advanced.
      Parameters:
      offset - where we start in the big logical array.
      b - the ByteBuff to transfer from or to
      transfer - the transfer interface.
      Returns:
      the length of bytes we transferred.
    • asSubByteBuffers

      public ByteBuffer[] asSubByteBuffers(long offset, int len)
      Creates a sub-array from a given array of ByteBuffers from the given offset to the length specified. For eg, if there are 4 buffers forming an array each with length 10 and if we call asSubByteBuffers(5, 10) then we will create an sub-array consisting of two BBs and the first one be a BB from 'position' 5 to a 'length' 5 and the 2nd BB will be from 'position' 0 to 'length' 5.
      Parameters:
      offset - the position in the whole array which is composited by multiple byte buffers.
      len - the length of bytes
      Returns:
      the underlying ByteBuffers, each ByteBuffer is a slice from the backend and will have a zero position.