public class ByteBufferUtil
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.nio.ByteBuffer |
EMPTY_BYTE_BUFFER |
Constructor and Description |
---|
ByteBufferUtil() |
Modifier and Type | Method and Description |
---|---|
static void |
arrayCopy(java.nio.ByteBuffer src,
int srcPos,
byte[] dst,
int dstPos,
int length) |
static void |
arrayCopy(java.nio.ByteBuffer src,
int srcPos,
java.nio.ByteBuffer dst,
int dstPos,
int length)
Transfer bytes from one ByteBuffer to another.
|
static java.nio.ByteBuffer |
bytes(double d) |
static java.nio.ByteBuffer |
bytes(float f) |
static java.nio.ByteBuffer |
bytes(java.net.InetAddress address) |
static java.nio.ByteBuffer |
bytes(int i) |
static java.nio.ByteBuffer |
bytes(long n) |
static java.nio.ByteBuffer |
bytes(java.lang.String s)
Encode a String in a ByteBuffer using UTF_8.
|
static java.nio.ByteBuffer |
bytes(java.lang.String s,
java.nio.charset.Charset charset)
Encode a String in a ByteBuffer using the provided charset.
|
static java.nio.ByteBuffer |
bytes(java.util.UUID uuid) |
static java.lang.String |
bytesToHex(java.nio.ByteBuffer bytes) |
static java.nio.ByteBuffer |
clone(java.nio.ByteBuffer buffer) |
static int |
compare(byte[] o1,
java.nio.ByteBuffer o2) |
static int |
compare(java.nio.ByteBuffer o1,
byte[] o2) |
static int |
compareSubArrays(java.nio.ByteBuffer bytes1,
int offset1,
java.nio.ByteBuffer bytes2,
int offset2,
int length)
Compare two ByteBuffer at specified offsets for length.
|
static int |
compareUnsigned(java.nio.ByteBuffer o1,
java.nio.ByteBuffer o2) |
static byte[] |
getArray(java.nio.ByteBuffer buffer)
You should almost never use this.
|
static int |
getShortLength(java.nio.ByteBuffer bb,
int position) |
static java.nio.ByteBuffer |
hexToBytes(java.lang.String str) |
static java.io.InputStream |
inputStream(java.nio.ByteBuffer bytes) |
static boolean |
isPrefix(java.nio.ByteBuffer prefix,
java.nio.ByteBuffer value) |
static int |
lastIndexOf(java.nio.ByteBuffer buffer,
byte valueToFind,
int startIndex)
ByteBuffer adaptation of org.apache.commons.lang3.ArrayUtils.lastIndexOf method
|
static java.nio.ByteBuffer |
minimalBufferFor(java.nio.ByteBuffer buf)
trims size of bytebuffer to exactly number of bytes in it, to do not hold too much memory
|
static java.nio.ByteBuffer |
read(java.io.DataInput in,
int length) |
static java.nio.ByteBuffer |
readBytes(java.nio.ByteBuffer bb,
int length) |
static byte[] |
readBytes(java.io.DataInput in,
int length) |
static java.nio.ByteBuffer |
readBytesWithShortLength(java.nio.ByteBuffer bb) |
static int |
readShortLength(java.nio.ByteBuffer bb) |
static int |
readShortLength(java.io.DataInput in) |
static java.nio.ByteBuffer |
readWithLength(java.io.DataInput in) |
static java.nio.ByteBuffer |
readWithShortLength(java.io.DataInput in) |
static java.nio.ByteBuffer |
skipShortLength(java.io.DataInput in) |
static java.lang.String |
string(java.nio.ByteBuffer buffer)
Decode a String representation.
|
static java.lang.String |
string(java.nio.ByteBuffer buffer,
java.nio.charset.Charset charset)
Decode a String representation.
|
static java.lang.String |
string(java.nio.ByteBuffer buffer,
int position,
int length)
Decode a String representation.
|
static java.lang.String |
string(java.nio.ByteBuffer buffer,
int position,
int length,
java.nio.charset.Charset charset)
Decode a String representation.
|
static double |
toDouble(java.nio.ByteBuffer bytes) |
static float |
toFloat(java.nio.ByteBuffer bytes) |
static int |
toInt(java.nio.ByteBuffer bytes)
Convert a byte buffer to an integer.
|
static long |
toLong(java.nio.ByteBuffer bytes) |
static void |
writeShortLength(java.nio.ByteBuffer bb,
int length) |
static void |
writeWithLength(byte[] bytes,
java.io.DataOutput out) |
static void |
writeWithLength(java.nio.ByteBuffer bytes,
DataOutputPlus out) |
static void |
writeWithShortLength(byte[] buffer,
java.io.DataOutput out) |
static void |
writeWithShortLength(java.nio.ByteBuffer buffer,
DataOutputPlus out) |
@Inline public static int compareUnsigned(java.nio.ByteBuffer o1, java.nio.ByteBuffer o2)
@Inline public static int compare(byte[] o1, java.nio.ByteBuffer o2)
@Inline public static int compare(java.nio.ByteBuffer o1, byte[] o2)
public static java.lang.String string(java.nio.ByteBuffer buffer) throws java.nio.charset.CharacterCodingException
buffer
- a byte buffer holding the string representationjava.nio.charset.CharacterCodingException
public static java.lang.String string(java.nio.ByteBuffer buffer, int position, int length) throws java.nio.charset.CharacterCodingException
buffer
- a byte buffer holding the string representationposition
- the starting position in buffer
to start decoding fromlength
- the number of bytes from buffer
to usejava.nio.charset.CharacterCodingException
public static java.lang.String string(java.nio.ByteBuffer buffer, int position, int length, java.nio.charset.Charset charset) throws java.nio.charset.CharacterCodingException
buffer
- a byte buffer holding the string representationposition
- the starting position in buffer
to start decoding fromlength
- the number of bytes from buffer
to usecharset
- the String encoding charsetjava.nio.charset.CharacterCodingException
public static java.lang.String string(java.nio.ByteBuffer buffer, java.nio.charset.Charset charset) throws java.nio.charset.CharacterCodingException
buffer
- a byte buffer holding the string representationcharset
- the String encoding charsetjava.nio.charset.CharacterCodingException
public static byte[] getArray(java.nio.ByteBuffer buffer)
public static int lastIndexOf(java.nio.ByteBuffer buffer, byte valueToFind, int startIndex)
buffer
- the array to traverse for looking for the object, may be null
valueToFind
- the value to findstartIndex
- the start index (i.e. BB position) to travers backwards from-1
if not found.public static java.nio.ByteBuffer bytes(java.lang.String s)
s
- the string to encodepublic static java.nio.ByteBuffer bytes(java.lang.String s, java.nio.charset.Charset charset)
s
- the string to encodecharset
- the String encoding charset to usepublic static java.nio.ByteBuffer clone(java.nio.ByteBuffer buffer)
public static void arrayCopy(java.nio.ByteBuffer src, int srcPos, byte[] dst, int dstPos, int length)
public static void arrayCopy(java.nio.ByteBuffer src, int srcPos, java.nio.ByteBuffer dst, int dstPos, int length)
src
- the source ByteBuffersrcPos
- starting position in the source ByteBufferdst
- the destination ByteBufferdstPos
- starting position in the destination ByteBufferlength
- the number of bytes to copypublic static void writeWithLength(java.nio.ByteBuffer bytes, DataOutputPlus out) throws java.io.IOException
java.io.IOException
public static void writeWithLength(byte[] bytes, java.io.DataOutput out) throws java.io.IOException
java.io.IOException
public static void writeWithShortLength(java.nio.ByteBuffer buffer, DataOutputPlus out) throws java.io.IOException
java.io.IOException
public static void writeWithShortLength(byte[] buffer, java.io.DataOutput out) throws java.io.IOException
java.io.IOException
public static java.nio.ByteBuffer readWithLength(java.io.DataInput in) throws java.io.IOException
java.io.IOException
public static int readShortLength(java.io.DataInput in) throws java.io.IOException
java.io.IOException
public static java.nio.ByteBuffer readWithShortLength(java.io.DataInput in) throws java.io.IOException
in
- data inputjava.io.IOException
- if an I/O error occurs.public static java.nio.ByteBuffer skipShortLength(java.io.DataInput in) throws java.io.IOException
in
- data inputjava.io.IOException
- if an I/O error occurs.public static java.nio.ByteBuffer read(java.io.DataInput in, int length) throws java.io.IOException
java.io.IOException
public static byte[] readBytes(java.io.DataInput in, int length) throws java.io.IOException
java.io.IOException
public static int toInt(java.nio.ByteBuffer bytes)
bytes
- byte buffer to convert to integerpublic static long toLong(java.nio.ByteBuffer bytes)
public static float toFloat(java.nio.ByteBuffer bytes)
public static double toDouble(java.nio.ByteBuffer bytes)
public static java.nio.ByteBuffer bytes(int i)
public static java.nio.ByteBuffer bytes(long n)
public static java.nio.ByteBuffer bytes(float f)
public static java.nio.ByteBuffer bytes(double d)
public static java.io.InputStream inputStream(java.nio.ByteBuffer bytes)
public static java.lang.String bytesToHex(java.nio.ByteBuffer bytes)
public static java.nio.ByteBuffer hexToBytes(java.lang.String str)
public static int compareSubArrays(java.nio.ByteBuffer bytes1, int offset1, java.nio.ByteBuffer bytes2, int offset2, int length)
bytes1
- First byte buffer to compare.offset1
- Position to start the comparison at in the first array.bytes2
- Second byte buffer to compare.offset2
- Position to start the comparison at in the second array.length
- How many bytes to compare?public static java.nio.ByteBuffer bytes(java.net.InetAddress address)
public static java.nio.ByteBuffer bytes(java.util.UUID uuid)
public static boolean isPrefix(java.nio.ByteBuffer prefix, java.nio.ByteBuffer value)
public static java.nio.ByteBuffer minimalBufferFor(java.nio.ByteBuffer buf)
public static int getShortLength(java.nio.ByteBuffer bb, int position)
public static int readShortLength(java.nio.ByteBuffer bb)
public static void writeShortLength(java.nio.ByteBuffer bb, int length)
public static java.nio.ByteBuffer readBytes(java.nio.ByteBuffer bb, int length)
public static java.nio.ByteBuffer readBytesWithShortLength(java.nio.ByteBuffer bb)
Copyright © 2017 The Apache Software Foundation