public class ByteArrayUtils extends Object
Additionally, this class has methods for manipulating byte arrays, such as combining or incrementing them.
Constructor and Description |
---|
ByteArrayUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
addAllIntermediaryByteArrays(List<byte[]> retVal,
ByteArrayRange range) |
static byte[] |
byteArrayFromString(String str)
Convert a string representation of binary data back to a String
|
static long |
byteArrayToLong(byte[] bytes)
Converts a byte array to a long
|
static short |
byteArrayToShort(byte[] bytes) |
static String |
byteArrayToString(byte[] byteArray)
Convert binary data to a string for transport
|
static byte[] |
combineArrays(byte[] id1,
byte[] id2)
Combine 2 arrays into one large array.
|
static byte[] |
combineVariableLengthArrays(byte[] array1,
byte[] array2)
Combines two variable length byte arrays into one large byte array and appends the length of
each individual byte array in sequential order at the end of the combined byte array.
|
static int |
compare(byte[] array1,
byte[] array2) |
static String |
getHexString(byte[] bytes) |
static byte[] |
getNextPrefix(byte[] rowKeyPrefix) |
static byte[] |
getPreviousPrefix(byte[] rowKeyPrefix) |
static ByteArrayRange |
getSingleRange(List<ByteArrayRange> ranges) |
static boolean |
increment(byte[] value)
add 1 to the least significant bit in this byte array (the last byte in the array)
|
static byte[] |
longToByteArray(long l)
Converts a long to a byte array
|
static byte[] |
safeRead(ByteBuffer buffer,
int length)
Read bytes from the buffer, but only if the buffer's remaining length supports it.
|
static short |
shortFromString(String input) |
static byte[] |
shortToByteArray(short input) |
static String |
shortToString(short input) |
static org.apache.commons.lang3.tuple.Pair<byte[],byte[]> |
splitVariableLengthArrays(byte[] combinedArray) |
static boolean |
startsWith(byte[] bytes,
byte[] prefix) |
static byte[] |
uuidToByteArray(UUID uuid)
Converts a UUID to a byte array
|
static long |
variableLengthDecode(byte[] b) |
static byte[] |
variableLengthEncode(long n) |
static void |
verifyBufferSize(ByteBuffer buffer,
int length)
Throw an exception if the requested length is longer than the remaining buffer size.
|
public static String byteArrayToString(byte[] byteArray)
byteArray
- the binary datapublic static byte[] byteArrayFromString(String str)
str
- the string representation of binary datapublic static void verifyBufferSize(ByteBuffer buffer, int length)
buffer
- the byte bufferlength
- the number of bytes to readpublic static byte[] safeRead(ByteBuffer buffer, int length)
buffer
- the byte bufferlength
- the number of bytes to readpublic static byte[] combineArrays(byte[] id1, byte[] id2)
id1
- the first byte array to use (the start of the result)id2
- the second byte array to combine (appended to id1)public static boolean increment(byte[] value)
value
- the array to incrementpublic static byte[] uuidToByteArray(UUID uuid)
uuid
- the uuidpublic static byte[] longToByteArray(long l)
l
- the longpublic static long byteArrayToLong(byte[] bytes)
bytes
- the byte array the longpublic static byte[] combineVariableLengthArrays(byte[] array1, byte[] array2)
Given byte_array_1 of length 8 + byte_array_2 of length 16, the result will be byte_array1 + byte_array_2 + 8 + 16.
Lengths are put after the individual arrays so they don't impact sorting when used within the key of a sorted key-value data store.
array1
- the first byte arrayarray2
- the second byte arraypublic static org.apache.commons.lang3.tuple.Pair<byte[],byte[]> splitVariableLengthArrays(byte[] combinedArray)
public static String shortToString(short input)
public static short shortFromString(String input)
public static byte[] shortToByteArray(short input)
public static short byteArrayToShort(byte[] bytes)
public static byte[] variableLengthEncode(long n)
public static long variableLengthDecode(byte[] b)
public static byte[] getNextPrefix(byte[] rowKeyPrefix)
public static byte[] getPreviousPrefix(byte[] rowKeyPrefix)
public static int compare(byte[] array1, byte[] array2)
public static boolean startsWith(byte[] bytes, byte[] prefix)
public static String getHexString(byte[] bytes)
public static ByteArrayRange getSingleRange(List<ByteArrayRange> ranges)
public static void addAllIntermediaryByteArrays(List<byte[]> retVal, ByteArrayRange range)
Copyright © 2013–2020. All rights reserved.