Package org.apache.hadoop.hbase.util
Class Bytes
java.lang.Object
org.apache.hadoop.hbase.util.Bytes
- All Implemented Interfaces:
Comparable<Bytes>
Utility class that handles byte arrays, conversions to/from other types, comparisons, hash code
generation, manufacturing keys for HashMaps or HashSets, and can be used as key in maps or trees.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classByte array comparator class.(package private) static class(package private) static class(package private) static interface(package private) static class(package private) static class(package private) static classProvides a lexicographical comparer implementation; either a Java implementation or a faster implementation based onUnsafe.static classABytes.ByteArrayComparatorthat treats the empty array as the largest value. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate byte[]static final Comparator<byte[]>Pass this to TreeMaps where byte [] are keys.static final org.apache.hadoop.io.RawComparator<byte[]>Use comparing byte arrays, byte-by-byteprivate static final byte[]static final intEstimate of size cost to pay beyond payload in jvm for instance of byte [].private static final char[]private static final char[]private intprivate static final org.slf4j.Loggerstatic final longMask to apply to a long to reveal the lower int only.private intprivate static final Randomprivate static final SecureRandomstatic 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(package private) static final booleanprivate static final String -
Constructor Summary
ConstructorsConstructorDescriptionBytes()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 rangeBytes(com.google.protobuf.ByteString byteString) Deprecated.As of release 2.0.0, this will be removed in HBase 3.0.0.Set the new Bytes to the contents of the passedibw. -
Method Summary
Modifier and TypeMethodDescriptionstatic 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 intbinarySearch(byte[][] arr, byte[] key, int offset, int length) Binary search for keys in indexes using Bytes.BYTES_RAWCOMPARATOR.static intbinarySearch(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.static intbinarySearch(byte[][] arr, Cell key, org.apache.hadoop.io.RawComparator<Cell> comparator) Deprecated.since 2.0.0 and will be removed in 3.0.0.static intbinarySearch(Cell[] arr, Cell key, CellComparator comparator) Binary search for keys in indexes.static longbytesToVint(byte[] buffer) Reads a zero-compressed encoded long from input buffer and returns it.intcompareTo(byte[] that) Compares the bytes in this object to the specified byte arraystatic intcompareTo(byte[] left, byte[] right) Lexicographically compare two arrays.static intcompareTo(byte[] buffer1, int offset1, int length1, byte[] buffer2, int offset2, int length2) Lexicographically compare two arrays.intDefine the sort order of the Bytes.static booleancontains(byte[] array, byte target) Return true if target is present as an element anywhere in the given array.static booleancontains(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[]Returns a copy of the bytes referred to by this writablestatic byte[]createMaxByteArray(int maxByteCount) Create a max byte array with the specified max byte countstatic booleanequals(byte[] left, byte[] right) Lexicographically determine the equality of two arrays.static booleanequals(byte[] left, int leftOffset, int leftLen, byte[] right, int rightOffset, int rightLen) Lexicographically determine the equality of two arrays.static booleanequals(byte[] a, ByteBuffer buf) Lexicographically determine the equality of two byte[], one as ByteBuffer.booleanstatic booleanprivate static IllegalArgumentExceptionexplainWrongLengthOrOffset(byte[] bytes, int offset, int length, int expectedLength) static intfindCommonPrefix(byte[] left, byte[] right, int leftLength, int rightLength, int leftOffset, int rightOffset) static byte[]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 givenbuf, from the position (inclusive) to the limit (exclusive).intReturns the number of valid bytes in the bufferintReturn the offset into the buffer.intgetSize()Deprecated.since 2.0.0 and will be removed in 3.0.0.static List<byte[]>getUtf8ByteArrays(List<String> strings) inthashCode()static inthashCode(byte[] b) Calculate a hash code from a given byte array.static inthashCode(byte[] b, int length) Calculate a hash code from a given byte array.static inthashCode(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 bytehexCharsToByte(char c1, char c2) private static inthexCharToNibble(char ch) static byte[]incrementBytes(byte[] value, long amount) Bytewise binary increment/deincrement of long contained in byte array on given amount.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.private static booleanisHexDigit(char c) static booleanisSorted(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 final intlen(byte[] b) Returns length of the byte array, returning 0 if the array is null.(package private) static Bytes.Comparer<byte[]>static IntegermapKey(byte[] b) Calculate a hash code from a given byte array suitable for use as a key in maps.static IntegermapKey(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 bytesstatic 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 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) Put a double value out to the specified byte array position as the IEEE 754 double format.static intputFloat(byte[] bytes, int offset, float f) Put a float value out to the specified byte array position.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) Deprecated.As of release 2.0.0, this will be removed in HBase 3.0.0.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) Deprecated.As of release 2.0.0, this will be removed in HBase 3.0.0.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) Deprecated.As of release 2.0.0, this will be removed in HBase 3.0.0.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 longreadAsVLong(byte[] buffer, int offset) Reads a zero-compressed encoded long from input buffer and returns it.static byte[]Read byte-array written with a WritableableUtils.vint prefix.static byte[]Read byte-array written with a WritableableUtils.vint prefix.private static byte[]readBytes(ByteBuffer buf) static StringreadStringFixedSize(DataInput in, int size) Reads a fixed-size field and interprets it as a string padded with zeros.static longreadVLong(byte[] buffer, int offset) Deprecated.since 0.98.12.static intsearchDelimiterIndex(byte[] b, int offset, int length, int delimiter) Find index of passed delimiter.static intsearchDelimiterIndexInReverse(byte[] b, int offset, int length, int delimiter) Find index of passed delimiter walking from end of buffer backwards.static voidsecureRandom(byte[] b) Fill given array with random bytes using a strong random number generator.static voidsecureRandom(byte[] b, int offset, int length) Fill given array with random bytes at the specified position using a strong random number generator.voidset(byte[] b) Use passed bytes as backing array for this instance.voidset(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 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) Make a new byte array from a subset of bytes at the tail of another.static byte[][]Convert a list of byte[] to an arraystatic 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 byte[][]toBinaryByteArrays(String[] t) Create an array of byte[] given an array of String.static 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) Create a byte[][] where first and only entry iscolumnstatic byte[][]toByteArrays(String column) Create a byte[][] where first and only entry iscolumnstatic byte[][]toByteArrays(String[] t) Create an array of byte[] given an array of String.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) 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 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) com.google.protobuf.ByteStringDeprecated.As of release 2.0.0, this will be removed in HBase 3.0.0.static doubletoDouble(byte[] bytes) Return double made from passed bytes.static doubletoDouble(byte[] bytes, int offset) Return double made from passed bytes.static floattoFloat(byte[] bytes) Put a float value out to the specified byte array position.static floattoFloat(byte[] bytes, int offset) Put a float value out to the specified byte array position.static StringtoHex(byte[] b) Convert a byte array into a hex stringstatic StringtoHex(byte[] b, int offset, int length) Convert a byte range 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) Deprecated.As of release 2.0.0, this will be removed in HBase 3.0.0.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) Deprecated.As of release 2.0.0, this will be removed in HBase 3.0.0.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) Deprecated.As of release 2.0.0, this will be removed in HBase 3.0.0.toString()static StringtoString(byte[] b) Convert a byte[] into a string.static StringtoString(byte[] b, int off) This method will convert utf8 encoded bytes into a string.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 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 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 byte[]vintToBytes(long vint) Encode a long value as a variable length integer.static intwriteByteArray(byte[] tgt, int tgtOffset, byte[] src, int srcOffset, int srcLength) Write byte-array from src to tgt with a vint length prefix.static voidwriteByteArray(DataOutput out, byte[] b) Write byte-array with a WritableableUtils.vint prefix.static voidwriteByteArray(DataOutput out, byte[] b, int offset, int length) Write byte-array to out with a vint length prefix.static voidwriteStringFixedSize(DataOutput out, String s, int size) Writes a string as a fixed-size field, padded with zeros.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
-
UTF8_CSN
-
EMPTY_BYTE_ARRAY
-
LOG
-
SIZEOF_BOOLEAN
Size of boolean in bytes- See Also:
-
SIZEOF_BYTE
Size of byte in bytes- See Also:
-
SIZEOF_CHAR
Size of char in bytes- See Also:
-
SIZEOF_DOUBLE
Size of double in bytes- See Also:
-
SIZEOF_FLOAT
Size of float in bytes- See Also:
-
SIZEOF_INT
Size of int in bytes- See Also:
-
SIZEOF_LONG
Size of long in bytes- See Also:
-
SIZEOF_SHORT
Size of short in bytes- See Also:
-
MASK_FOR_LOWER_INT_IN_LONG
Mask to apply to a long to reveal the lower int only. Use like this: int i = (int)(0xFFFFFFFF00000000L ^ some_long_value);- See Also:
-
ESTIMATED_HEAP_TAX
Estimate of size cost to pay beyond payload in jvm for instance of byte []. Estimate based on study of jhat and jprofiler numbers.- See Also:
-
UNSAFE_UNALIGNED
-
bytes
-
offset
-
length
-
BYTES_COMPARATOR
Pass this to TreeMaps where byte [] are keys. -
BYTES_RAWCOMPARATOR
Use comparing byte arrays, byte-by-byte -
HEX_CHARS_UPPER
-
RNG
-
SECURE_RNG
-
HEX_CHARS
-
-
Constructor Details
-
Bytes
public Bytes()Create a zero-size sequence. -
Bytes
Create a Bytes using the byte array as the initial value.- Parameters:
bytes- This array becomes the backing storage for the object.
-
Bytes
Set the new Bytes to the contents of the passedibw.- Parameters:
ibw- the value to set this Bytes to.
-
Bytes
Set the value to a given byte range- Parameters:
bytes- the new byte range to set tooffset- the offset in newData to start atlength- the number of bytes in the range
-
Bytes
Deprecated.As of release 2.0.0, this will be removed in HBase 3.0.0.Copy bytes from ByteString instance.- Parameters:
byteString- copy from
-
-
Method Details
-
len
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
-
get
Get the data from the Bytes.- Returns:
- The data is only valid between offset and offset+length.
-
set
Use passed bytes as backing array for this instance. -
set
Use passed bytes as backing array for this instance. -
getSize
Deprecated.since 2.0.0 and will be removed in 3.0.0. UsegetLength()instead.- Returns:
- the number of valid bytes in the buffer
- See Also:
-
getLength
Returns the number of valid bytes in the buffer -
getOffset
Return the offset into the buffer. -
toByteString
Deprecated.As of release 2.0.0, this will be removed in HBase 3.0.0. -
hashCode
-
compareTo
Define the sort order of the Bytes.- Specified by:
compareToin interfaceComparable<Bytes>- Parameters:
that- The other bytes writable- Returns:
- Positive if left is bigger than right, 0 if they are equal, and negative if left is smaller than right.
-
compareTo
Compares the bytes in this object to the specified byte array- Returns:
- Positive if left is bigger than right, 0 if they are equal, and negative if left is smaller than right.
-
equals
-
toString
-
toArray
Convert a list of byte[] to an array- Parameters:
array- List of byte [].- Returns:
- Array of byte [].
-
copyBytes
Returns a copy of the bytes referred to by this writable -
readByteArray
Read byte-array written with a WritableableUtils.vint prefix.- Parameters:
in- Input to read from.- Returns:
- byte array read off
in - Throws:
IOException- e
-
readByteArrayThrowsRuntime
Read byte-array written with a WritableableUtils.vint prefix. IOException is converted to a RuntimeException.- Parameters:
in- Input to read from.- Returns:
- byte array read off
in
-
writeByteArray
Write byte-array with a WritableableUtils.vint prefix.- Parameters:
out- output stream to be written tob- array to write- Throws:
IOException- e
-
writeByteArray
public static void writeByteArray(DataOutput out, byte[] b, int offset, int length) throws IOException Write byte-array to out with a vint length prefix.- Parameters:
out- output streamb- arrayoffset- offset into arraylength- length past offset- Throws:
IOException- e
-
writeByteArray
public 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.- Parameters:
tgt- target arraytgtOffset- offset into target arraysrc- source arraysrcOffset- source offsetsrcLength- source length- Returns:
- New offset in src array.
-
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
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:
-
readBytes
-
toString
Convert a byte[] into a string. Charset is assumed to be UTF-8.- 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 array- Returns:
- String made from
bor null
-
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
-
toStringBinary
Write a printable representation of a byte array.- Parameters:
b- byte array- 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:
-
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
-
isHexDigit
-
toBinaryFromHex
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
-
toBytes
Converts a string to a UTF-8 byte array.- Parameters:
s- string- Returns:
- the byte array
-
toBytes
Convert a boolean to a byte array. True becomes -1 and false becomes 0.- Parameters:
b- value- Returns:
bencoded in a byte array.
-
toBoolean
ReversestoBytes(boolean)- Parameters:
b- array- Returns:
- True or false.
-
toBytes
Convert a long value to a byte array using big-endian.- Parameters:
val- value to convert- Returns:
- the byte array
-
toLong
Converts a byte array to a long value. ReversestoBytes(long)- Parameters:
bytes- array- Returns:
- the long value
-
toLong
Converts a byte array to a long value. Assumes there will beSIZEOF_LONGbytes available.- Parameters:
bytes- bytesoffset- offset- Returns:
- the long value
-
toLong
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.
-
explainWrongLengthOrOffset
private static IllegalArgumentException explainWrongLengthOrOffset(byte[] bytes, int offset, int length, int expectedLength) -
putLong
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
Deprecated.As of release 2.0.0, this will be removed in HBase 3.0.0.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
Put a float value out to the specified byte array position. Presumes float encoded as IEEE 754 floating-point "single format"- Parameters:
bytes- byte array- Returns:
- Float made from passed byte array.
-
toFloat
Put a float value out to the specified byte array position. 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
Put a float value out to the specified byte array position.- Parameters:
bytes- byte arrayoffset- offset to write tof- float value- Returns:
- New offset in
bytes
-
toBytes
Return the float represented as byte[] -
toDouble
Return double made from passed bytes. -
toDouble
Return double made from passed bytes. -
putDouble
Put a double value out to the specified byte array position as the IEEE 754 double format.- Parameters:
bytes- byte arrayoffset- offset to write tod- value- Returns:
- New offset into array
bytes
-
toBytes
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
Convert an int value to a byte array. Big-endian. Same as what DataOutputStream.writeInt does.- Parameters:
val- value- Returns:
- the byte array
-
toInt
Converts a byte array to an int value- Parameters:
bytes- byte array- Returns:
- the int value
-
toInt
Converts a byte array to an int value- Parameters:
bytes- byte arrayoffset- offset into array- Returns:
- the int value
-
toInt
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
Deprecated.As of release 2.0.0, this will be removed in HBase 3.0.0.Converts a byte array to an int value (Unsafe version)- Parameters:
bytes- byte arrayoffset- offset into array- Returns:
- the int value
-
toShortUnsafe
Deprecated.As of release 2.0.0, this will be removed in HBase 3.0.0.Converts a byte array to an short value (Unsafe version)- Parameters:
bytes- byte arrayoffset- offset into array- Returns:
- the short value
-
toLongUnsafe
Deprecated.As of release 2.0.0, this will be removed in HBase 3.0.0.Converts a byte array to an long value (Unsafe version)- Parameters:
bytes- byte arrayoffset- offset into array- Returns:
- the long value
-
readAsInt
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
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
Deprecated.As of release 2.0.0, this will be removed in HBase 3.0.0.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
Convert a short value to a byte array ofSIZEOF_SHORTbytes long.- Parameters:
val- value- Returns:
- the byte array
-
toShort
Converts a byte array to a short value- Parameters:
bytes- byte array- Returns:
- the short value
-
toShort
Converts a byte array to a short value- Parameters:
bytes- byte arrayoffset- offset into array- Returns:
- the short value
-
toShort
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
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
Deprecated.As of release 2.0.0, this will be removed in HBase 3.0.0.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
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 -
toBigDecimal
Converts a byte array to a BigDecimal -
toBigDecimal
Converts a byte array to a BigDecimal 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
-
vintToBytes
Encode a long value as a variable length integer.- Parameters:
vint- Integer to make a vint of.- Returns:
- Vint as bytes array.
-
bytesToVint
Reads a zero-compressed encoded long from input buffer and returns it.- Parameters:
buffer- buffer to convert- Returns:
- vint bytes as an integer.
-
readVLong
Deprecated.since 0.98.12. UsereadAsVLong(byte[],int)instead.Reads a zero-compressed encoded long from input buffer and returns it.- Parameters:
buffer- Binary arrayoffset- Offset into array at which vint begins.- Returns:
- deserialized long from buffer.
- Throws:
IOException- e- See Also:
-
readAsVLong
Reads a zero-compressed encoded long from input buffer and returns it.- Parameters:
buffer- Binary arrayoffset- Offset into array at which vint begins.- Returns:
- deserialized long from buffer.
-
compareTo
Lexicographically compare two arrays.- 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.
-
lexicographicalComparerJavaImpl
-
equals
Lexicographically determine the equality of two arrays.- 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) Lexicographically determine the equality of two arrays.- Parameters:
left- left operandleftOffset- offset into left operandleftLen- length of left operandright- right operandrightOffset- offset into right operandrightLen- length of right operand- Returns:
- True if equal
-
equals
Lexicographically determine the equality of two byte[], one as ByteBuffer.- Parameters:
a- left operandbuf- right operand- Returns:
- True if equal
-
startsWith
Return true if the byte array on the right is a prefix of the byte array on the left. -
hashCode
Calculate a hash code from a given byte array.- Parameters:
b- bytes to hash- Returns:
- Runs
WritableComparator.hashBytes(byte[], int)on the passed in array. This method is whatTextuse calculating hash code.
-
hashCode
Calculate a hash code from a given byte array.- Parameters:
b- valuelength- length of the value- Returns:
- Runs
WritableComparator.hashBytes(byte[], int)on the passed in array. This method is whatTextuse calculating hash code.
-
mapKey
Calculate a hash code from a given byte array suitable for use as a key in maps.- Parameters:
b- bytes to hash- Returns:
- A hash of
bas an Integer that can be used as key in Maps.
-
mapKey
Calculate a hash code from a given byte array suitable for use as a key in maps.- Parameters:
b- bytes to hashlength- length to hash- Returns:
- A hash of
bas an Integer that can be used as key in Maps.
-
add
Concatenate byte arrays.- Parameters:
a- lower halfb- upper half- Returns:
- New array that has a in lower half and b in upper half.
-
add
Concatenate byte arrays.- Parameters:
a- first thirdb- second thirdc- third third- Returns:
- New array made from a, b and c
-
add
Concatenate byte arrays.- Parameters:
arrays- all the arrays to concatenate together.- Returns:
- New array made from the concatenation of the given arrays.
-
head
Make a new byte array from a subset of bytes at the head of another.- Parameters:
a- arraylength- amount of bytes to grab- Returns:
- First
lengthbytes froma
-
tail
Make a new byte array from a subset of bytes at the tail of another.- Parameters:
a- arraylength- amount of bytes to snarf- Returns:
- Last
lengthbytes froma
-
padHead
Make a new byte array from a subset of bytes at the head of another, zero padded as desired.- Parameters:
a- arraylength- new array size- Returns:
- Value in
apluslengthprepended 0 bytes
-
padTail
Make a new byte array from a subset of bytes at the tail of another, zero padded as desired.- Parameters:
a- arraylength- new array size- Returns:
- Value in
apluslengthappended 0 bytes
-
split
Split passed range. Expensive operation relatively. Uses BigInteger math. Useful splitting ranges for MapReduce jobs.- Parameters:
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.- Returns:
- Array of dividing values
-
split
Split passed range. Expensive operation relatively. Uses BigInteger math. Useful splitting ranges for MapReduce jobs.- Parameters:
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.- Returns:
- Array of dividing values
-
iterateOnSplits
Iterate over keys within the passed range, splitting at an [a,b) boundary. -
iterateOnSplits
Iterate over keys within the passed range. -
hashCode
Calculate the hash code for a given range of bytes.- Parameters:
bytes- array to hashoffset- offset to start fromlength- length to hash
-
toByteArrays
Create an array of byte[] given an array of String.- Parameters:
t- operands- Returns:
- Array of byte arrays made from passed array of Text
-
toBinaryByteArrays
Create an array of byte[] given an array of String.- Parameters:
t- operands- Returns:
- Array of binary byte arrays made from passed array of binary strings
-
toByteArrays
Create a byte[][] where first and only entry iscolumn- Parameters:
column- operand- Returns:
- A byte array of a byte array where first and only entry is
column
-
toByteArrays
Create a byte[][] where first and only entry iscolumn- Parameters:
column- operand- Returns:
- A byte array of a byte array where first and only entry is
column
-
binarySearch
@Deprecated public 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. UsebinarySearch(byte[][], byte[], int, int)instead.Binary search for keys in indexes.- Parameters:
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.- Returns:
- zero-based index of the key, if the key is present in the array. Otherwise, a value -(i + 1) such that the key is between arr[i - 1] and arr[i] non-inclusively, where i is in [0, i], if we define arr[-1] = -Inf and arr[N] = Inf for an N-element array. The above means that this function can return 2N + 1 different values ranging from -(N + 1) to N - 1.
- See Also:
-
binarySearch
Binary search for keys in indexes using Bytes.BYTES_RAWCOMPARATOR.- Parameters:
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- Returns:
- zero-based index of the key, if the key is present in the array. Otherwise, a value -(i + 1) such that the key is between arr[i - 1] and arr[i] non-inclusively, where i is in [0, i], if we define arr[-1] = -Inf and arr[N] = Inf for an N-element array. The above means that this function can return 2N + 1 different values ranging from -(N + 1) to N - 1.
-
binarySearch
@Deprecated public 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. UsebinarySearch(Cell[], Cell, CellComparator)instead.Binary search for keys in indexes.- Parameters:
arr- array of byte arrays to search forkey- the key you want to findcomparator- a comparator to compare.- Returns:
- zero-based index of the key, if the key is present in the array. Otherwise, a value -(i + 1) such that the key is between arr[i - 1] and arr[i] non-inclusively, where i is in [0, i], if we define arr[-1] = -Inf and arr[N] = Inf for an N-element array. The above means that this function can return 2N + 1 different values ranging from -(N + 1) to N - 1.
- See Also:
-
binarySearch
Binary search for keys in indexes.- Parameters:
arr- array of byte arrays to search forkey- the key you want to findcomparator- a comparator to compare.- Returns:
- zero-based index of the key, if the key is present in the array. Otherwise, a value -(i + 1) such that the key is between arr[i - 1] and arr[i] non-inclusively, where i is in [0, i], if we define arr[-1] = -Inf and arr[N] = Inf for an N-element array. The above means that this function can return 2N + 1 different values ranging from -(N + 1) to N - 1.
-
incrementBytes
Bytewise binary increment/deincrement of long contained in byte array on given amount.- Parameters:
value- - array of bytes containing long (length <= SIZEOF_LONG)amount- value will be incremented on (deincremented if negative)- Returns:
- array of bytes containing incremented long (length == SIZEOF_LONG)
-
binaryIncrementPos
-
binaryIncrementNeg
-
writeStringFixedSize
Writes a string as a fixed-size field, padded with zeros.- Throws:
IOException
-
readStringFixedSize
Reads a fixed-size field and interprets it as a string padded with zeros.- Throws:
IOException
-
copy
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
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 from- Returns:
- a copy of the given designated byte array
-
unsignedBinarySearch
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
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.
-
equals
-
isSorted
-
getUtf8ByteArrays
-
indexOf
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
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
Return true if target is present as an element anywhere in the given array.- Parameters:
array- an array ofbytevalues, possibly emptytarget- a primitivebytevalue- Returns:
trueiftargetis present as an element anywhere inarray.
-
contains
Return true if target is present as an element anywhere in the given array.- Parameters:
array- an array ofbytevalues, possibly emptytarget- an array ofbyte- Returns:
trueiftargetis present anywhere inarray
-
zero
Fill given array with zeros.- Parameters:
b- array which needs to be filled with zeros
-
zero
Fill given array with zeros at the specified position. -
random
Fill given array with random bytes.- Parameters:
b- array which needs to be filled with random bytesIf you want random bytes generated by a strong source of randomness use
secureRandom(byte[]).b- array which needs to be filled with random bytes
-
random
Fill given array with random bytes at the specified position.If you want random bytes generated by a strong source of randomness use
secureRandom(byte[], int, int).- Parameters:
b- array which needs to be filled with random bytesoffset- staring offset in arraylength- number of bytes to fill
-
secureRandom
Fill given array with random bytes using a strong random number generator.- Parameters:
b- array which needs to be filled with random bytes
-
secureRandom
Fill given array with random bytes at the specified position using a strong random number generator.- Parameters:
b- array which needs to be filled with random bytesoffset- staring offset in arraylength- number of bytes to fill
-
createMaxByteArray
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
Create a byte array which is multiple given bytes- Returns:
- byte array
-
toHex
Convert a byte range into a hex string -
toHex
Convert a byte array into a hex string -
hexCharToNibble
-
hexCharsToByte
-
fromHex
Create a byte array from a string of hash digits. The length of the string must be a multiple of 2 -
searchDelimiterIndex
Find index of passed delimiter.- Returns:
- Index of delimiter having started from start of
bmoving rightward.
-
searchDelimiterIndexInReverse
Find index of passed delimiter walking from end of buffer backwards.- Returns:
- Index of delimiter
-
findCommonPrefix
public static int findCommonPrefix(byte[] left, byte[] right, int leftLength, int rightLength, int leftOffset, int rightOffset)
-