public class Bytes
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static class |
Bytes.ByteArrayComparator
Byte array comparator class.
|
static class |
Bytes.RowEndKeyComparator
A
Bytes.ByteArrayComparator that treats the empty array as the largest value. |
| Modifier and Type | Field and Description |
|---|---|
static java.util.Comparator<byte[]> |
BYTES_COMPARATOR
Pass this to TreeMaps where byte [] are keys.
|
static byte[] |
EMPTY_BYTE_ARRAY |
static int |
ESTIMATED_HEAP_TAX
Estimate of size cost to pay beyond payload in jvm for instance of byte [].
|
static int |
SIZEOF_BOOLEAN
Size of boolean in bytes
|
static int |
SIZEOF_BYTE
Size of byte in bytes
|
static int |
SIZEOF_CHAR
Size of char in bytes
|
static int |
SIZEOF_DOUBLE
Size of double in bytes
|
static int |
SIZEOF_FLOAT
Size of float in bytes
|
static int |
SIZEOF_INT
Size of int in bytes
|
static int |
SIZEOF_LONG
Size of long in bytes
|
static int |
SIZEOF_SHORT
Size of short in bytes
|
| Constructor and Description |
|---|
Bytes() |
| Modifier and Type | Method and Description |
|---|---|
static byte[] |
add(byte[] a,
byte[] b) |
static byte[] |
add(byte[] a,
byte[] b,
byte[] c) |
static byte[] |
appendZeroByte(byte[] input)
Treat the byte[] as an unsigned series of bytes, most significant bits first.
|
static int |
compareTo(byte[] left,
byte[] right) |
static int |
compareTo(byte[] buffer1,
int offset1,
int length1,
byte[] buffer2,
int offset2,
int length2)
Lexicographically compare two arrays.
|
static byte[] |
concatenate(byte[] a,
byte[] b) |
static boolean |
contains(byte[] array,
byte target) |
static boolean |
contains(byte[] array,
byte[] target) |
static byte[] |
copy(byte[] bytes)
Copy the byte array given in parameter and return an instance
of a new byte array with the same length and the same content.
|
static byte[] |
copy(byte[] bytes,
int offset,
int length)
Copy the byte array given in parameter and return an instance
of a new byte array with the same length and the same content.
|
static java.nio.ByteBuffer |
copyToByteBuffer(java.nio.ByteBuffer bb)
Copies a direct bytebuffer to a non-direct byte buffer.
|
static java.nio.ByteBuffer |
copyToDirectByteBuffer(java.nio.ByteBuffer bb)
Copies a non-direct bytebuffer to a direct byte buffer.
|
static byte[] |
createMaxByteArray(int maxByteCount)
Create a max byte array with the specified max byte count
|
static byte[] |
createStopKeyForPrefix(byte[] prefix)
Returns the Stop Key for the given physical row key prefix
|
static boolean |
equals(byte[] left,
byte[] right) |
static boolean |
equals(byte[] a,
java.nio.ByteBuffer buf) |
static boolean |
equals(byte[] left,
int leftOffset,
int leftLen,
byte[] right,
int rightOffset,
int rightLen) |
static boolean |
equals(java.util.List<byte[]> a,
java.util.List<byte[]> b) |
static byte[] |
fromHex(java.lang.String hex)
Create a byte array from a string of hash digits.
|
static byte[] |
getBytes(java.nio.ByteBuffer buf)
Returns a new byte array, copied from the given
buf,
from the position (inclusive) to the limit (exclusive). |
static int |
hashCode(byte[] b) |
static int |
hashCode(byte[] bytes,
int offset,
int length) |
static byte[] |
head(byte[] a,
int length) |
static int |
indexOf(byte[] array,
byte target)
Returns the index of the first appearance of the value
target in
array. |
static int |
indexOf(byte[] array,
byte[] target)
Returns the start position of the first occurrence of the specified
target within array, or -1 if there is no such occurrence. |
static int |
len(byte[] b)
Returns length of the byte array, returning 0 if the array is null.
|
static byte[] |
maxOfStartRows(byte[] left,
byte[] right) |
static byte[] |
maxOfStopRows(byte[] left,
byte[] right) |
static byte[] |
minOfStartRows(byte[] left,
byte[] right) |
static byte[] |
minOfStopRows(byte[] left,
byte[] right) |
static byte[] |
multiple(byte[] srcBytes,
int multiNum)
Create a byte array which is multiple given bytes
|
static byte[] |
padHead(byte[] a,
int length) |
static byte[] |
padTail(byte[] a,
int length) |
static int |
putAsShort(byte[] bytes,
int offset,
int val)
Put an int value as short out to the specified byte array position.
|
static int |
putBigDecimal(byte[] bytes,
int offset,
java.math.BigDecimal val)
Put a BigDecimal value out to the specified byte array position.
|
static int |
putByte(byte[] bytes,
int offset,
byte b)
Write a single byte out to the specified byte array position.
|
static int |
putByteBuffer(byte[] bytes,
int offset,
java.nio.ByteBuffer buf)
Add the whole content of the ByteBuffer to the bytes arrays.
|
static int |
putBytes(byte[] tgtBytes,
int tgtOffset,
byte[] srcBytes,
int srcOffset,
int srcLength)
Put bytes at the specified byte array position.
|
static int |
putDouble(byte[] bytes,
int offset,
double d) |
static int |
putFloat(byte[] bytes,
int offset,
float f) |
static int |
putInt(byte[] bytes,
int offset,
int val)
Put an int value out to the specified byte array position.
|
static int |
putIntUnsafe(byte[] bytes,
int offset,
int val)
Put an int value out to the specified byte array position (Unsafe).
|
static int |
putLong(byte[] bytes,
int offset,
long val)
Put a long value out to the specified byte array position.
|
static int |
putLongUnsafe(byte[] bytes,
int offset,
long val)
Put a long value out to the specified byte array position (Unsafe).
|
static int |
putShort(byte[] bytes,
int offset,
short val)
Put a short value out to the specified byte array position.
|
static int |
putShortUnsafe(byte[] bytes,
int offset,
short val)
Put a short value out to the specified byte array position (Unsafe).
|
static void |
random(byte[] b)
Fill given array with random bytes.
|
static void |
random(byte[] b,
int offset,
int length)
Fill given array with random bytes at the specified position.
|
static int |
readAsInt(byte[] bytes,
int offset,
int length)
Converts a byte array to an int value
|
static boolean |
startsWith(byte[] bytes,
byte[] prefix)
Return true if the byte array on the right is a prefix of the byte
array on the left.
|
static byte[] |
tail(byte[] a,
int length) |
static java.lang.String |
toBase64(byte[] b)
Encodes the specified byte array to a base-64 String.
|
static java.math.BigDecimal |
toBigDecimal(byte[] bytes)
Converts a byte array to a BigDecimal
|
static java.math.BigDecimal |
toBigDecimal(byte[] bytes,
int offset,
int length)
Converts a byte array to a BigDecimal value
|
static byte |
toBinaryFromHex(byte ch)
Takes a ASCII digit in the range A-F0-9 and returns
the corresponding integer/ordinal value.
|
static boolean |
toBoolean(byte[] b)
Reverses
toBytes(boolean) |
static byte[][] |
toByteArrays(byte[] column) |
static byte[][] |
toByteArrays(java.lang.String column) |
static byte[][] |
toByteArrays(java.lang.String[] t) |
static java.nio.ByteBuffer |
toByteBuffer(java.lang.String s)
Converts a string to a UTF-8 ByteBuffer.
|
static byte[] |
toBytes(java.math.BigDecimal val)
Convert a BigDecimal value to a byte array
|
static byte[] |
toBytes(boolean b)
Convert a boolean to a byte array.
|
static byte[] |
toBytes(java.nio.ByteBuffer buf)
Returns a new byte array, copied from the given
buf,
from the index 0 (inclusive) to the limit (exclusive),
regardless of the current position. |
static byte[] |
toBytes(double d)
Serialize a double as the IEEE 754 double format output.
|
static byte[] |
toBytes(float f) |
static byte[] |
toBytes(int val)
Convert an int value to a byte array.
|
static byte[] |
toBytes(long val)
Convert a long value to a byte array using big-endian.
|
static byte[] |
toBytes(short val)
Convert a short value to a byte array of
SIZEOF_SHORT bytes long. |
static byte[] |
toBytes(java.lang.String s)
Converts a string to a UTF-8 byte array.
|
static byte[] |
toBytesBinary(java.lang.String in) |
static java.nio.ByteBuffer |
toDirectByteBuffer(java.lang.String s)
Converts a string to a UTF-8 DirectByteBuffer.
|
static double |
toDouble(byte[] bytes) |
static double |
toDouble(byte[] bytes,
int offset) |
static float |
toFloat(byte[] bytes)
Presumes float encoded as IEEE 754 floating-point "single format"
|
static float |
toFloat(byte[] bytes,
int offset)
Presumes float encoded as IEEE 754 floating-point "single format"
|
static java.lang.String |
toHex(byte[] b)
Convert a byte array into a hex string
|
static int |
toInt(byte[] bytes)
Converts a byte array to an int value
|
static int |
toInt(byte[] bytes,
int offset)
Converts a byte array to an int value
|
static int |
toInt(byte[] bytes,
int offset,
int length)
Converts a byte array to an int value
|
static int |
toIntUnsafe(byte[] bytes,
int offset)
Converts a byte array to an int value (Unsafe version)
|
static long |
toLong(byte[] bytes)
Converts a byte array to a long value.
|
static long |
toLong(byte[] bytes,
int offset)
Converts a byte array to a long value.
|
static long |
toLong(byte[] bytes,
int offset,
int length)
Converts a byte array to a long value.
|
static long |
toLongUnsafe(byte[] bytes,
int offset)
Converts a byte array to an long value (Unsafe version)
|
static short |
toShort(byte[] bytes)
Converts a byte array to a short value
|
static short |
toShort(byte[] bytes,
int offset)
Converts a byte array to a short value
|
static short |
toShort(byte[] bytes,
int offset,
int length)
Converts a byte array to a short value
|
static short |
toShortUnsafe(byte[] bytes,
int offset)
Converts a byte array to an short value (Unsafe version)
|
static java.lang.String |
toString(byte[] b) |
static java.lang.String |
toString(byte[] b,
int off,
int len)
This method will convert utf8 encoded bytes into a string.
|
static java.lang.String |
toString(byte[] b1,
java.lang.String sep,
byte[] b2)
Joins two byte arrays together using a separator.
|
static java.lang.String |
toString(java.nio.ByteBuffer b) |
static java.lang.String |
toString(java.nio.ByteBuffer b,
int len) |
static java.lang.String |
toString(java.nio.ByteBuffer b,
int offset,
int len) |
static java.lang.String |
toStringBinary(byte[] b)
Write a printable representation of a byte array.
|
static java.lang.String |
toStringBinary(byte[] b,
int off,
int len)
Write a printable representation of a byte array.
|
static java.lang.String |
toStringBinary(java.nio.ByteBuffer buf)
Converts the given byte buffer to a printable representation,
from the index 0 (inclusive) to the limit (exclusive),
regardless of the current position.
|
static int |
unsignedBinarySearch(byte[] a,
int fromIndex,
int toIndex,
byte key)
Search sorted array "a" for byte "key".
|
static byte[] |
unsignedCopyAndIncrement(byte[] input)
Treat the byte[] as an unsigned series of bytes, most significant bits first.
|
static void |
zero(byte[] b)
Fill given array with zeros.
|
static void |
zero(byte[] b,
int offset,
int length)
Fill given array with zeros at the specified position.
|
public static final byte[] EMPTY_BYTE_ARRAY
public static final int SIZEOF_BOOLEAN
public static final int SIZEOF_BYTE
public static final int SIZEOF_CHAR
public static final int SIZEOF_DOUBLE
public static final int SIZEOF_FLOAT
public static final int SIZEOF_INT
public static final int SIZEOF_LONG
public static final int SIZEOF_SHORT
public static final int ESTIMATED_HEAP_TAX
public static final java.util.Comparator<byte[]> BYTES_COMPARATOR
public static final int len(byte[] b)
b - byte array, which can be nullpublic static int putBytes(byte[] tgtBytes,
int tgtOffset,
byte[] srcBytes,
int srcOffset,
int srcLength)
tgtBytes - the byte arraytgtOffset - position in the arraysrcBytes - array to write outsrcOffset - source offsetsrcLength - source lengthpublic static int putByte(byte[] bytes,
int offset,
byte b)
bytes - the byte arrayoffset - position in the arrayb - byte to write outpublic static int putByteBuffer(byte[] bytes,
int offset,
java.nio.ByteBuffer buf)
bytes - the byte arrayoffset - position in the arraybuf - ByteBuffer to write outpublic static byte[] toBytes(java.nio.ByteBuffer buf)
buf,
from the index 0 (inclusive) to the limit (exclusive),
regardless of the current position.
The position and the other index parameters are not changed.buf - a byte buffergetBytes(ByteBuffer)public static java.lang.String toString(java.nio.ByteBuffer b)
public static java.lang.String toString(java.nio.ByteBuffer b,
int len)
public static java.lang.String toString(java.nio.ByteBuffer b,
int offset,
int len)
public static java.lang.String toString(byte[] b)
b - Presumed UTF-8 encoded byte array.bpublic static java.lang.String toString(byte[] b1,
java.lang.String sep,
byte[] b2)
b1 - The first byte array.sep - The separator to use.b2 - The second byte array.public static java.lang.String toString(byte[] b,
int off,
int len)
b - Presumed UTF-8 encoded byte array.off - offset into arraylen - length of utf-8 sequenceb or nullpublic static java.lang.String toBase64(byte[] b)
b - byte arraypublic static java.lang.String toStringBinary(byte[] b)
b - byte arraytoStringBinary(byte[], int, int)public static java.lang.String toStringBinary(java.nio.ByteBuffer buf)
buf - a byte buffertoBytes(ByteBuffer),
getBytes(ByteBuffer)public static java.lang.String toStringBinary(byte[] b,
int off,
int len)
b - array to write outoff - offset to start atlen - length to writepublic static byte toBinaryFromHex(byte ch)
ch - The hex digit.public static byte[] toBytesBinary(java.lang.String in)
public static java.nio.ByteBuffer toDirectByteBuffer(java.lang.String s)
s - stringpublic static java.nio.ByteBuffer copyToByteBuffer(java.nio.ByteBuffer bb)
bb - input byte buffer, needs to be non-directpublic static java.nio.ByteBuffer copyToDirectByteBuffer(java.nio.ByteBuffer bb)
bb - input byte buffer, needs to be non-directpublic static java.nio.ByteBuffer toByteBuffer(java.lang.String s)
s - stringpublic static byte[] toBytes(java.lang.String s)
s - stringpublic static byte[] toBytes(boolean b)
b - valueb encoded in a byte array.public static boolean toBoolean(byte[] b)
toBytes(boolean)b - arraypublic static byte[] toBytes(long val)
val - value to convertpublic static long toLong(byte[] bytes)
toBytes(long)bytes - arraypublic static long toLong(byte[] bytes,
int offset)
SIZEOF_LONG bytes available.bytes - bytesoffset - offsetpublic static long toLong(byte[] bytes,
int offset,
int length)
bytes - array of bytesoffset - offset into arraylength - length of data (must be SIZEOF_LONG)java.lang.IllegalArgumentException - if length is not SIZEOF_LONG or
if there's not enough room in the array at the offset indicated.public static int putLong(byte[] bytes,
int offset,
long val)
bytes - the byte arrayoffset - position in the arrayval - long to write outjava.lang.IllegalArgumentException - if the byte array given doesn't have
enough room at the offset specified.public static int putLongUnsafe(byte[] bytes,
int offset,
long val)
bytes - the byte arrayoffset - position in the arrayval - long to write outpublic static float toFloat(byte[] bytes)
bytes - byte arraypublic static float toFloat(byte[] bytes,
int offset)
bytes - array to convertoffset - offset into arraypublic static int putFloat(byte[] bytes,
int offset,
float f)
bytes - byte arrayoffset - offset to write tof - float valuebytespublic static byte[] toBytes(float f)
f - float valuepublic static double toDouble(byte[] bytes)
bytes - byte arraypublic static double toDouble(byte[] bytes,
int offset)
bytes - byte arrayoffset - offset where double ispublic static int putDouble(byte[] bytes,
int offset,
double d)
bytes - byte arrayoffset - offset to write tod - valuebytespublic static byte[] toBytes(double d)
d - valuepublic static byte[] toBytes(int val)
val - valuepublic static int toInt(byte[] bytes)
bytes - byte arraypublic static int toInt(byte[] bytes,
int offset)
bytes - byte arrayoffset - offset into arraypublic static int toInt(byte[] bytes,
int offset,
int length)
bytes - byte arrayoffset - offset into arraylength - length of int (has to be SIZEOF_INT)java.lang.IllegalArgumentException - if length is not SIZEOF_INT or
if there's not enough room in the array at the offset indicated.public static int toIntUnsafe(byte[] bytes,
int offset)
bytes - byte arrayoffset - offset into arraypublic static short toShortUnsafe(byte[] bytes,
int offset)
bytes - byte arrayoffset - offset into arraypublic static long toLongUnsafe(byte[] bytes,
int offset)
bytes - byte arrayoffset - offset into arraypublic static int readAsInt(byte[] bytes,
int offset,
int length)
bytes - byte arrayoffset - offset into arraylength - how many bytes should be considered for creating intjava.lang.IllegalArgumentException - if there's not enough room in the array at the offset
indicated.public static int putInt(byte[] bytes,
int offset,
int val)
bytes - the byte arrayoffset - position in the arrayval - int to write outjava.lang.IllegalArgumentException - if the byte array given doesn't have
enough room at the offset specified.public static int putIntUnsafe(byte[] bytes,
int offset,
int val)
bytes - the byte arrayoffset - position in the arrayval - int to write outpublic static byte[] toBytes(short val)
SIZEOF_SHORT bytes long.val - valuepublic static short toShort(byte[] bytes)
bytes - byte arraypublic static short toShort(byte[] bytes,
int offset)
bytes - byte arrayoffset - offset into arraypublic static short toShort(byte[] bytes,
int offset,
int length)
bytes - byte arrayoffset - offset into arraylength - length, has to be SIZEOF_SHORTjava.lang.IllegalArgumentException - if length is not SIZEOF_SHORT
or if there's not enough room in the array at the offset indicated.public static byte[] getBytes(java.nio.ByteBuffer buf)
buf,
from the position (inclusive) to the limit (exclusive).
The position and the other index parameters are not changed.buf - a byte buffertoBytes(ByteBuffer)public static int putShort(byte[] bytes,
int offset,
short val)
bytes - the byte arrayoffset - position in the arrayval - short to write outjava.lang.IllegalArgumentException - if the byte array given doesn't have
enough room at the offset specified.public static int putShortUnsafe(byte[] bytes,
int offset,
short val)
bytes - the byte arrayoffset - position in the arrayval - short to write outpublic static int putAsShort(byte[] bytes,
int offset,
int val)
bytes - the byte arrayoffset - position in the arrayval - value to write outjava.lang.IllegalArgumentException - if the byte array given doesn't have
enough room at the offset specified.public static byte[] toBytes(java.math.BigDecimal val)
val - public static java.math.BigDecimal toBigDecimal(byte[] bytes)
bytes - public static java.math.BigDecimal toBigDecimal(byte[] bytes,
int offset,
int length)
bytes - offset - length - public static int putBigDecimal(byte[] bytes,
int offset,
java.math.BigDecimal val)
bytes - the byte arrayoffset - position in the arrayval - BigDecimal to write outpublic static int compareTo(byte[] left,
byte[] right)
left - left operandright - right operandpublic static int compareTo(byte[] buffer1,
int offset1,
int length1,
byte[] buffer2,
int offset2,
int length2)
buffer1 - left operandbuffer2 - right operandoffset1 - Where to start comparing in the left bufferoffset2 - Where to start comparing in the right bufferlength1 - How much to compare from the left bufferlength2 - How much to compare from the right bufferpublic static boolean equals(byte[] left,
byte[] right)
left - left operandright - right operandpublic static boolean equals(byte[] left,
int leftOffset,
int leftLen,
byte[] right,
int rightOffset,
int rightLen)
public static boolean equals(byte[] a,
java.nio.ByteBuffer buf)
a - left operandbuf - right operandpublic static boolean startsWith(byte[] bytes,
byte[] prefix)
public static int hashCode(byte[] b)
b - bytes to hashArrays#hashCode(byte[], int) on the
passed in array. This method is what org.apache.hadoop.io.Text and
ImmutableBytesWritable use calculating hash code.public static byte[] add(byte[] a,
byte[] b)
a - lower halfb - upper halfpublic static byte[] add(byte[] a,
byte[] b,
byte[] c)
a - first thirdb - second thirdc - third thirdpublic static byte[] head(byte[] a,
int length)
a - arraylength - amount of bytes to grablength bytes from apublic static byte[] tail(byte[] a,
int length)
a - arraylength - amount of bytes to snarflength bytes from apublic static byte[] padHead(byte[] a,
int length)
a - arraylength - new array sizea plus length prepended 0 bytespublic static byte[] padTail(byte[] a,
int length)
a - arraylength - new array sizea plus length appended 0 bytespublic static int hashCode(byte[] bytes,
int offset,
int length)
bytes - array to hashoffset - offset to start fromlength - length to hashpublic static byte[][] toByteArrays(java.lang.String[] t)
t - operandspublic static byte[][] toByteArrays(java.lang.String column)
column - operandcolumnpublic static byte[][] toByteArrays(byte[] column)
column - operandcolumnpublic static byte[] copy(byte[] bytes)
bytes - the byte array to duplicatepublic static byte[] copy(byte[] bytes,
int offset,
int length)
bytes - the byte array to copy fromoffset - length - public static int unsignedBinarySearch(byte[] a,
int fromIndex,
int toIndex,
byte key)
a - Array to search. Entries must be sorted and unique.fromIndex - First index inclusive of "a" to include in the search.toIndex - Last index exclusive of "a" to include in the search.key - The byte to search for.public static byte[] unsignedCopyAndIncrement(byte[] input)
input - The byte[] to increment.public static byte[] createStopKeyForPrefix(byte[] prefix)
public static byte[] appendZeroByte(byte[] input)
input - The byte[] to append to.public static boolean equals(java.util.List<byte[]> a,
java.util.List<byte[]> b)
public static int indexOf(byte[] array,
byte target)
target in
array.array - an array of byte values, possibly emptytarget - a primitive byte valuei for which array[i] == target, or
-1 if no such index exists.public static int indexOf(byte[] array,
byte[] target)
target within array, or -1 if there is no such occurrence.
More formally, returns the lowest index i such that java.util.Arrays.copyOfRange(array, i, i + target.length) contains exactly
the same elements as target.
array - the array to search for the sequence targettarget - the array to search for as a sub-sequence of arraypublic static boolean contains(byte[] array,
byte target)
array - an array of byte values, possibly emptytarget - a primitive byte valuetrue if target is present as an element anywhere in array.public static boolean contains(byte[] array,
byte[] target)
array - an array of byte values, possibly emptytarget - an array of bytetrue if target is present anywhere in arraypublic static void zero(byte[] b)
b - array which needs to be filled with zerospublic static void zero(byte[] b,
int offset,
int length)
b - offset - length - public static void random(byte[] b)
b - array which needs to be filled with random bytespublic static void random(byte[] b,
int offset,
int length)
b - offset - length - public static byte[] createMaxByteArray(int maxByteCount)
maxByteCount - the length of returned byte arraypublic static byte[] multiple(byte[] srcBytes,
int multiNum)
srcBytes - multiNum - public static java.lang.String toHex(byte[] b)
b - public static byte[] fromHex(java.lang.String hex)
hex - public static byte[] maxOfStartRows(byte[] left,
byte[] right)
public static byte[] minOfStartRows(byte[] left,
byte[] right)
public static byte[] maxOfStopRows(byte[] left,
byte[] right)
public static byte[] minOfStopRows(byte[] left,
byte[] right)
public static byte[] concatenate(byte[] a,
byte[] b)