@InterfaceAudience.Public public class Bytes extends Object implements Comparable<Bytes>
Modifier and Type | Class and Description |
---|---|
static class |
Bytes.ByteArrayComparator
Byte array comparator class.
|
(package private) static interface |
Bytes.Comparer<T> |
(package private) static class |
Bytes.Converter |
(package private) static class |
Bytes.ConverterHolder |
(package private) static class |
Bytes.LexicographicalComparerHolder
Provides a lexicographical comparer implementation; either a Java implementation or a faster
implementation based on
Unsafe . |
static class |
Bytes.RowEndKeyComparator
A
Bytes.ByteArrayComparator that treats the empty array as the largest value. |
Modifier and Type | Field and Description |
---|---|
private byte[] |
bytes |
static Comparator<byte[]> |
BYTES_COMPARATOR
Pass this to TreeMaps where byte [] are keys.
|
static org.apache.hadoop.io.RawComparator<byte[]> |
BYTES_RAWCOMPARATOR
Use comparing byte arrays, byte-by-byte
|
private static byte[] |
EMPTY_BYTE_ARRAY |
static int |
ESTIMATED_HEAP_TAX
Estimate of size cost to pay beyond payload in jvm for instance of byte [].
|
private static char[] |
HEX_CHARS |
private static char[] |
HEX_CHARS_UPPER |
private int |
length |
private static org.slf4j.Logger |
LOG |
static long |
MASK_FOR_LOWER_INT_IN_LONG
Mask to apply to a long to reveal the lower int only.
|
private int |
offset |
private static Random |
RNG |
private static SecureRandom |
SECURE_RNG |
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
|
(package private) static boolean |
UNSAFE_UNALIGNED |
private static String |
UTF8_CSN |
Constructor and Description |
---|
Bytes()
Create a zero-size sequence.
|
Bytes(byte[] bytes)
Create a Bytes using the byte array as the initial value.
|
Bytes(byte[] bytes,
int offset,
int length)
Set the value to a given byte range
|
Bytes(Bytes ibw)
Set the new Bytes to the contents of the passed
ibw . |
Bytes(com.google.protobuf.ByteString byteString)
Deprecated.
As of release 2.0.0, this will be removed in HBase 3.0.0.
|
Modifier and Type | Method and Description |
---|---|
static byte[] |
add(byte[][] arrays)
Concatenate byte arrays.
|
static byte[] |
add(byte[] a,
byte[] b)
Concatenate byte arrays.
|
static byte[] |
add(byte[] a,
byte[] b,
byte[] c)
Concatenate byte arrays.
|
private static byte[] |
binaryIncrementNeg(byte[] value,
long amount) |
private static byte[] |
binaryIncrementPos(byte[] value,
long amount) |
static int |
binarySearch(byte[][] arr,
byte[] key,
int offset,
int length)
Binary search for keys in indexes using Bytes.BYTES_RAWCOMPARATOR.
|
static int |
binarySearch(byte[][] arr,
byte[] key,
int offset,
int length,
org.apache.hadoop.io.RawComparator<?> comparator)
Deprecated.
since 2.0.0 and will be removed in 3.0.0. Use
binarySearch(byte[][], byte[], int, int) instead. |
static int |
binarySearch(byte[][] arr,
Cell key,
org.apache.hadoop.io.RawComparator<Cell> comparator)
Deprecated.
since 2.0.0 and will be removed in 3.0.0. Use
binarySearch(Cell[], Cell, CellComparator) instead. |
static int |
binarySearch(Cell[] arr,
Cell key,
CellComparator comparator)
Binary search for keys in indexes.
|
static long |
bytesToVint(byte[] buffer)
Reads a zero-compressed encoded long from input buffer and returns it.
|
int |
compareTo(byte[] that)
Compares the bytes in this object to the specified byte array n * @return Positive if left is
bigger than right, 0 if they are equal, and negative if left is smaller than right.
|
static int |
compareTo(byte[] left,
byte[] right)
Lexicographically compare two arrays.
|
static int |
compareTo(byte[] buffer1,
int offset1,
int length1,
byte[] buffer2,
int offset2,
int length2)
Lexicographically compare two arrays.
|
int |
compareTo(Bytes that)
Define the sort order of the Bytes.
|
static boolean |
contains(byte[] array,
byte target)
Return true if target is present as an element anywhere in the given array.
|
static boolean |
contains(byte[] array,
byte[] target)
Return true if target is present as an element anywhere in the given array.
|
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.
|
byte[] |
copyBytes()
Returns a copy of the bytes referred to by this writable
|
static byte[] |
createMaxByteArray(int maxByteCount)
Create a max byte array with the specified max byte count
|
static boolean |
equals(byte[] left,
byte[] right)
Lexicographically determine the equality of two arrays.
|
static boolean |
equals(byte[] a,
ByteBuffer buf)
Lexicographically determine the equality of two byte[], one as ByteBuffer.
|
static boolean |
equals(byte[] left,
int leftOffset,
int leftLen,
byte[] right,
int rightOffset,
int rightLen)
Lexicographically determine the equality of two arrays.
|
static boolean |
equals(List<byte[]> a,
List<byte[]> b) |
boolean |
equals(Object right_obj) |
private static IllegalArgumentException |
explainWrongLengthOrOffset(byte[] bytes,
int offset,
int length,
int expectedLength) |
static int |
findCommonPrefix(byte[] left,
byte[] right,
int leftLength,
int rightLength,
int leftOffset,
int rightOffset) |
static byte[] |
fromHex(String hex)
Create a byte array from a string of hash digits.
|
byte[] |
get()
Get the data from the Bytes.
|
static byte[] |
getBytes(ByteBuffer buf)
Returns a new byte array, copied from the given
buf , from the position (inclusive) to
the limit (exclusive). |
int |
getLength()
Returns the number of valid bytes in the buffer
|
int |
getOffset()
Return the offset into the buffer.
|
int |
getSize()
Deprecated.
since 2.0.0 and will be removed in 3.0.0. Use
getLength() instead. |
static List<byte[]> |
getUtf8ByteArrays(List<String> strings) |
int |
hashCode() |
static int |
hashCode(byte[] b)
Calculate a hash code from a given byte array.
|
static int |
hashCode(byte[] b,
int length)
Calculate a hash code from a given byte array.
|
static int |
hashCode(byte[] bytes,
int offset,
int length)
Calculate the hash code for a given range of bytes.
|
static byte[] |
head(byte[] a,
int length)
Make a new byte array from a subset of bytes at the head of another.
|
private static byte |
hexCharsToByte(char c1,
char c2) |
private static int |
hexCharToNibble(char ch) |
static byte[] |
incrementBytes(byte[] value,
long amount)
Bytewise binary increment/deincrement of long contained in byte array on given amount.
|
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. |
private static boolean |
isHexDigit(char c) |
static boolean |
isSorted(Collection<byte[]> arrays) |
static Iterable<byte[]> |
iterateOnSplits(byte[] a,
byte[] b,
boolean inclusive,
int num)
Iterate over keys within the passed range.
|
static Iterable<byte[]> |
iterateOnSplits(byte[] a,
byte[] b,
int num)
Iterate over keys within the passed range, splitting at an [a,b) boundary.
|
static int |
len(byte[] b)
Returns length of the byte array, returning 0 if the array is null.
|
(package private) static Bytes.Comparer<byte[]> |
lexicographicalComparerJavaImpl() |
static Integer |
mapKey(byte[] b)
Calculate a hash code from a given byte array suitable for use as a key in maps.
|
static Integer |
mapKey(byte[] b,
int length)
Calculate a hash code from a given byte array suitable for use as a key in maps.
|
static byte[] |
multiple(byte[] srcBytes,
int multiNum)
Create a byte array which is multiple given bytes nn * @return byte array
|
static byte[] |
padHead(byte[] a,
int length)
Make a new byte array from a subset of bytes at the head of another, zero padded as desired.
|
static byte[] |
padTail(byte[] a,
int length)
Make a new byte array from a subset of bytes at the tail of another, zero padded as desired.
|
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,
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,
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)
Put a double value out to the specified byte array position as the IEEE 754 double format.
|
static int |
putFloat(byte[] bytes,
int offset,
float f)
Put a float value out to the specified byte array position.
|
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)
Deprecated.
As of release 2.0.0, this will be removed in HBase 3.0.0.
|
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)
Deprecated.
As of release 2.0.0, this will be removed in HBase 3.0.0.
|
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)
Deprecated.
As of release 2.0.0, this will be removed in HBase 3.0.0.
|
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 long |
readAsVLong(byte[] buffer,
int offset)
Reads a zero-compressed encoded long from input buffer and returns it.
|
static byte[] |
readByteArray(DataInput in)
Read byte-array written with a WritableableUtils.vint prefix.
|
static byte[] |
readByteArrayThrowsRuntime(DataInput in)
Read byte-array written with a WritableableUtils.vint prefix.
|
private static byte[] |
readBytes(ByteBuffer buf) |
static String |
readStringFixedSize(DataInput in,
int size)
Reads a fixed-size field and interprets it as a string padded with zeros.
|
static long |
readVLong(byte[] buffer,
int offset)
Deprecated.
since 0.98.12. Use
readAsVLong(byte[],int) instead. |
static int |
searchDelimiterIndex(byte[] b,
int offset,
int length,
int delimiter)
Find index of passed delimiter.
|
static int |
searchDelimiterIndexInReverse(byte[] b,
int offset,
int length,
int delimiter)
Find index of passed delimiter walking from end of buffer backwards.
|
static void |
secureRandom(byte[] b)
Fill given array with random bytes using a strong random number generator.
|
static void |
secureRandom(byte[] b,
int offset,
int length)
Fill given array with random bytes at the specified position using a strong random number
generator.
|
void |
set(byte[] b)
Use passed bytes as backing array for this instance.
|
void |
set(byte[] b,
int offset,
int length)
Use passed bytes as backing array for this instance.
|
static byte[][] |
split(byte[] a,
byte[] b,
boolean inclusive,
int num)
Split passed range.
|
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)
Make a new byte array from a subset of bytes at the tail of another.
|
static byte[][] |
toArray(List<byte[]> array)
Convert a list of byte[] to an array
|
static BigDecimal |
toBigDecimal(byte[] bytes)
Converts a byte array to a BigDecimal
|
static BigDecimal |
toBigDecimal(byte[] bytes,
int offset,
int length)
Converts a byte array to a BigDecimal value
|
static byte[][] |
toBinaryByteArrays(String[] t)
Create an array of byte[] given an array of String.
|
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)
Create a byte[][] where first and only entry is
column |
static byte[][] |
toByteArrays(String column)
Create a byte[][] where first and only entry is
column |
static byte[][] |
toByteArrays(String[] t)
Create an array of byte[] given an array of String.
|
static byte[] |
toBytes(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(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)
Return the float represented as byte[]
|
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(String s)
Converts a string to a UTF-8 byte array.
|
static byte[] |
toBytesBinary(String in) |
com.google.protobuf.ByteString |
toByteString()
Deprecated.
As of release 2.0.0, this will be removed in HBase 3.0.0.
|
static double |
toDouble(byte[] bytes)
Return double made from passed bytes.
|
static double |
toDouble(byte[] bytes,
int offset)
Return double made from passed bytes.
|
static float |
toFloat(byte[] bytes)
Put a float value out to the specified byte array position.
|
static float |
toFloat(byte[] bytes,
int offset)
Put a float value out to the specified byte array position.
|
static String |
toHex(byte[] b)
Convert a byte array into a hex string
|
static String |
toHex(byte[] b,
int offset,
int length)
Convert a byte range 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)
Deprecated.
As of release 2.0.0, this will be removed in HBase 3.0.0.
|
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)
Deprecated.
As of release 2.0.0, this will be removed in HBase 3.0.0.
|
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)
Deprecated.
As of release 2.0.0, this will be removed in HBase 3.0.0.
|
String |
toString() |
static String |
toString(byte[] b)
Convert a byte[] into a string.
|
static String |
toString(byte[] b,
int off)
This method will convert utf8 encoded bytes into a string.
|
static String |
toString(byte[] b,
int off,
int len)
This method will convert utf8 encoded bytes into a string.
|
static String |
toString(byte[] b1,
String sep,
byte[] b2)
Joins two byte arrays together using a separator.
|
static String |
toStringBinary(byte[] b)
Write a printable representation of a byte array.
|
static String |
toStringBinary(byte[] b,
int off,
int len)
Write a printable representation of a byte array.
|
static String |
toStringBinary(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 byte[] |
vintToBytes(long vint)
Encode a long value as a variable length integer.
|
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(DataOutput out,
byte[] b)
Write byte-array with a WritableableUtils.vint prefix.
|
static void |
writeByteArray(DataOutput out,
byte[] b,
int offset,
int length)
Write byte-array to out with a vint length prefix.
|
static void |
writeStringFixedSize(DataOutput out,
String s,
int size)
Writes a string as a fixed-size field, padded with zeros.
|
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.
|
private static final byte[] EMPTY_BYTE_ARRAY
private static final org.slf4j.Logger LOG
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 long MASK_FOR_LOWER_INT_IN_LONG
public static final int ESTIMATED_HEAP_TAX
@InterfaceAudience.Private static final boolean UNSAFE_UNALIGNED
private byte[] bytes
private int offset
private int length
public static final Comparator<byte[]> BYTES_COMPARATOR
public static final org.apache.hadoop.io.RawComparator<byte[]> BYTES_RAWCOMPARATOR
private static final char[] HEX_CHARS_UPPER
private static final SecureRandom SECURE_RNG
private static final char[] HEX_CHARS
public Bytes()
public Bytes(byte[] bytes)
bytes
- This array becomes the backing storage for the object.public Bytes(Bytes ibw)
ibw
.ibw
- the value to set this Bytes to.public Bytes(byte[] bytes, int offset, int length)
bytes
- the new byte range to set tooffset
- the offset in newData to start atlength
- the number of bytes in the range@Deprecated public Bytes(com.google.protobuf.ByteString byteString)
byteString
- copy frompublic static final int len(byte[] b)
b
- byte array, which can be nullpublic byte[] get()
public void set(byte[] b)
public void set(byte[] b, int offset, int length)
@Deprecated public int getSize()
getLength()
instead.getLength()
,
HBASE-11862public int getLength()
public int getOffset()
@Deprecated public com.google.protobuf.ByteString toByteString()
public int compareTo(Bytes that)
compareTo
in interface Comparable<Bytes>
that
- The other bytes writablepublic int compareTo(byte[] that)
public static byte[][] toArray(List<byte[]> array)
array
- List of byte [].public byte[] copyBytes()
public static byte[] readByteArray(DataInput in) throws IOException
in
- Input to read from.in
IOException
- epublic static byte[] readByteArrayThrowsRuntime(DataInput in)
in
- Input to read from.in
public static void writeByteArray(DataOutput out, byte[] b) throws IOException
out
- output stream to be written tob
- array to writeIOException
- epublic static void writeByteArray(DataOutput out, byte[] b, int offset, int length) throws IOException
out
- output streamb
- arrayoffset
- offset into arraylength
- length past offsetIOException
- 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 int putByteBuffer(byte[] bytes, int offset, ByteBuffer buf)
bytes
- the byte arrayoffset
- position in the arraybuf
- ByteBuffer to write outpublic static byte[] toBytes(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)
private static byte[] readBytes(ByteBuffer buf)
public static String toString(byte[] b)
b
- Presumed UTF-8 encoded byte array.b
public static String toString(byte[] b1, String sep, byte[] b2)
b1
- The first byte array.sep
- The separator to use.b2
- The second byte array.public static String toString(byte[] b, int off)
b
- Presumed UTF-8 encoded byte array.off
- offset into arrayb
or nullpublic static 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 String toStringBinary(byte[] b)
b
- byte array n * @see #toStringBinary(byte[], int, int)public static String toStringBinary(ByteBuffer buf)
buf
- a byte buffertoBytes(ByteBuffer)
,
getBytes(ByteBuffer)
public static String toStringBinary(byte[] b, int off, int len)
b
- array to write outoff
- offset to start atlen
- length to writeprivate static boolean isHexDigit(char c)
public static byte toBinaryFromHex(byte ch)
ch
- The hex digit.public static byte[] toBytesBinary(String in)
public static byte[] toBytes(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
)IllegalArgumentException
- if length is not SIZEOF_LONG
or if there's not enough
room in the array at the offset indicated.private static IllegalArgumentException explainWrongLengthOrOffset(byte[] bytes, int offset, int length, int expectedLength)
public static int putLong(byte[] bytes, int offset, long val)
bytes
- the byte arrayoffset
- position in the arrayval
- long to write outIllegalArgumentException
- if the byte array given doesn't have enough room at the offset
specified.@Deprecated 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 valuebytes
public static byte[] toBytes(float f)
public static double toDouble(byte[] bytes)
public static double toDouble(byte[] bytes, int offset)
public static int putDouble(byte[] bytes, int offset, double d)
bytes
- byte arrayoffset
- offset to write tod
- valuebytes
public 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
)IllegalArgumentException
- if length is not SIZEOF_INT
or if there's not enough
room in the array at the offset indicated.@Deprecated public static int toIntUnsafe(byte[] bytes, int offset)
bytes
- byte arrayoffset
- offset into array@Deprecated public static short toShortUnsafe(byte[] bytes, int offset)
bytes
- byte arrayoffset
- offset into array@Deprecated public 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 intIllegalArgumentException
- 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 outIllegalArgumentException
- if the byte array given doesn't have enough room at the offset
specified.@Deprecated 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_SHORT
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(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 outIllegalArgumentException
- if the byte array given doesn't have enough room at the offset
specified.@Deprecated 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 outIllegalArgumentException
- if the byte array given doesn't have enough room at the offset
specified.public static byte[] toBytes(BigDecimal val)
public static BigDecimal toBigDecimal(byte[] bytes)
public static BigDecimal toBigDecimal(byte[] bytes, int offset, int length)
public static int putBigDecimal(byte[] bytes, int offset, BigDecimal val)
bytes
- the byte arrayoffset
- position in the arrayval
- BigDecimal to write outpublic static byte[] vintToBytes(long vint)
vint
- Integer to make a vint of.public static long bytesToVint(byte[] buffer)
buffer
- buffer to convert@Deprecated public static long readVLong(byte[] buffer, int offset) throws IOException
readAsVLong(byte[],int)
instead.buffer
- Binary arrayoffset
- Offset into array at which vint begins.IOException
- ereadAsVLong(byte[], int)
,
HBASE-6919public static long readAsVLong(byte[] buffer, int offset)
buffer
- Binary arrayoffset
- Offset into array at which vint begins.public 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 buffer@InterfaceAudience.Private static Bytes.Comparer<byte[]> lexicographicalComparerJavaImpl()
public 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)
left
- left operandleftOffset
- offset into left operandleftLen
- length of left operandright
- right operandrightOffset
- offset into right operandrightLen
- length of right operandpublic static boolean equals(byte[] a, ByteBuffer buf)
a
- left operandbuf
- 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
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
use calculating hash code.public static Integer mapKey(byte[] b)
b
- bytes to hashb
as an Integer that can be used as key in Maps.public static 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[] add(byte[][] arrays)
arrays
- all the arrays to concatenate together.public static byte[] head(byte[] a, int length)
a
- arraylength
- amount of bytes to grablength
bytes from a
public static byte[] tail(byte[] a, int length)
a
- arraylength
- amount of bytes to snarflength
bytes from a
public 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 byte[][] split(byte[] a, byte[] b, boolean inclusive, int num)
a
- Beginning of rangeb
- End of rangeinclusive
- Whether the end of range is prefix-inclusive or is considered an exclusive
boundary. Automatic splits are generally exclusive and manual splits with an
explicit range utilize an inclusive end of range.num
- Number of times to split range. Pass 1 if you want to split the range in two;
i.e. one split.public static Iterable<byte[]> iterateOnSplits(byte[] a, byte[] b, int num)
public static Iterable<byte[]> iterateOnSplits(byte[] a, byte[] b, boolean inclusive, int num)
public static int hashCode(byte[] bytes, int offset, int length)
bytes
- array to hashoffset
- offset to start fromlength
- length to hashpublic static byte[][] toByteArrays(String[] t)
t
- operandspublic static byte[][] toBinaryByteArrays(String[] t)
t
- operandspublic static byte[][] toByteArrays(String column)
column
column
- operandcolumn
public static byte[][] toByteArrays(byte[] column)
column
column
- operandcolumn
@Deprecated public static int binarySearch(byte[][] arr, byte[] key, int offset, int length, org.apache.hadoop.io.RawComparator<?> comparator)
binarySearch(byte[][], byte[], int, int)
instead.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.binarySearch(byte[][], byte[], int, int)
,
HBASE-13450public static int binarySearch(byte[][] arr, byte[] key, int offset, int length)
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 key@Deprecated public static int binarySearch(byte[][] arr, Cell key, org.apache.hadoop.io.RawComparator<Cell> comparator)
binarySearch(Cell[], Cell, CellComparator)
instead.arr
- array of byte arrays to search forkey
- the key you want to findcomparator
- a comparator to compare.binarySearch(Cell[], Cell, CellComparator)
,
HBASE-13450public static int binarySearch(Cell[] arr, Cell key, CellComparator comparator)
arr
- array of byte arrays to search forkey
- the key you want to findcomparator
- a comparator to compare.public static byte[] incrementBytes(byte[] value, long amount)
value
- - array of bytes containing long (length <= SIZEOF_LONG)amount
- value will be incremented on (deincremented if negative)private static byte[] binaryIncrementPos(byte[] value, long amount)
private static byte[] binaryIncrementNeg(byte[] value, long amount)
public static void writeStringFixedSize(DataOutput out, String s, int size) throws IOException
IOException
public static String readStringFixedSize(DataInput in, int size) throws IOException
IOException
public 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 frompublic 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 boolean isSorted(Collection<byte[]> arrays)
public static List<byte[]> getUtf8ByteArrays(List<String> strings)
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 target
target
- the array to search for as a sub-sequence of array
public 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 byte
true
if target
is present anywhere in array
public static void zero(byte[] b)
b
- array which needs to be filled with zerospublic static void zero(byte[] b, int offset, int length)
public static void random(byte[] b)
b
- array which needs to be filled with random bytes
If you want random bytes generated by a strong source of randomness use
secureRandom(byte[])
.
b
- array which needs to be filled with random bytespublic static void random(byte[] b, int offset, int length)
If you want random bytes generated by a strong source of randomness use
secureRandom(byte[], int, int)
.
b
- array which needs to be filled with random bytesoffset
- staring offset in arraylength
- number of bytes to fillpublic static void secureRandom(byte[] b)
b
- array which needs to be filled with random bytespublic static void secureRandom(byte[] b, int offset, int length)
b
- array which needs to be filled with random bytesoffset
- staring offset in arraylength
- number of bytes to fillpublic static byte[] createMaxByteArray(int maxByteCount)
maxByteCount
- the length of returned byte arraypublic static byte[] multiple(byte[] srcBytes, int multiNum)
public static String toHex(byte[] b, int offset, int length)
private static int hexCharToNibble(char ch)
private static byte hexCharsToByte(char c1, char c2)
public static byte[] fromHex(String hex)
public static int searchDelimiterIndex(byte[] b, int offset, int length, int delimiter)
b
moving rightward.public static int searchDelimiterIndexInReverse(byte[] b, int offset, int length, int delimiter)
public static int findCommonPrefix(byte[] left, byte[] right, int leftLength, int rightLength, int leftOffset, int rightOffset)
Copyright © 2007–2020 The Apache Software Foundation. All rights reserved.