Package org.apache.openjpa.lib.util
Class Bytes
- java.lang.Object
-
- org.apache.openjpa.lib.util.Bytes
-
public final class Bytes extends Object
This class came from the Apache Commons Id sandbox project in support of the UUIDGenerator implementation.Static methods for managing byte arrays (all methods follow Big Endian order where most significant bits are in front).
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte[]append(byte[] a, byte[] b)Appends two bytes array into one.static booleanareEqual(byte[] a, byte[] b)Compares two byte arrays for equality.static intcompareTo(byte[] lhs, byte[] rhs)Compares two byte arrays as specified byComparable.static byte[]toBytes(long n)Returns a 8-byte array built from a long.static byte[]toBytes(long n, byte[] b)Build a 8-byte array from a long.static longtoLong(byte[] b)Build a long from first 8 bytes of the array.static shorttoShort(byte[] b)Build a short from first 2 bytes of the array.
-
-
-
Method Detail
-
append
public static byte[] append(byte[] a, byte[] b)Appends two bytes array into one.- Parameters:
a- A byte[].b- A byte[].- Returns:
- A byte[].
-
toBytes
public static byte[] toBytes(long n)
Returns a 8-byte array built from a long.- Parameters:
n- The number to convert.- Returns:
- A byte[].
-
toBytes
public static byte[] toBytes(long n, byte[] b)Build a 8-byte array from a long. No check is performed on the array length.- Parameters:
n- The number to convert.b- The array to fill.- Returns:
- A byte[].
-
toLong
public static long toLong(byte[] b)
Build a long from first 8 bytes of the array.- Parameters:
b- The byte[] to convert.- Returns:
- A long.
-
areEqual
public static boolean areEqual(byte[] a, byte[] b)Compares two byte arrays for equality.- Parameters:
a- A byte[].b- A byte[].- Returns:
- True if the arrays have identical contents.
-
compareTo
public static int compareTo(byte[] lhs, byte[] rhs)Compares two byte arrays as specified by
Comparable.- Parameters:
lhs- - left hand value in the comparison operation.rhs- - right hand value in the comparison operation.- Returns:
- a negative integer, zero, or a positive integer as
lhsis less than, equal to, or greater thanrhs.
-
toShort
public static short toShort(byte[] b)
Build a short from first 2 bytes of the array.- Parameters:
b- The byte[] to convert.- Returns:
- A short.
-
-