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 management (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,
long capacity,
long memoryAddress)
Constructs a new ArrowBuf.
|
Modifier and Type | Method and Description |
---|---|
long |
capacity() |
ArrowBuf |
capacity(long newCapacity)
Adjusts the capacity of this buffer.
|
void |
checkBytes(long start,
long end)
Allows a function to determine whether not reading a particular string of bytes is valid.
|
ArrowBuf |
clear() |
void |
close() |
boolean |
equals(Object obj) |
long |
getActualMemoryConsumed()
Return that is Accounted for by this buffer (and its potentially shared siblings within the
context of the associated allocator).
|
byte |
getByte(long index)
Get byte value stored at a particular index in the
underlying memory chunk this ArrowBuf has access to.
|
void |
getBytes(long index,
ArrowBuf dst,
long 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(long index,
byte[] dst)
Copy data from this ArrowBuf at a given index in into destination
byte array.
|
void |
getBytes(long index,
byte[] dst,
int dstIndex,
int length)
Copy data from this ArrowBuf at a given index into destination byte array.
|
void |
getBytes(long index,
ByteBuffer dst)
Copy data from this ArrowBuf at a given index into the destination
ByteBuffer.
|
void |
getBytes(long index,
OutputStream out,
int length)
Copy a certain length of bytes from this ArrowBuf at a given
index into the given OutputStream.
|
char |
getChar(long index)
Get char value stored at a particular index in the
underlying memory chunk this ArrowBuf has access to.
|
double |
getDouble(long index)
Get double value stored at a particular index in the
underlying memory chunk this ArrowBuf has access to.
|
float |
getFloat(long 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(long index)
Get int value stored at a particular index in the
underlying memory chunk this ArrowBuf has access to.
|
long |
getLong(long index)
Get long value stored at a particular index in the
underlying memory chunk this ArrowBuf has access to.
|
long |
getPossibleMemoryConsumed()
Returns the possible memory consumed by this ArrowBuf in the worse case scenario.
|
ReferenceManager |
getReferenceManager()
Get reference manager for this ArrowBuf.
|
short |
getShort(long index)
Get short value stored at a particular index in the
underlying memory chunk this ArrowBuf has access to.
|
int |
hashCode() |
long |
memoryAddress() |
ByteBuffer |
nioBuffer()
Make a nio byte buffer from this arrowbuf.
|
ByteBuffer |
nioBuffer(long index,
int length)
Make a nio byte buffer from this ArrowBuf.
|
ByteOrder |
order()
Returns the byte order of elements in this buffer.
|
void |
print(StringBuilder sb,
int indent)
Print detailed information of this buffer into
sb . |
void |
print(StringBuilder sb,
int indent,
BaseAllocator.Verbosity verbosity)
Print information of this buffer into
sb at the given
indentation and verbosity level. |
long |
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
|
long |
readerIndex()
Get the index at which the next byte will be read from.
|
ArrowBuf |
readerIndex(long readerIndex)
Set the reader index for this ArrowBuf.
|
ArrowBuf |
reallocIfNeeded(long size)
Returns
this if size is less then capacity() , otherwise
delegates to BufferManager.replace(ArrowBuf, long) to get a new buffer. |
int |
refCnt() |
void |
setByte(long index,
byte value)
Set byte value at a particular index in the
underlying memory chunk this ArrowBuf has access to.
|
void |
setByte(long index,
int value)
Set byte value at a particular index in the
underlying memory chunk this ArrowBuf has access to.
|
void |
setBytes(long 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(long index,
ArrowBuf src,
long srcIndex,
long length)
Copy data from src ArrowBuf starting at index srcIndex into this
ArrowBuf at given index.
|
void |
setBytes(long index,
byte[] src)
Copy data from a given byte array into this ArrowBuf starting at
a given index.
|
void |
setBytes(long index,
byte[] src,
int srcIndex,
long length)
Copy data from a given byte array starting at the given source index into
this ArrowBuf at a given index.
|
void |
setBytes(long index,
ByteBuffer src)
Copy data into this ArrowBuf at a given index onwards from
a source ByteBuffer.
|
void |
setBytes(long 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(long index,
InputStream in,
int length)
Copy a certain length of bytes from given InputStream
into this ArrowBuf at the provided index.
|
void |
setChar(long index,
int value)
Set char value at a particular index in the
underlying memory chunk this ArrowBuf has access to.
|
void |
setDouble(long index,
double value)
Set double value at a particular index in the
underlying memory chunk this ArrowBuf has access to.
|
void |
setFloat(long index,
float value)
Set float value at a particular index in the
underlying memory chunk this ArrowBuf has access to.
|
void |
setInt(long index,
int value)
Set int value at a particular index in the
underlying memory chunk this ArrowBuf has access to.
|
void |
setLong(long index,
long value)
Set long value at a particular index in the
underlying memory chunk this ArrowBuf has access to.
|
ArrowBuf |
setOne(int index,
int length)
Deprecated.
use
setOne(long, long) instead. |
ArrowBuf |
setOne(long index,
long length)
Sets all bits to one in the specified range.
|
void |
setShort(long index,
int value)
Set short value at a particular index in the
underlying memory chunk this ArrowBuf has access to.
|
void |
setShort(long index,
short value)
Set short value at a particular index in the
underlying memory chunk this ArrowBuf has access to.
|
ArrowBuf |
setZero(long index,
long 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(long index,
long length)
Returns a slice (view) starting at
index with the given length . |
String |
toHexString(long start,
int length)
Return the buffer's byte contents in the form of a hex dump.
|
String |
toString() |
long |
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.
|
long |
writerIndex()
Get the index at which next byte will be written to.
|
ArrowBuf |
writerIndex(long 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, long capacity, long memoryAddress)
referenceManager
- The memory manager to track memory usage and reference count of this buffercapacity
- The capacity in bytes of this bufferpublic int refCnt()
public void checkBytes(long start, long 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 ReferenceManager getReferenceManager()
ReferenceManager
public long capacity()
public ArrowBuf capacity(long newCapacity)
newCapacity
- Must be in in the range [0, length).public ByteOrder order()
public long readableBytes()
public long writableBytes()
public ArrowBuf slice()
public ArrowBuf slice(long index, long length)
index
with the given length
.public ByteBuffer nioBuffer()
public ByteBuffer nioBuffer(long index, int length)
public long memoryAddress()
public long getLong(long index)
index
- index (0 based relative to this ArrowBuf)
where the value will be read frompublic void setLong(long index, long value)
index
- index (0 based relative to this ArrowBuf)
where the value will be writtenvalue
- value to writepublic float getFloat(long index)
index
- index (0 based relative to this ArrowBuf)
where the value will be read frompublic void setFloat(long index, float value)
index
- index (0 based relative to this ArrowBuf)
where the value will be writtenvalue
- value to writepublic double getDouble(long index)
index
- index (0 based relative to this ArrowBuf)
where the value will be read frompublic void setDouble(long index, double value)
index
- index (0 based relative to this ArrowBuf)
where the value will be writtenvalue
- value to writepublic char getChar(long index)
index
- index (0 based relative to this ArrowBuf)
where the value will be read frompublic void setChar(long index, int value)
index
- index (0 based relative to this ArrowBuf)
where the value will be writtenvalue
- value to writepublic int getInt(long index)
index
- index (0 based relative to this ArrowBuf)
where the value will be read frompublic void setInt(long index, int value)
index
- index (0 based relative to this ArrowBuf)
where the value will be writtenvalue
- value to writepublic short getShort(long index)
index
- index (0 based relative to this ArrowBuf)
where the value will be read frompublic void setShort(long index, int value)
index
- index (0 based relative to this ArrowBuf)
where the value will be writtenvalue
- value to writepublic void setShort(long index, short value)
index
- index (0 based relative to this ArrowBuf)
where the value will be writtenvalue
- value to writepublic void setByte(long index, int value)
index
- index (0 based relative to this ArrowBuf)
where the value will be writtenvalue
- value to writepublic void setByte(long index, byte value)
index
- index (0 based relative to this ArrowBuf)
where the value will be writtenvalue
- value to writepublic byte getByte(long 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(long 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(long 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(long 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(long index, byte[] src, int srcIndex, long 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(long 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(long 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(long 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(long index, ArrowBuf dst, long 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(long index, ArrowBuf src, long srcIndex, long 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(long 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(long 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(long 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 AutoCloseable
public long getPossibleMemoryConsumed()
public long getActualMemoryConsumed()
public String toHexString(long 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 void print(StringBuilder sb, int indent)
sb
.
Most information will only be present if BaseAllocator.DEBUG is true.
public long readerIndex()
public long writerIndex()
public ArrowBuf readerIndex(long readerIndex)
readerIndex
- new reader indexpublic ArrowBuf writerIndex(long writerIndex)
writerIndex
- new writer indexpublic ArrowBuf setZero(long index, long length)
index
- index index (0 based relative to the portion of memory
this ArrowBuf has access to)length
- length of bytes to zero-out@Deprecated public ArrowBuf setOne(int index, int length)
setOne(long, long)
instead.index
- index index (0 based relative to the portion of memory
this ArrowBuf has access to)length
- length of bytes to set.public ArrowBuf setOne(long index, long length)
index
- index index (0 based relative to the portion of memory
this ArrowBuf has access to)length
- length of bytes to set.public ArrowBuf reallocIfNeeded(long size)
this
if size is less then capacity()
, otherwise
delegates to BufferManager.replace(ArrowBuf, long)
to get a new buffer.public ArrowBuf clear()
Copyright © 2023 The Apache Software Foundation. All rights reserved.