public final class BufferUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static int |
byteToInt(byte b) |
static void |
cleanDirectBuffer(ByteBuffer buffer)
Forces to unmap a direct buffer if this buffer is no longer used.
|
static ByteBuffer |
cloneByteBuffer(ByteBuffer buf)
Clones a bytebuffer.
|
static List<ByteBuffer> |
cloneByteBufferList(List<ByteBuffer> source)
Clones a list of ByteBuffers.
|
static boolean |
equalIncreasingByteArray(int len,
byte[] arr)
Checks if the given byte array starts with an increasing sequence of bytes starting at zero of
length equal to or greater than the given length.
|
static boolean |
equalIncreasingByteArray(int start,
int len,
byte[] arr)
Checks if the given byte array starts with an increasing sequence of bytes starting at the
given value of length equal to or greater than the given length.
|
static boolean |
equalIncreasingByteBuffer(int start,
int len,
ByteBuffer buf)
Checks if the given ByteBuffer starts with an increasing sequence of bytes starting at the
given value of length equal to or greater than the given length.
|
static void |
fastCopy(ReadableByteChannel src,
WritableByteChannel dest)
An efficient copy between two channels with a fixed-size buffer.
|
static ByteBuffer |
generateNewByteBufferFromThriftRPCResults(ByteBuffer data)
Extracts a correct ByteBuffer from Thrift RPC result.
|
static byte[] |
getIncreasingByteArray(int len)
Gets an increasing sequence of bytes starting at zero.
|
static byte[] |
getIncreasingByteArray(int start,
int len)
Gets an increasing sequence of bytes starting with the given value.
|
static ByteBuffer |
getIncreasingByteBuffer(int len)
Gets a ByteBuffer containing an increasing sequence of bytes starting at zero.
|
static ByteBuffer |
getIncreasingByteBuffer(int start,
int len)
Gets a ByteBuffer containing an increasing sequence of bytes starting at the given value.
|
static ByteBuffer |
getIncreasingIntBuffer(int len)
Gets a ByteBuffer containing an increasing sequence of integers starting at zero.
|
static ByteBuffer |
getIncreasingIntBuffer(int start,
int len)
Get a ByteBuffer containing an increasing sequence of integers starting at the given value.
|
static void |
putIntByteBuffer(ByteBuffer buf,
int b)
Puts a byte (the first byte of an integer) into a ByteBuffer.
|
static void |
writeBufferToFile(String path,
byte[] buffer)
Writes buffer to the given file path.
|
public static int byteToInt(byte b)
public static void cleanDirectBuffer(ByteBuffer buffer)
NOTE: DirectByteBuffers are not guaranteed to be garbage-collected immediately after their references are released and may lead to OutOfMemoryError. This function helps by calling the Cleaner method of a DirectByteBuffer explicitly. See more discussion.
buffer - the byte buffer to be unmapped, this must be a direct bufferpublic static ByteBuffer cloneByteBuffer(ByteBuffer buf)
The new bytebuffer will have the same content, but the type of the bytebuffer may not be the same.
buf - The ByteBuffer to clonepublic static List<ByteBuffer> cloneByteBufferList(List<ByteBuffer> source)
source - the list of ByteBuffers to clonepublic static ByteBuffer generateNewByteBufferFromThriftRPCResults(ByteBuffer data)
data - result of Thrift RPCpublic static void putIntByteBuffer(ByteBuffer buf, int b)
buf - ByteBuffer to useb - byte to put into the ByteBufferpublic static byte[] getIncreasingByteArray(int len)
len - the target length of the sequencepublic static byte[] getIncreasingByteArray(int start,
int len)
start - the starting value to uselen - the target length of the sequencepublic static boolean equalIncreasingByteArray(int len,
byte[] arr)
len - the target length of the sequencearr - the byte array to checklen that is an increasing
sequence of bytes starting at zeropublic static boolean equalIncreasingByteArray(int start,
int len,
byte[] arr)
start - the starting value to uselen - the target length of the sequencearr - the byte array to checklen that is an increasing
sequence of bytes starting at startpublic static ByteBuffer getIncreasingByteBuffer(int len)
len - the target length of the sequencepublic static ByteBuffer getIncreasingByteBuffer(int start, int len)
len - the target length of the sequencestart - the starting value to usepublic static boolean equalIncreasingByteBuffer(int start,
int len,
ByteBuffer buf)
start - the starting value to uselen - the target length of the sequencebuf - the ByteBuffer to checklen that is an increasing
sequence of bytes starting at startpublic static ByteBuffer getIncreasingIntBuffer(int len)
len - the target length of the sequencepublic static ByteBuffer getIncreasingIntBuffer(int start, int len)
start - the starting value to uselen - the target length of the sequencepublic static void writeBufferToFile(String path, byte[] buffer) throws IOException
path - file path to write the databuffer - raw dataIOException - if the operation failspublic static void fastCopy(ReadableByteChannel src, WritableByteChannel dest) throws IOException
src - the source channeldest - the destination channelIOException - if the copy failsCopyright © 2015. All Rights Reserved.