Class Bytes
java.lang.Object
com.mapr.org.apache.hadoop.hbase.util.Bytes
Utility class that handles byte arrays, conversions to/from other types,
comparisons, hash code generation, manufacturing keys for HashMaps or
HashSets, etc.
Use this instead of the HBase class when we can not have dependency on
HBase artifacts.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classByte array comparator class.static classABytes.ByteArrayComparatorthat treats the empty array as the largest value. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Comparator<byte[]>Pass this to TreeMaps where byte [] are keys.static final byte[]static final intEstimate of size cost to pay beyond payload in jvm for instance of byte [].static final intSize of boolean in bytesstatic final intSize of byte in bytesstatic final intSize of char in bytesstatic final intSize of double in bytesstatic final intSize of float in bytesstatic final intSize of int in bytesstatic final intSize of long in bytesstatic final intSize of short in bytes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic 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 intcompareTo(byte[] left, byte[] right) static intcompareTo(byte[] buffer1, int offset1, int length1, byte[] buffer2, int offset2, int length2) Lexicographically compare two arrays.static byte[]concatenate(byte[] a, byte[] b) static booleancontains(byte[] array, byte target) static booleancontains(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 ByteBufferCopies a direct bytebuffer to a non-direct byte buffer.static ByteBufferCopies a non-direct bytebuffer to a direct byte buffer.static byte[]createMaxByteArray(int maxByteCount) Create a max byte array with the specified max byte countstatic byte[]createStopKeyForPrefix(byte[] prefix) Returns the Stop Key for the given physical row key prefixstatic booleanequals(byte[] left, byte[] right) static booleanequals(byte[] left, int leftOffset, int leftLen, byte[] right, int rightOffset, int rightLen) static booleanequals(byte[] a, ByteBuffer buf) static booleanstatic byte[]Create a byte array from a string of hash digits.static byte[]getBytes(ByteBuffer buf) Returns a new byte array, copied from the givenbuf, from the position (inclusive) to the limit (exclusive).static inthashCode(byte[] b) static inthashCode(byte[] bytes, int offset, int length) static byte[]head(byte[] a, int length) static intindexOf(byte[] array, byte target) Returns the index of the first appearance of the valuetargetinarray.static intindexOf(byte[] array, byte[] target) Returns the start position of the first occurrence of the specifiedtargetwithinarray, or-1if there is no such occurrence.static final intlen(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 bytesstatic byte[]padHead(byte[] a, int length) static byte[]padTail(byte[] a, int length) static intputAsShort(byte[] bytes, int offset, int val) Put an int value as short out to the specified byte array position.static intputBigDecimal(byte[] bytes, int offset, BigDecimal val) Put a BigDecimal value out to the specified byte array position.static intputByte(byte[] bytes, int offset, byte b) Write a single byte out to the specified byte array position.static intputByteBuffer(byte[] bytes, int offset, ByteBuffer buf) Add the whole content of the ByteBuffer to the bytes arrays.static intputBytes(byte[] tgtBytes, int tgtOffset, byte[] srcBytes, int srcOffset, int srcLength) Put bytes at the specified byte array position.static intputDouble(byte[] bytes, int offset, double d) static intputFloat(byte[] bytes, int offset, float f) static intputInt(byte[] bytes, int offset, int val) Put an int value out to the specified byte array position.static intputIntUnsafe(byte[] bytes, int offset, int val) Put an int value out to the specified byte array position (Unsafe).static intputLong(byte[] bytes, int offset, long val) Put a long value out to the specified byte array position.static intputLongUnsafe(byte[] bytes, int offset, long val) Put a long value out to the specified byte array position (Unsafe).static intputShort(byte[] bytes, int offset, short val) Put a short value out to the specified byte array position.static intputShortUnsafe(byte[] bytes, int offset, short val) Put a short value out to the specified byte array position (Unsafe).static voidrandom(byte[] b) Fill given array with random bytes.static voidrandom(byte[] b, int offset, int length) Fill given array with random bytes at the specified position.static intreadAsInt(byte[] bytes, int offset, int length) Converts a byte array to an int valuestatic booleanstartsWith(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 StringtoBase64(byte[] b) Encodes the specified byte array to a base-64 String.static BigDecimaltoBigDecimal(byte[] bytes) Converts a byte array to a BigDecimalstatic BigDecimaltoBigDecimal(byte[] bytes, int offset, int length) Converts a byte array to a BigDecimal valuestatic bytetoBinaryFromHex(byte ch) Takes a ASCII digit in the range A-F0-9 and returns the corresponding integer/ordinal value.static booleantoBoolean(byte[] b) ReversestoBytes(boolean)static byte[][]toByteArrays(byte[] column) static byte[][]toByteArrays(String column) static byte[][]toByteArrays(String[] t) static ByteBufferConverts a string to a UTF-8 ByteBuffer.static byte[]toBytes(boolean b) Convert a boolean to a byte array.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 ofSIZEOF_SHORTbytes long.static byte[]Converts a string to a UTF-8 byte array.static byte[]toBytes(BigDecimal val) Convert a BigDecimal value to a byte arraystatic byte[]toBytes(ByteBuffer buf) Returns a new byte array, copied from the givenbuf, from the index 0 (inclusive) to the limit (exclusive), regardless of the current position.static byte[]toBytesBinary(String in) static ByteBufferConverts a string to a UTF-8 DirectByteBuffer.static doubletoDouble(byte[] bytes) static doubletoDouble(byte[] bytes, int offset) static floattoFloat(byte[] bytes) Presumes float encoded as IEEE 754 floating-point "single format"static floattoFloat(byte[] bytes, int offset) Presumes float encoded as IEEE 754 floating-point "single format"static StringtoHex(byte[] b) Convert a byte array into a hex stringstatic inttoInt(byte[] bytes) Converts a byte array to an int valuestatic inttoInt(byte[] bytes, int offset) Converts a byte array to an int valuestatic inttoInt(byte[] bytes, int offset, int length) Converts a byte array to an int valuestatic inttoIntUnsafe(byte[] bytes, int offset) Converts a byte array to an int value (Unsafe version)static longtoLong(byte[] bytes) Converts a byte array to a long value.static longtoLong(byte[] bytes, int offset) Converts a byte array to a long value.static longtoLong(byte[] bytes, int offset, int length) Converts a byte array to a long value.static longtoLongUnsafe(byte[] bytes, int offset) Converts a byte array to an long value (Unsafe version)static shorttoShort(byte[] bytes) Converts a byte array to a short valuestatic shorttoShort(byte[] bytes, int offset) Converts a byte array to a short valuestatic shorttoShort(byte[] bytes, int offset, int length) Converts a byte array to a short valuestatic shorttoShortUnsafe(byte[] bytes, int offset) Converts a byte array to an short value (Unsafe version)static StringtoString(byte[] b) static StringtoString(byte[] b, int off, int len) This method will convert utf8 encoded bytes into a string.static StringJoins two byte arrays together using a separator.static Stringstatic StringtoString(ByteBuffer b, int len) static StringtoString(ByteBuffer b, int offset, int len) static StringtoStringBinary(byte[] b) Write a printable representation of a byte array.static StringtoStringBinary(byte[] b, int off, int len) Write a printable representation of a byte array.static StringtoStringBinary(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 StringConverts the given byte buffer to a printable representation, from the position (inclusive) to the limit (exclusive).static intunsignedBinarySearch(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 voidzero(byte[] b) Fill given array with zeros.static voidzero(byte[] b, int offset, int length) Fill given array with zeros at the specified position.
-
Field Details
-
EMPTY_BYTE_ARRAY
public static final byte[] EMPTY_BYTE_ARRAY -
SIZEOF_BOOLEAN
public static final int SIZEOF_BOOLEANSize of boolean in bytes- See Also:
-
SIZEOF_BYTE
public static final int SIZEOF_BYTESize of byte in bytes- See Also:
-
SIZEOF_CHAR
public static final int SIZEOF_CHARSize of char in bytes- See Also:
-
SIZEOF_DOUBLE
public static final int SIZEOF_DOUBLESize of double in bytes- See Also:
-
SIZEOF_FLOAT
public static final int SIZEOF_FLOATSize of float in bytes- See Also:
-
SIZEOF_INT
public static final int SIZEOF_INTSize of int in bytes- See Also:
-
SIZEOF_LONG
public static final int SIZEOF_LONGSize of long in bytes- See Also:
-
SIZEOF_SHORT
public static final int SIZEOF_SHORTSize of short in bytes- See Also:
-
ESTIMATED_HEAP_TAX
public static final int ESTIMATED_HEAP_TAXEstimate of size cost to pay beyond payload in jvm for instance of byte []. Estimate based on study of jhat and jprofiler numbers.- See Also:
-
BYTES_COMPARATOR
Pass this to TreeMaps where byte [] are keys.
-
-
Constructor Details
-
Bytes
public Bytes()
-
-
Method Details
-
len
public static final int len(byte[] b) Returns length of the byte array, returning 0 if the array is null. Useful for calculating sizes.- Parameters:
b- byte array, which can be null- Returns:
- 0 if b is null, otherwise returns length
-
putBytes
public static int putBytes(byte[] tgtBytes, int tgtOffset, byte[] srcBytes, int srcOffset, int srcLength) Put bytes at the specified byte array position.- Parameters:
tgtBytes- the byte arraytgtOffset- position in the arraysrcBytes- array to write outsrcOffset- source offsetsrcLength- source length- Returns:
- incremented offset
-
putByte
public static int putByte(byte[] bytes, int offset, byte b) Write a single byte out to the specified byte array position.- Parameters:
bytes- the byte arrayoffset- position in the arrayb- byte to write out- Returns:
- incremented offset
-
putByteBuffer
Add the whole content of the ByteBuffer to the bytes arrays. The ByteBuffer is modified.- Parameters:
bytes- the byte arrayoffset- position in the arraybuf- ByteBuffer to write out- Returns:
- incremented offset
-
toBytes
Returns a new byte array, copied from the givenbuf, from the index 0 (inclusive) to the limit (exclusive), regardless of the current position. The position and the other index parameters are not changed.- Parameters:
buf- a byte buffer- Returns:
- the byte array
- See Also:
-
toString
-
toString
-
toString
-
toString
- Parameters:
b- Presumed UTF-8 encoded byte array.- Returns:
- String made from
b
-
toString
Joins two byte arrays together using a separator.- Parameters:
b1- The first byte array.sep- The separator to use.b2- The second byte array.
-
toString
This method will convert utf8 encoded bytes into a string. If the given byte array is null, this method will return null.- Parameters:
b- Presumed UTF-8 encoded byte array.off- offset into arraylen- length of utf-8 sequence- Returns:
- String made from
bor null
-
toBase64
Encodes the specified byte array to a base-64 String.- Parameters:
b- byte array- Returns:
- base 64 encoded string
-
toStringBinary
Write a printable representation of a byte array.- Parameters:
b- byte array- Returns:
- string
- See Also:
-
toStringBinary
Converts the given byte buffer to a printable representation, from the index 0 (inclusive) to the limit (exclusive), regardless of the current position. The position and the other index parameters are not changed.- Parameters:
buf- a byte buffer- Returns:
- a string representation of the buffer's binary contents
- See Also:
-
toStringBinary2
Converts the given byte buffer to a printable representation, from the position (inclusive) to the limit (exclusive). The position and the other index parameters are not changed.- Parameters:
buf- a byte buffer- Returns:
- a string representation of the buffer's binary contents
- See Also:
-
toStringBinary
Write a printable representation of a byte array. Non-printable characters are hex escaped in the format \\x%02X, eg: \x00 \x05 etc- Parameters:
b- array to write outoff- offset to start atlen- length to write- Returns:
- string output
-
toBinaryFromHex
public static byte toBinaryFromHex(byte ch) Takes a ASCII digit in the range A-F0-9 and returns the corresponding integer/ordinal value.- Parameters:
ch- The hex digit.- Returns:
- The converted hex value as a byte.
-
toBytesBinary
-
toDirectByteBuffer
Converts a string to a UTF-8 DirectByteBuffer.- Parameters:
s- string- Returns:
- the byte array
-
copyToByteBuffer
Copies a direct bytebuffer to a non-direct byte buffer.- Parameters:
bb- input byte buffer, needs to be non-direct- Returns:
- a new copy of the bytes in a direct byte buffer
-
copyToDirectByteBuffer
Copies a non-direct bytebuffer to a direct byte buffer.- Parameters:
bb- input byte buffer, needs to be non-direct- Returns:
- a new copy of the bytes in a direct byte buffer
-
toByteBuffer
Converts a string to a UTF-8 ByteBuffer.- Parameters:
s- string- Returns:
- the byte array
-
toBytes
Converts a string to a UTF-8 byte array.- Parameters:
s- string- Returns:
- the byte array
-
toBytes
public static byte[] toBytes(boolean b) Convert a boolean to a byte array. True becomes -1 and false becomes 0.- Parameters:
b- value- Returns:
bencoded in a byte array.
-
toBoolean
public static boolean toBoolean(byte[] b) ReversestoBytes(boolean)- Parameters:
b- array- Returns:
- True or false.
-
toBytes
public static byte[] toBytes(long val) Convert a long value to a byte array using big-endian.- Parameters:
val- value to convert- Returns:
- the byte array
-
toLong
public static long toLong(byte[] bytes) Converts a byte array to a long value. ReversestoBytes(long)- Parameters:
bytes- array- Returns:
- the long value
-
toLong
public static long toLong(byte[] bytes, int offset) Converts a byte array to a long value. Assumes there will beSIZEOF_LONGbytes available.- Parameters:
bytes- bytesoffset- offset- Returns:
- the long value
-
toLong
public static long toLong(byte[] bytes, int offset, int length) Converts a byte array to a long value.- Parameters:
bytes- array of bytesoffset- offset into arraylength- length of data (must beSIZEOF_LONG)- Returns:
- the long value
- Throws:
IllegalArgumentException- if length is notSIZEOF_LONGor if there's not enough room in the array at the offset indicated.
-
putLong
public static int putLong(byte[] bytes, int offset, long val) Put a long value out to the specified byte array position.- Parameters:
bytes- the byte arrayoffset- position in the arrayval- long to write out- Returns:
- incremented offset
- Throws:
IllegalArgumentException- if the byte array given doesn't have enough room at the offset specified.
-
putLongUnsafe
public static int putLongUnsafe(byte[] bytes, int offset, long val) Put a long value out to the specified byte array position (Unsafe).- Parameters:
bytes- the byte arrayoffset- position in the arrayval- long to write out- Returns:
- incremented offset
-
toFloat
public static float toFloat(byte[] bytes) Presumes float encoded as IEEE 754 floating-point "single format"- Parameters:
bytes- byte array- Returns:
- Float made from passed byte array.
-
toFloat
public static float toFloat(byte[] bytes, int offset) Presumes float encoded as IEEE 754 floating-point "single format"- Parameters:
bytes- array to convertoffset- offset into array- Returns:
- Float made from passed byte array.
-
putFloat
public static int putFloat(byte[] bytes, int offset, float f) - Parameters:
bytes- byte arrayoffset- offset to write tof- float value- Returns:
- New offset in
bytes
-
toBytes
public static byte[] toBytes(float f) - Parameters:
f- float value- Returns:
- the float represented as byte []
-
toDouble
public static double toDouble(byte[] bytes) - Parameters:
bytes- byte array- Returns:
- Return double made from passed bytes.
-
toDouble
public static double toDouble(byte[] bytes, int offset) - Parameters:
bytes- byte arrayoffset- offset where double is- Returns:
- Return double made from passed bytes.
-
putDouble
public static int putDouble(byte[] bytes, int offset, double d) - Parameters:
bytes- byte arrayoffset- offset to write tod- value- Returns:
- New offset into array
bytes
-
toBytes
public static byte[] toBytes(double d) Serialize a double as the IEEE 754 double format output. The resultant array will be 8 bytes long.- Parameters:
d- value- Returns:
- the double represented as byte []
-
toBytes
public static byte[] toBytes(int val) Convert an int value to a byte array. Big-endian. Same as what DataOutputStream.writeInt does.- Parameters:
val- value- Returns:
- the byte array
-
toInt
public static int toInt(byte[] bytes) Converts a byte array to an int value- Parameters:
bytes- byte array- Returns:
- the int value
-
toInt
public static int toInt(byte[] bytes, int offset) Converts a byte array to an int value- Parameters:
bytes- byte arrayoffset- offset into array- Returns:
- the int value
-
toInt
public static int toInt(byte[] bytes, int offset, int length) Converts a byte array to an int value- Parameters:
bytes- byte arrayoffset- offset into arraylength- length of int (has to beSIZEOF_INT)- Returns:
- the int value
- Throws:
IllegalArgumentException- if length is notSIZEOF_INTor if there's not enough room in the array at the offset indicated.
-
toIntUnsafe
public static int toIntUnsafe(byte[] bytes, int offset) Converts a byte array to an int value (Unsafe version)- Parameters:
bytes- byte arrayoffset- offset into array- Returns:
- the int value
-
toShortUnsafe
public static short toShortUnsafe(byte[] bytes, int offset) Converts a byte array to an short value (Unsafe version)- Parameters:
bytes- byte arrayoffset- offset into array- Returns:
- the short value
-
toLongUnsafe
public static long toLongUnsafe(byte[] bytes, int offset) Converts a byte array to an long value (Unsafe version)- Parameters:
bytes- byte arrayoffset- offset into array- Returns:
- the long value
-
readAsInt
public static int readAsInt(byte[] bytes, int offset, int length) Converts a byte array to an int value- Parameters:
bytes- byte arrayoffset- offset into arraylength- how many bytes should be considered for creating int- Returns:
- the int value
- Throws:
IllegalArgumentException- if there's not enough room in the array at the offset indicated.
-
putInt
public static int putInt(byte[] bytes, int offset, int val) Put an int value out to the specified byte array position.- Parameters:
bytes- the byte arrayoffset- position in the arrayval- int to write out- Returns:
- incremented offset
- Throws:
IllegalArgumentException- if the byte array given doesn't have enough room at the offset specified.
-
putIntUnsafe
public static int putIntUnsafe(byte[] bytes, int offset, int val) Put an int value out to the specified byte array position (Unsafe).- Parameters:
bytes- the byte arrayoffset- position in the arrayval- int to write out- Returns:
- incremented offset
-
toBytes
public static byte[] toBytes(short val) Convert a short value to a byte array ofSIZEOF_SHORTbytes long.- Parameters:
val- value- Returns:
- the byte array
-
toShort
public static short toShort(byte[] bytes) Converts a byte array to a short value- Parameters:
bytes- byte array- Returns:
- the short value
-
toShort
public static short toShort(byte[] bytes, int offset) Converts a byte array to a short value- Parameters:
bytes- byte arrayoffset- offset into array- Returns:
- the short value
-
toShort
public static short toShort(byte[] bytes, int offset, int length) Converts a byte array to a short value- Parameters:
bytes- byte arrayoffset- offset into arraylength- length, has to beSIZEOF_SHORT- Returns:
- the short value
- Throws:
IllegalArgumentException- if length is notSIZEOF_SHORTor if there's not enough room in the array at the offset indicated.
-
getBytes
Returns a new byte array, copied from the givenbuf, from the position (inclusive) to the limit (exclusive). The position and the other index parameters are not changed.- Parameters:
buf- a byte buffer- Returns:
- the byte array
- See Also:
-
putShort
public static int putShort(byte[] bytes, int offset, short val) Put a short value out to the specified byte array position.- Parameters:
bytes- the byte arrayoffset- position in the arrayval- short to write out- Returns:
- incremented offset
- Throws:
IllegalArgumentException- if the byte array given doesn't have enough room at the offset specified.
-
putShortUnsafe
public static int putShortUnsafe(byte[] bytes, int offset, short val) Put a short value out to the specified byte array position (Unsafe).- Parameters:
bytes- the byte arrayoffset- position in the arrayval- short to write out- Returns:
- incremented offset
-
putAsShort
public static int putAsShort(byte[] bytes, int offset, int val) Put an int value as short out to the specified byte array position. Only the lower 2 bytes of the short will be put into the array. The caller of the API need to make sure they will not loose the value by doing so. This is useful to store an unsigned short which is represented as int in other parts.- Parameters:
bytes- the byte arrayoffset- position in the arrayval- value to write out- Returns:
- incremented offset
- Throws:
IllegalArgumentException- if the byte array given doesn't have enough room at the offset specified.
-
toBytes
Convert a BigDecimal value to a byte array- Parameters:
val-- Returns:
- the byte array
-
toBigDecimal
Converts a byte array to a BigDecimal- Parameters:
bytes-- Returns:
- the char value
-
toBigDecimal
Converts a byte array to a BigDecimal value- Parameters:
bytes-offset-length-- Returns:
- the char value
-
putBigDecimal
Put a BigDecimal value out to the specified byte array position.- Parameters:
bytes- the byte arrayoffset- position in the arrayval- BigDecimal to write out- Returns:
- incremented offset
-
compareTo
public static int compareTo(byte[] left, byte[] right) - Parameters:
left- left operandright- right operand- Returns:
- 0 if equal, < 0 if left is less than right, etc.
-
compareTo
public static int compareTo(byte[] buffer1, int offset1, int length1, byte[] buffer2, int offset2, int length2) Lexicographically compare two arrays.- Parameters:
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- Returns:
- 0 if equal, < 0 if left is less than right, etc.
-
equals
public static boolean equals(byte[] left, byte[] right) - Parameters:
left- left operandright- right operand- Returns:
- True if equal
-
equals
public static boolean equals(byte[] left, int leftOffset, int leftLen, byte[] right, int rightOffset, int rightLen) -
equals
- Parameters:
a- left operandbuf- right operand- Returns:
- True if equal
-
startsWith
public 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. -
hashCode
public static int hashCode(byte[] b) - Parameters:
b- bytes to hash- Returns:
- Runs
Arrays#hashCode(byte[], int)on the passed in array. This method is whatorg.apache.hadoop.io.TextandImmutableBytesWritableuse calculating hash code.
-
add
public static byte[] add(byte[] a, byte[] b) - Parameters:
a- lower halfb- upper half- Returns:
- New array that has a in lower half and b in upper half.
-
add
public static byte[] add(byte[] a, byte[] b, byte[] c) - Parameters:
a- first thirdb- second thirdc- third third- Returns:
- New array made from a, b and c
-
head
public static byte[] head(byte[] a, int length) - Parameters:
a- arraylength- amount of bytes to grab- Returns:
- First
lengthbytes froma
-
tail
public static byte[] tail(byte[] a, int length) - Parameters:
a- arraylength- amount of bytes to snarf- Returns:
- Last
lengthbytes froma
-
padHead
public static byte[] padHead(byte[] a, int length) - Parameters:
a- arraylength- new array size- Returns:
- Value in
apluslengthprepended 0 bytes
-
padTail
public static byte[] padTail(byte[] a, int length) - Parameters:
a- arraylength- new array size- Returns:
- Value in
apluslengthappended 0 bytes
-
hashCode
public static int hashCode(byte[] bytes, int offset, int length) - Parameters:
bytes- array to hashoffset- offset to start fromlength- length to hash
-
toByteArrays
- Parameters:
t- operands- Returns:
- Array of byte arrays made from passed array of Text
-
toByteArrays
- Parameters:
column- operand- Returns:
- A byte array of a byte array where first and only entry is
column
-
toByteArrays
public static byte[][] toByteArrays(byte[] column) - Parameters:
column- operand- Returns:
- A byte array of a byte array where first and only entry is
column
-
copy
public 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.- Parameters:
bytes- the byte array to duplicate- Returns:
- a copy of the given byte array
-
copy
public 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.- Parameters:
bytes- the byte array to copy fromoffset-length-- Returns:
- a copy of the given designated byte array
-
unsignedBinarySearch
public static int unsignedBinarySearch(byte[] a, int fromIndex, int toIndex, byte key) Search sorted array "a" for byte "key". I can't remember if I wrote this or copied it from somewhere. (mcorgan)- Parameters:
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.- Returns:
- The index of key if found. If not found, return -(index + 1), where negative indicates "not found" and the "index + 1" handles the "-0" case.
-
unsignedCopyAndIncrement
public static byte[] unsignedCopyAndIncrement(byte[] input) Treat the byte[] as an unsigned series of bytes, most significant bits first. Start by adding 1 to the rightmost bit/byte and carry over all overflows to the more significant bits/bytes.- Parameters:
input- The byte[] to increment.- Returns:
- The incremented copy of "in". May be same length or 1 byte longer.
-
createStopKeyForPrefix
public static byte[] createStopKeyForPrefix(byte[] prefix) Returns the Stop Key for the given physical row key prefix -
appendZeroByte
public static byte[] appendZeroByte(byte[] input) Treat the byte[] as an unsigned series of bytes, most significant bits first. Append \x00 to those series of bytes.- Parameters:
input- The byte[] to append to.- Returns:
- The appended copy of "input". Will always by 1 byte longer.
-
equals
-
indexOf
public static int indexOf(byte[] array, byte target) Returns the index of the first appearance of the valuetargetinarray.- Parameters:
array- an array ofbytevalues, possibly emptytarget- a primitivebytevalue- Returns:
- the least index
ifor whicharray[i] == target, or-1if no such index exists.
-
indexOf
public static int indexOf(byte[] array, byte[] target) Returns the start position of the first occurrence of the specifiedtargetwithinarray, or-1if there is no such occurrence.More formally, returns the lowest index
isuch thatjava.util.Arrays.copyOfRange(array, i, i + target.length)contains exactly the same elements astarget.- Parameters:
array- the array to search for the sequencetargettarget- the array to search for as a sub-sequence ofarray
-
contains
public static boolean contains(byte[] array, byte target) - Parameters:
array- an array ofbytevalues, possibly emptytarget- a primitivebytevalue- Returns:
trueiftargetis present as an element anywhere inarray.
-
contains
public static boolean contains(byte[] array, byte[] target) - Parameters:
array- an array ofbytevalues, possibly emptytarget- an array ofbyte- Returns:
trueiftargetis present anywhere inarray
-
zero
public static void zero(byte[] b) Fill given array with zeros.- Parameters:
b- array which needs to be filled with zeros
-
zero
public static void zero(byte[] b, int offset, int length) Fill given array with zeros at the specified position.- Parameters:
b-offset-length-
-
random
public static void random(byte[] b) Fill given array with random bytes.- Parameters:
b- array which needs to be filled with random bytes
-
random
public static void random(byte[] b, int offset, int length) Fill given array with random bytes at the specified position.- Parameters:
b-offset-length-
-
createMaxByteArray
public static byte[] createMaxByteArray(int maxByteCount) Create a max byte array with the specified max byte count- Parameters:
maxByteCount- the length of returned byte array- Returns:
- the created max byte array
-
multiple
public static byte[] multiple(byte[] srcBytes, int multiNum) Create a byte array which is multiple given bytes- Parameters:
srcBytes-multiNum-- Returns:
- byte array
-
toHex
Convert a byte array into a hex string- Parameters:
b-
-
fromHex
Create a byte array from a string of hash digits. The length of the string must be a multiple of 2- Parameters:
hex-
-
maxOfStartRows
public static byte[] maxOfStartRows(byte[] left, byte[] right) -
minOfStartRows
public static byte[] minOfStartRows(byte[] left, byte[] right) -
maxOfStopRows
public static byte[] maxOfStopRows(byte[] left, byte[] right) -
minOfStopRows
public static byte[] minOfStopRows(byte[] left, byte[] right) -
concatenate
public static byte[] concatenate(byte[] a, byte[] b)
-