public final class ArrowBuf extends Object implements AutoCloseable
ReferenceManager and ArrowBuf can work
with a custom user provided implementation of ReferenceManager
Two important instance variables of an ArrowBuf: (1) address - starting virtual address in the underlying memory chunk that this ArrowBuf has access to (2) length - length (in bytes) in the underlying memory chunk that this ArrowBuf has access to
The mangement (allocation, deallocation, reference counting etc) for
the memory chunk is not done by ArrowBuf.
Default implementation of ReferenceManager, allocation is in
BaseAllocator, BufferLedger and AllocationManager
| Constructor and Description |
|---|
ArrowBuf(ReferenceManager referenceManager,
BufferManager bufferManager,
int length,
long memoryAddress,
boolean isEmpty)
Constructs a new ArrowBuf
|
| Modifier and Type | Method and Description |
|---|---|
NettyArrowBuf |
asNettyBuffer()
Get a wrapper buffer to comply with Netty interfaces and
can be used in RPC/RPC allocator code.
|
int |
capacity() |
ArrowBuf |
capacity(int newCapacity)
Adjusts the capacity of this buffer.
|
void |
checkBytes(int start,
int end)
Allows a function to determine whether not reading a particular string of bytes is valid.
|
ArrowBuf |
clear()
Deprecated.
|
void |
close() |
boolean |
equals(Object obj) |
int |
getActualMemoryConsumed()
Return that is Accounted for by this buffer (and its potentially shared siblings within the
context of the associated allocator).
|
byte |
getByte(int index)
Get byte value stored at a particular index in the
underlying memory chunk this ArrowBuf has access to.
|
void |
getBytes(int index,
ArrowBuf dst,
int dstIndex,
int length)
Copy a given length of data from this ArrowBuf starting at a given index
into a dst ArrowBuf at dstIndex.
|
void |
getBytes(int index,
byte[] dst)
Copy data from this ArrowBuf at a given index in into destination
byte array.
|
void |
getBytes(int index,
byte[] dst,
int dstIndex,
int length)
Copy data from this ArrowBuf at a given index into destination byte array.
|
void |
getBytes(int index,
ByteBuffer dst)
Copy data from this ArrowBuf at a given index into the destination
ByteBuffer.
|
void |
getBytes(int index,
OutputStream out,
int length)
Copy a certain length of bytes from this ArrowBuf at a given
index into the given OutputStream.
|
char |
getChar(int index)
Get char value stored at a particular index in the
underlying memory chunk this ArrowBuf has access to.
|
double |
getDouble(int index)
Get double value stored at a particular index in the
underlying memory chunk this ArrowBuf has access to.
|
float |
getFloat(int index)
Get float value stored at a particular index in the
underlying memory chunk this ArrowBuf has access to.
|
long |
getId()
Get the integer id assigned to this ArrowBuf for debugging purposes.
|
int |
getInt(int index)
Get int value stored at a particular index in the
underlying memory chunk this ArrowBuf has access to.
|
long |
getLong(int index)
Get long value stored at a particular index in the
underlying memory chunk this ArrowBuf has access to.
|
int |
getPossibleMemoryConsumed()
Returns the possible memory consumed by this ArrowBuf in the worse case scenario.
|
ReferenceManager |
getReferenceManager()
Get reference manager for this ArrowBuf.
|
short |
getShort(int index)
Get short value stored at a particular index in the
underlying memory chunk this ArrowBuf has access to.
|
int |
hashCode() |
boolean |
isEmpty() |
long |
memoryAddress() |
ByteBuffer |
nioBuffer() |
ByteBuffer |
nioBuffer(int index,
int length) |
ByteOrder |
order()
Returns the byte order of elements in this buffer.
|
void |
print(StringBuilder sb,
int indent,
BaseAllocator.Verbosity verbosity)
Prints information of this buffer into
sb at the given
indentation and verbosity level. |
int |
readableBytes()
Returns the number of bytes still available to read in this buffer.
|
byte |
readByte()
Read the byte at readerIndex.
|
void |
readBytes(byte[] dst)
Read dst.length bytes at readerIndex into dst byte array
|
int |
readerIndex()
Get the index at which the next byte will be read from.
|
ArrowBuf |
readerIndex(int readerIndex)
Set the reader index for this ArrowBuf.
|
ArrowBuf |
reallocIfNeeded(int size)
Returns
this if size is less then capacity(), otherwise
delegates to BufferManager.replace(ArrowBuf, int) to get a new buffer. |
int |
refCnt() |
void |
release()
Deprecated.
|
void |
release(int decrement)
Deprecated.
|
void |
retain()
Deprecated.
|
void |
retain(int increment)
Deprecated.
|
void |
setByte(int index,
byte value)
Set byte value at a particular index in the
underlying memory chunk this ArrowBuf has access to.
|
void |
setByte(int index,
int value)
Set byte value at a particular index in the
underlying memory chunk this ArrowBuf has access to.
|
void |
setBytes(int index,
ArrowBuf src)
Copy readableBytes() number of bytes from src ArrowBuf
starting from its readerIndex into this ArrowBuf starting
at the given index.
|
void |
setBytes(int index,
ArrowBuf src,
int srcIndex,
int length)
Copy data from src ArrowBuf starting at index srcIndex into this
ArrowBuf at given index.
|
void |
setBytes(int index,
byte[] src)
Copy data from a given byte array into this ArrowBuf starting at
a given index.
|
void |
setBytes(int index,
byte[] src,
int srcIndex,
int length)
Copy data from a given byte array starting at the given source index into
this ArrowBuf at a given index.
|
void |
setBytes(int index,
ByteBuffer src)
Copy data into this ArrowBuf at a given index onwards from
a source ByteBuffer.
|
void |
setBytes(int index,
ByteBuffer src,
int srcIndex,
int length)
Copy data into this ArrowBuf at a given index onwards from
a source ByteBuffer starting at a given srcIndex for a certain
length.
|
int |
setBytes(int index,
InputStream in,
int length)
Copy a certain length of bytes from given InputStream
into this ArrowBuf at the provided index.
|
void |
setChar(int index,
int value)
Set char value at a particular index in the
underlying memory chunk this ArrowBuf has access to.
|
void |
setDouble(int index,
double value)
Set double value at a particular index in the
underlying memory chunk this ArrowBuf has access to.
|
void |
setFloat(int index,
float value)
Set float value at a particular index in the
underlying memory chunk this ArrowBuf has access to.
|
ArrowBuf |
setIndex(int readerIndex,
int writerIndex)
Deprecated.
|
void |
setInt(int index,
int value)
Set int value at a particular index in the
underlying memory chunk this ArrowBuf has access to.
|
void |
setLong(int index,
long value)
Set long value at a particular index in the
underlying memory chunk this ArrowBuf has access to.
|
void |
setShort(int index,
int value)
Set short value at a particular index in the
underlying memory chunk this ArrowBuf has access to.
|
void |
setShort(int index,
short value)
Set short value at a particular index in the
underlying memory chunk this ArrowBuf has access to.
|
ArrowBuf |
setZero(int index,
int length)
Zero-out the bytes in this ArrowBuf starting at
the given index for the given length.
|
ArrowBuf |
slice()
Returns a slice of only the readable bytes in the buffer.
|
ArrowBuf |
slice(int index,
int length)
Returns a slice (view) starting at
index with the given length. |
String |
toHexString(int start,
int length)
Return the buffer's byte contents in the form of a hex dump.
|
String |
toString() |
int |
writableBytes()
Returns the number of bytes still available to write into this buffer before capacity is reached.
|
void |
writeByte(byte value)
Set the provided byte value at the writerIndex.
|
void |
writeByte(int value)
Set the lower order byte for the provided value at
the writerIndex.
|
void |
writeBytes(byte[] src)
Write the bytes from given byte array into this
ArrowBuf starting at writerIndex.
|
void |
writeBytes(byte[] src,
int srcIndex,
int length)
Write the bytes from given byte array starting at srcIndex
into this ArrowBuf starting at writerIndex.
|
void |
writeDouble(double value)
Set the provided double value at the writerIndex.
|
void |
writeFloat(float value)
Set the provided float value at the writerIndex.
|
void |
writeInt(int value)
Set the provided int value at the writerIndex.
|
void |
writeLong(long value)
Set the provided long value at the writerIndex.
|
int |
writerIndex()
Get the index at which next byte will be written to.
|
ArrowBuf |
writerIndex(int writerIndex)
Set the writer index for this ArrowBuf.
|
void |
writeShort(int value)
Set the provided int value as short at the writerIndex.
|
public ArrowBuf(ReferenceManager referenceManager, BufferManager bufferManager, int length, long memoryAddress, boolean isEmpty)
referenceManager - The memory manager to track memory usage and reference count of this bufferlength - The byte length of this bufferisEmpty - Indicates if this buffer is empty which enables some optimizations.public int refCnt()
public void checkBytes(int start,
int end)
Will throw an exception if the memory is not readable for some reason. Only doesn't something in the case that AssertionUtil.BOUNDS_CHECKING_ENABLED is true.
start - The starting position of the bytes to be read.end - The exclusive endpoint of the bytes to be read.public NettyArrowBuf asNettyBuffer()
NettyArrowBufpublic ReferenceManager getReferenceManager()
ReferenceManagerpublic boolean isEmpty()
public int capacity()
public ArrowBuf capacity(int newCapacity)
newCapacity - Must be in in the range [0, length).public ByteOrder order()
public int readableBytes()
public int writableBytes()
public ArrowBuf slice()
public ArrowBuf slice(int index, int length)
index with the given length.public ByteBuffer nioBuffer()
public ByteBuffer nioBuffer(int index, int length)
public long memoryAddress()
public long getLong(int index)
index - index (0 based relative to this ArrowBuf)
where the value will be read frompublic void setLong(int index,
long value)
index - index (0 based relative to this ArrowBuf)
where the value will be writtenvalue - value to writepublic float getFloat(int index)
index - index (0 based relative to this ArrowBuf)
where the value will be read frompublic void setFloat(int index,
float value)
index - index (0 based relative to this ArrowBuf)
where the value will be writtenvalue - value to writepublic double getDouble(int index)
index - index (0 based relative to this ArrowBuf)
where the value will be read frompublic void setDouble(int index,
double value)
index - index (0 based relative to this ArrowBuf)
where the value will be writtenvalue - value to writepublic char getChar(int index)
index - index (0 based relative to this ArrowBuf)
where the value will be read frompublic void setChar(int index,
int value)
index - index (0 based relative to this ArrowBuf)
where the value will be writtenvalue - value to writepublic int getInt(int index)
index - index (0 based relative to this ArrowBuf)
where the value will be read frompublic void setInt(int index,
int value)
index - index (0 based relative to this ArrowBuf)
where the value will be writtenvalue - value to writepublic short getShort(int index)
index - index (0 based relative to this ArrowBuf)
where the value will be read frompublic void setShort(int index,
int value)
index - index (0 based relative to this ArrowBuf)
where the value will be writtenvalue - value to writepublic void setShort(int index,
short value)
index - index (0 based relative to this ArrowBuf)
where the value will be writtenvalue - value to writepublic void setByte(int index,
int value)
index - index (0 based relative to this ArrowBuf)
where the value will be writtenvalue - value to writepublic void setByte(int index,
byte value)
index - index (0 based relative to this ArrowBuf)
where the value will be writtenvalue - value to writepublic byte getByte(int index)
index - index (0 based relative to this ArrowBuf)
where the value will be read frompublic byte readByte()
public void readBytes(byte[] dst)
dst - byte array where the data will be writtenpublic void writeByte(byte value)
value - value to setpublic void writeByte(int value)
value - value to be setpublic void writeBytes(byte[] src)
src - src byte arraypublic void writeBytes(byte[] src,
int srcIndex,
int length)
src - src byte arraysrcIndex - index in the byte array where the copy will being fromlength - length of data to copypublic void writeShort(int value)
value - value to setpublic void writeInt(int value)
value - value to setpublic void writeLong(long value)
value - value to setpublic void writeFloat(float value)
value - value to setpublic void writeDouble(double value)
value - value to setpublic void getBytes(int index,
byte[] dst)
index - starting index (0 based relative to the portion of memory)
this ArrowBuf has access todst - byte array to copy the data intopublic void getBytes(int index,
byte[] dst,
int dstIndex,
int length)
index - index (0 based relative to the portion of memory
this ArrowBuf has access to)dst - byte array to copy the data intodstIndex - starting index in dst byte array to copy intolength - length of data to copy from this ArrowBufpublic void setBytes(int index,
byte[] src)
index - starting index (0 based relative to the portion of memory)
this ArrowBuf has access tosrc - byte array to copy the data frompublic void setBytes(int index,
byte[] src,
int srcIndex,
int length)
index - index (0 based relative to the portion of memory this ArrowBuf
has access to)src - src byte array to copy the data fromsrcIndex - index in the byte array where the copy will start fromlength - length of data to copy from byte arraypublic void getBytes(int index,
ByteBuffer dst)
index - index (0 based relative to the portion of memory this ArrowBuf
has access to)dst - dst ByteBuffer where the data will be copied intopublic void setBytes(int index,
ByteBuffer src)
index - index index (0 based relative to the portion of memory
this ArrowBuf has access to)src - src ByteBuffer where the data will be copied frompublic void setBytes(int index,
ByteBuffer src,
int srcIndex,
int length)
index - index (0 based relative to the portion of memory
this ArrowBuf has access to)src - src ByteBuffer where the data will be copied fromsrcIndex - starting index in the src ByteBuffer where the data copy
will start fromlength - length of data to copy from src ByteBufferpublic void getBytes(int index,
ArrowBuf dst,
int dstIndex,
int length)
index - index (0 based relative to the portion of memory
this ArrowBuf has access to)dst - dst ArrowBuf where the data will be copied intodstIndex - index (0 based relative to the portion of memory
dst ArrowBuf has access to)length - length of data to copypublic void setBytes(int index,
ArrowBuf src,
int srcIndex,
int length)
index - index index (0 based relative to the portion of memory
this ArrowBuf has access to)src - src ArrowBuf where the data will be copied fromsrcIndex - starting index in the src ArrowBuf where the copy
will begin fromlength - length of data to copy from src ArrowBufpublic void setBytes(int index,
ArrowBuf src)
index - index index (0 based relative to the portion of memory
this ArrowBuf has access to)src - src ArrowBuf where the data will be copied frompublic int setBytes(int index,
InputStream in,
int length)
throws IOException
index - index index (0 based relative to the portion of memory
this ArrowBuf has access to)in - src stream to copy fromlength - length of data to copyIOException - on failing to read from streampublic void getBytes(int index,
OutputStream out,
int length)
throws IOException
index - index index (0 based relative to the portion of memory
this ArrowBuf has access to)out - dst stream to copy data intolength - length of data to copyIOException - on failing to write to streampublic void close()
close in interface AutoCloseablepublic int getPossibleMemoryConsumed()
public int getActualMemoryConsumed()
public String toHexString(int start, int length)
start - the starting byte indexlength - how many bytes to logpublic long getId()
public void print(StringBuilder sb, int indent, BaseAllocator.Verbosity verbosity)
sb at the given
indentation and verbosity level.
It will include history if BaseAllocator.DEBUG is true and the verbosity.includeHistoricalLog are true.
public int readerIndex()
public int writerIndex()
public ArrowBuf readerIndex(int readerIndex)
readerIndex - new reader indexpublic ArrowBuf writerIndex(int writerIndex)
writerIndex - new writer indexpublic ArrowBuf setZero(int index, int length)
index - index index (0 based relative to the portion of memory
this ArrowBuf has access to)length - length of bytes to zero-outpublic ArrowBuf reallocIfNeeded(int size)
this if size is less then capacity(), otherwise
delegates to BufferManager.replace(ArrowBuf, int) to get a new buffer.@Deprecated public void release()
@Deprecated public void release(int decrement)
@Deprecated public void retain()
@Deprecated public void retain(int increment)
@Deprecated public ArrowBuf clear()
@Deprecated public ArrowBuf setIndex(int readerIndex, int writerIndex)
readerIndex - index to read fromwriterIndex - index to write toCopyright © 2019 The Apache Software Foundation. All rights reserved.