- All Implemented Interfaces:
Serializable
,Comparable<ByteUtils>
,Constable
Utility methods to do byte-level encoding. These methods are biased towards little-endian byte order because it is the most
common byte order and reading several bytes at once may be optimizable in the future with the help of sun.mist.Unsafe.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic double
readDoubleLE
(byte[] arr, int offset) Converts a byte array written in little endian format to a double.static float
readFloatLE
(byte[] arr, int offset) Converts a byte array written in little endian format to a float.static int
readIntBE
(byte[] arr, int offset) Converts a byte array written in big endian format to an int.static int
readIntLE
(byte[] arr, int offset) Converts a byte array written in little endian format to an int.static long
readLongBE
(byte[] arr, int offset) Converts a byte array written in big endian format to a long.static long
readLongLE
(byte[] arr, int offset) Converts a byte array written in little endian format to a long.static short
readShortBE
(byte[] arr, int offset) Converts a byte array written in big endian format to a short.static ByteUtils
Returns the enum constant of this class with the specified name.static ByteUtils[]
values()
Returns an array containing the constants of this enum class, in the order they are declared.static void
writeDoubleLE
(double val, byte[] arr, int offset) Converts a double to a byte array in little endian format.static void
writeFloatLE
(float val, byte[] arr, int offset) Converts a float to a byte array in little endian format.static void
writeIntBE
(int val, byte[] arr, int offset) Converts an int to a byte array in big endian format.static void
writeIntLE
(int val, byte[] arr, int offset) Converts an int to a byte array in little endian format.static void
writeLongBE
(long val, byte[] arr, int offset) Converts a long to a byte array in big endian format.static void
writeLongLE
(long val, byte[] arr, int offset) Converts a long to a byte array in little endian format.static void
writeShortBE
(short val, byte[] arr, int offset) Converts a short to a byte array in big endian format.static long
zigZagDecode
(long n) Zig-zag decode.static long
zigZagEncode
(long n) Zig-zag encode: this helps transforming small signed numbers into small positive numbers.
-
Field Details
-
LITTLE_ENDIAN_CHAR
-
LITTLE_ENDIAN_INT
-
LITTLE_ENDIAN_LONG
-
BIG_ENDIAN_LONG
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum class has no constant with the specified nameNullPointerException
- if the argument is null
-
zigZagDecode
public static long zigZagDecode(long n) Zig-zag decode. -
zigZagEncode
public static long zigZagEncode(long n) Zig-zag encode: this helps transforming small signed numbers into small positive numbers. -
writeLongLE
public static void writeLongLE(long val, byte[] arr, int offset) Converts a long to a byte array in little endian format.- Parameters:
val
- The long to convert to a byte arrayarr
- The byte array to write the long value in little endian layoutoffset
- The offset where in the array to write to
-
readLongLE
public static long readLongLE(byte[] arr, int offset) Converts a byte array written in little endian format to a long.- Parameters:
arr
- The byte array to read from in little endian layoutoffset
- The offset where in the array to read from
-
writeLongBE
public static void writeLongBE(long val, byte[] arr, int offset) Converts a long to a byte array in big endian format.- Parameters:
val
- The long to convert to a byte arrayarr
- The byte array to write the long value in big endian layoutoffset
- The offset where in the array to write to
-
readLongBE
public static long readLongBE(byte[] arr, int offset) Converts a byte array written in big endian format to a long.- Parameters:
arr
- The byte array to read from in big endian layoutoffset
- The offset where in the array to read from
-
writeIntLE
public static void writeIntLE(int val, byte[] arr, int offset) Converts an int to a byte array in little endian format.- Parameters:
val
- The int to convert to a byte arrayarr
- The byte array to write the int value in little endian layoutoffset
- The offset where in the array to write to
-
readIntLE
public static int readIntLE(byte[] arr, int offset) Converts a byte array written in little endian format to an int.- Parameters:
arr
- The byte array to read from in little endian layoutoffset
- The offset where in the array to read from
-
writeDoubleLE
public static void writeDoubleLE(double val, byte[] arr, int offset) Converts a double to a byte array in little endian format.- Parameters:
val
- The double to convert to a byte arrayarr
- The byte array to write the double value in little endian layoutoffset
- The offset where in the array to write to
-
readDoubleLE
public static double readDoubleLE(byte[] arr, int offset) Converts a byte array written in little endian format to a double.- Parameters:
arr
- The byte array to read from in little endian layoutoffset
- The offset where in the array to read from
-
writeFloatLE
public static void writeFloatLE(float val, byte[] arr, int offset) Converts a float to a byte array in little endian format.- Parameters:
val
- The float to convert to a byte arrayarr
- The byte array to write the float value in little endian layoutoffset
- The offset where in the array to write to
-
readFloatLE
public static float readFloatLE(byte[] arr, int offset) Converts a byte array written in little endian format to a float.- Parameters:
arr
- The byte array to read from in little endian layoutoffset
- The offset where in the array to read from
-
writeIntBE
public static void writeIntBE(int val, byte[] arr, int offset) Converts an int to a byte array in big endian format.- Parameters:
val
- The int to convert to a byte arrayarr
- The byte array to write the int value in big endian layoutoffset
- The offset where in the array to write to
-
readIntBE
public static int readIntBE(byte[] arr, int offset) Converts a byte array written in big endian format to an int.- Parameters:
arr
- The byte array to read from in big endian layoutoffset
- The offset where in the array to read from
-
writeShortBE
public static void writeShortBE(short val, byte[] arr, int offset) Converts a short to a byte array in big endian format.- Parameters:
val
- The short to convert to a byte arrayarr
- The byte array to write the short value in big endian layoutoffset
- The offset where in the array to write to
-
readShortBE
public static short readShortBE(byte[] arr, int offset) Converts a byte array written in big endian format to a short.- Parameters:
arr
- The byte array to read from in big endian layoutoffset
- The offset where in the array to read from
-