public final class Bytes extends Object
Static methods for managing byte arrays (all methods follow Big Endian order where most significant bits are in front).
Modifier and Type | Method and Description |
---|---|
static byte[] |
append(byte[] a,
byte[] b)
Appends two bytes array into one.
|
static boolean |
areEqual(byte[] a,
byte[] b)
Compares two byte arrays for equality.
|
static int |
compareTo(byte[] lhs,
byte[] rhs)
Compares two byte arrays as specified by
Comparable . |
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 long |
toLong(byte[] b)
Build a long from first 8 bytes of the array.
|
static short |
toShort(byte[] b)
Build a short from first 2 bytes of the array.
|
public static byte[] append(byte[] a, byte[] b)
a
- A byte[].b
- A byte[].public static byte[] toBytes(long n)
n
- The number to convert.public static byte[] toBytes(long n, byte[] b)
n
- The number to convert.b
- The array to fill.public static long toLong(byte[] b)
b
- The byte[] to convert.public static boolean areEqual(byte[] a, byte[] b)
a
- A byte[].b
- A byte[].public static int compareTo(byte[] lhs, byte[] rhs)
Compares two byte arrays as specified by Comparable
.
lhs
- - left hand value in the comparison operation.rhs
- - right hand value in the comparison operation.lhs
is less than, equal to, or greater than
rhs
.public static short toShort(byte[] b)
b
- The byte[] to convert.Copyright © 2006–2018 Apache Software Foundation. All rights reserved.