Package org.apache.hadoop.hbase.util
Class ByteBufferArray
java.lang.Object
org.apache.hadoop.hbase.util.ByteBufferArray
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
-
Nested Class Summary
Modifier and TypeClassDescriptionprivate class
Iterator to fetch ByteBuffers from offset with given length in this big logical array. -
Field Summary
Modifier and TypeFieldDescriptionprivate final int
(package private) final ByteBuffer[]
private final int
static final int
private static final org.slf4j.Logger
private static final BiConsumer<ByteBuffer,
ByteBuff> Transfer bytes from sourceByteBuffer
to destinationByteBuff
, Position of both source and destination will be advanced.private static final BiConsumer<ByteBuffer,
ByteBuff> Transfer bytes from sourceByteBuff
to destinationByteBuffer
. -
Constructor Summary
ConstructorDescriptionByteBufferArray
(int bufferSize, int bufferCount, int threadCount, long capacity, ByteBufferAllocator alloc) ByteBufferArray
(long capacity, ByteBufferAllocator allocator) We allocate a number of byte buffers as the capacity. -
Method Summary
Modifier and TypeMethodDescriptionasSubByteBuffers
(long offset, int len) Creates a sub-array from a given array of ByteBuffers from the given offset to the length specified.private void
createBuffers
(int threadCount, ByteBufferAllocator alloc) private static int
getBufferCount
(long capacity) (package private) static int
getBufferSize
(long capacity) 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.int
Transfers bytes from this buffers array into the given destinationByteBuff
private static long
roundUp
(long n, long to) int
Transfers bytes from the given sourceByteBuff
into this buffer array
-
Field Details
-
LOG
-
DEFAULT_BUFFER_SIZE
- See Also:
-
bufferSize
-
bufferCount
-
buffers
-
WRITER
Transfer bytes from sourceByteBuff
to destinationByteBuffer
. Position of both source and destination will be advanced. -
READER
Transfer bytes from sourceByteBuffer
to destinationByteBuff
, Position of both source and destination will be advanced.
-
-
Constructor Details
-
ByteBufferArray
We allocate a number of byte buffers as the capacity.- Parameters:
capacity
- total size of the byte buffer arrayallocator
- the ByteBufferAllocator that will create the buffers- Throws:
IOException
- throws IOException if there is an exception thrown by the allocator
-
ByteBufferArray
ByteBufferArray(int bufferSize, int bufferCount, int threadCount, long capacity, ByteBufferAllocator alloc) throws IOException - Throws:
IOException
-
-
Method Details
-
createBuffers
- Throws:
IOException
-
getBufferSize
-
getBufferCount
-
roundUp
-
read
Transfers bytes from this buffers array into the given destinationByteBuff
- 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
Transfers bytes from the given sourceByteBuff
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
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 totransfer
- the transfer interface.- Returns:
- the length of bytes we transferred.
-
asSubByteBuffers
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.
-