@InterfaceAudience.Private public class ByteBufferArray extends Object
Modifier and Type | Class and Description |
---|---|
private class |
ByteBufferArray.BufferIterator
Iterator to fetch ByteBuffers from offset with given length in this big logical array.
|
Modifier and Type | Field and Description |
---|---|
private int |
bufferCount |
(package private) ByteBuffer[] |
buffers |
private int |
bufferSize |
static int |
DEFAULT_BUFFER_SIZE |
private static org.slf4j.Logger |
LOG |
private static BiConsumer<ByteBuffer,ByteBuff> |
READER
Transfer bytes from source
ByteBuffer to destination ByteBuff , Position of both
source and destination will be advanced. |
private static BiConsumer<ByteBuffer,ByteBuff> |
WRITER
Transfer bytes from source
ByteBuff to destination ByteBuffer . |
Constructor and Description |
---|
ByteBufferArray(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.
|
Modifier and Type | Method and Description |
---|---|
ByteBuffer[] |
asSubByteBuffers(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 |
read(long offset,
ByteBuff dst)
Transfers bytes from this buffers array into the given destination
ByteBuff |
private static long |
roundUp(long n,
long to) |
int |
write(long offset,
ByteBuff src)
Transfers bytes from the given source
ByteBuff into this buffer array |
private static final org.slf4j.Logger LOG
public static final int DEFAULT_BUFFER_SIZE
private final int bufferSize
private final int bufferCount
final ByteBuffer[] buffers
private static final BiConsumer<ByteBuffer,ByteBuff> WRITER
ByteBuff
to destination ByteBuffer
. Position of both
source and destination will be advanced.private static final BiConsumer<ByteBuffer,ByteBuff> READER
ByteBuffer
to destination ByteBuff
, Position of both
source and destination will be advanced.public ByteBufferArray(long capacity, ByteBufferAllocator allocator) throws IOException
capacity
- total size of the byte buffer arrayallocator
- the ByteBufferAllocator that will create the buffersIOException
- throws IOException if there is an exception thrown by the allocatorByteBufferArray(int bufferSize, int bufferCount, int threadCount, long capacity, ByteBufferAllocator alloc) throws IOException
IOException
private void createBuffers(int threadCount, ByteBufferAllocator alloc) throws IOException
IOException
static int getBufferSize(long capacity)
private static int getBufferCount(long capacity)
private static long roundUp(long n, long to)
public int read(long offset, ByteBuff dst)
ByteBuff
offset
- start position in this big logical array.dst
- the destination ByteBuff. Notice that its position will be advanced.public int write(long offset, ByteBuff src)
ByteBuff
into this buffer arrayoffset
- start offset of this big logical array.src
- the source ByteBuff. Notice that its position will be advanced.private int internalTransfer(long offset, ByteBuff b, BiConsumer<ByteBuffer,ByteBuff> transfer)
offset
- where we start in the big logical array.b
- the ByteBuff to transfer from or totransfer
- the transfer interface.public ByteBuffer[] asSubByteBuffers(long offset, int len)
offset
- the position in the whole array which is composited by multiple byte buffers.len
- the length of bytesCopyright © 2007–2020 The Apache Software Foundation. All rights reserved.