public class Bytes
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static class |
Bytes.ByteArrayComparator
Byte array comparator class.
|
| Modifier and Type | Field and Description |
|---|---|
static java.util.Comparator<byte[]> |
BYTES_COMPARATOR
Pass this to TreeMaps where byte [] are keys.
|
static RawComparator<byte[]> |
BYTES_RAWCOMPARATOR
Use comparing byte arrays, byte-by-byte
|
static byte[] |
EMPTY_BYTE_ARRAY
An empty instance.
|
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
|
static java.lang.String |
UTF8_ENCODING
When we encode strings, we always specify UTF8 encoding
|
| 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 int |
binarySearch(byte[][] arr,
byte[] key,
int offset,
int length,
RawComparator<byte[]> comparator)
Binary search for keys in indexes.
|
static long |
bytesToVint(byte[] buffer) |
static int |
compareTo(byte[] left,
byte[] right) |
static int |
compareTo(byte[] buffer1,
int offset1,
int length1,
byte[] buffer2,
int offset2,
int length2)
Lexographically compare two arrays.
|
static boolean |
equals(byte[] left,
byte[] right) |
static int |
hashCode(byte[] b) |
static int |
hashCode(byte[] b,
int length) |
static byte[] |
head(byte[] a,
int length) |
static byte[] |
incrementBytes(byte[] value,
long amount)
Bytewise binary increment/deincrement of long contained in byte array on
given amount.
|
static java.lang.Iterable<byte[]> |
iterateOnSplits(byte[] a,
byte[] b,
int num)
Iterate over keys within the passed inclusive range.
|
static java.lang.Integer |
mapKey(byte[] b) |
static java.lang.Integer |
mapKey(byte[] b,
int length) |
static byte[] |
padHead(byte[] a,
int length) |
static byte[] |
padTail(byte[] a,
int length) |
static int |
putByte(byte[] bytes,
int offset,
byte b)
Write a single byte out to the specified byte array position.
|
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 |
putLong(byte[] bytes,
int offset,
long val)
Put a long value out to the specified byte array position.
|
static int |
putShort(byte[] bytes,
int offset,
short val)
Put a short value out to the specified byte array position.
|
static byte[] |
readByteArray(java.io.DataInput in)
Read byte-array written with a WritableableUtils.vint prefix.
|
static byte[] |
readByteArrayThrowsRuntime(java.io.DataInput in)
Read byte-array written with a WritableableUtils.vint prefix.
|
static long |
readVLong(byte[] buffer,
int offset)
Reads a zero-compressed encoded long from input stream and returns it.
|
static byte[][] |
split(byte[] a,
byte[] b,
int num)
Split passed range.
|
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 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 byte[] |
toBytes(boolean b)
Convert a boolean to a byte array.
|
static byte[] |
toBytes(java.nio.ByteBuffer bb)
Returns a new byte array, copied from the passed ByteBuffer.
|
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 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 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 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 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 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 bb)
This method will convert utf8 encoded bytes into a string.
|
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 bb)
Write a printable representation of a ByteBuffer.
|
static byte[] |
vintToBytes(long vint) |
static int |
writeByteArray(byte[] tgt,
int tgtOffset,
byte[] src,
int srcOffset,
int srcLength)
Write byte-array from src to tgt with a vint length prefix.
|
static void |
writeByteArray(java.io.DataOutput out,
byte[] b)
Write byte-array with a WritableableUtils.vint prefix.
|
static void |
writeByteArray(java.io.DataOutput out,
byte[] b,
int offset,
int length)
Write byte-array to out with a vint length prefix.
|
public static final java.lang.String UTF8_ENCODING
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 java.util.Comparator<byte[]> BYTES_COMPARATOR
public static RawComparator<byte[]> BYTES_RAWCOMPARATOR
public static byte[] readByteArray(java.io.DataInput in)
throws java.io.IOException
in - Input to read from.injava.io.IOException - epublic static byte[] readByteArrayThrowsRuntime(java.io.DataInput in)
in - Input to read from.inpublic static void writeByteArray(java.io.DataOutput out,
byte[] b)
throws java.io.IOException
out - output stream to be written tob - array to writejava.io.IOException - epublic static void writeByteArray(java.io.DataOutput out,
byte[] b,
int offset,
int length)
throws java.io.IOException
out - output streamb - arrayoffset - offset into arraylength - length past offsetjava.io.IOException - epublic static int writeByteArray(byte[] tgt,
int tgtOffset,
byte[] src,
int srcOffset,
int srcLength)
tgt - target arraytgtOffset - offset into target arraysrc - source arraysrcOffset - source offsetsrcLength - source lengthpublic 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 byte[] toBytes(java.nio.ByteBuffer bb)
bb - A ByteBufferpublic static java.lang.String toString(java.nio.ByteBuffer bb)
bb - Presumed UTF-8 encoded ByteBuffer.b or nullpublic 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 toStringBinary(java.nio.ByteBuffer bb)
bb - ByteBuffer to write outpublic static java.lang.String toStringBinary(byte[] b)
b - byte arraytoStringBinary(byte[], int, int)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 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 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 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 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 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 byte[] vintToBytes(long vint)
vint - Integer to make a vint of.public static long bytesToVint(byte[] buffer)
buffer - buffer to convertpublic static long readVLong(byte[] buffer,
int offset)
throws java.io.IOException
buffer - Binary arrayoffset - Offset into array at which vint begins.java.io.IOException - epublic 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 startsWith(byte[] bytes,
byte[] prefix)
public static int hashCode(byte[] b)
b - bytes to hashWritableComparator.hashBytes(byte[], int) on the
passed in array. This method is what
Text and
org.apache.hadoop.hbase.io.ImmutableBytesWritable use calculating hash code.public static int hashCode(byte[] b,
int length)
b - valuelength - length of the valueWritableComparator.hashBytes(byte[], int) on the
passed in array. This method is what
Text and
org.apache.hadoop.hbase.io.ImmutableBytesWritable use calculating hash code.public static java.lang.Integer mapKey(byte[] b)
b - bytes to hashb as an Integer that can be used as key in
Maps.public static java.lang.Integer mapKey(byte[] b,
int length)
b - bytes to hashlength - length to hashb as an Integer that can be used as key in
Maps.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 byte[][] split(byte[] a,
byte[] b,
int num)
a - Beginning of rangeb - End of rangenum - Number of times to split range. Pass 1 if you want to split the
range in two; i.e. one split.public static java.lang.Iterable<byte[]> iterateOnSplits(byte[] a,
byte[] b,
int num)
public 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 int binarySearch(byte[][] arr,
byte[] key,
int offset,
int length,
RawComparator<byte[]> comparator)
arr - array of byte arrays to search forkey - the key you want to findoffset - the offset in the key you want to findlength - the length of the keycomparator - a comparator to compare.public static byte[] incrementBytes(byte[] value,
long amount)
throws java.io.IOException
value - - array of bytes containing long (length <= SIZEOF_LONG)amount - value will be incremented on (deincremented if negative)java.io.IOException - - if value.length > SIZEOF_LONGCopyright © 2019 The Apache Software Foundation