Package org.apache.datasketches.common
Class ByteArrayUtil
java.lang.Object
org.apache.datasketches.common.ByteArrayUtil
Useful methods for byte arrays.
- Author:
- Lee Rhodes
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
copyBytes
(byte[] source, int srcStart, byte[] target, int tgtStart, int numBytes) Copies bytes from source to target with offsets on both the source and target.static double
getDoubleBE
(byte[] array, int offset) Get a double from the given byte array starting at the given offset in big endian order.static double
getDoubleLE
(byte[] array, int offset) Get a double from the given byte array starting at the given offset in little endian order.static float
getFloatBE
(byte[] array, int offset) Get a float from the given byte array starting at the given offset in big endian order.static float
getFloatLE
(byte[] array, int offset) Get a float from the given byte array starting at the given offset in little endian order.static int
getIntBE
(byte[] array, int offset) Get a int from the given byte array starting at the given offset in big endian order.static int
getIntLE
(byte[] array, int offset) Get a int from the given byte array starting at the given offset in little endian order.static long
getLongBE
(byte[] array, int offset) Get a long from the source byte array starting at the given offset in big endian order.static long
getLongLE
(byte[] array, int offset) Get a long from the given byte array starting at the given offset in little endian order.static short
getShortBE
(byte[] array, int offset) Get a short from the given byte array starting at the given offset in big endian order.static short
getShortLE
(byte[] array, int offset) Get a short from the given byte array starting at the given offset in little endian order.static void
putDoubleBE
(byte[] array, int offset, double value) Put the source double into the destination byte array starting at the given offset in big endian order.static void
putDoubleLE
(byte[] array, int offset, double value) Put the source double into the destination byte array starting at the given offset in little endian order.static void
putFloatBE
(byte[] array, int offset, float value) Put the source float into the destination byte array starting at the given offset in big endian order.static void
putFloatLE
(byte[] array, int offset, float value) Put the source float into the destination byte array starting at the given offset in little endian order.static void
putIntBE
(byte[] array, int offset, int value) Put the source int into the destination byte array starting at the given offset in big endian order.static void
putIntLE
(byte[] array, int offset, int value) Put the source int into the destination byte array starting at the given offset in little endian order.static void
putLongBE
(byte[] array, int offset, long value) Put the source long into the destination byte array starting at the given offset in big endian order.static void
putLongLE
(byte[] array, int offset, long value) Put the source long into the destination byte array starting at the given offset in little endian order.static void
putShortBE
(byte[] array, int offset, short value) Put the source short into the destination byte array starting at the given offset in big endian order.static void
putShortLE
(byte[] array, int offset, short value) Put the source short into the destination byte array starting at the given offset in little endian order.
-
Constructor Details
-
ByteArrayUtil
public ByteArrayUtil()
-
-
Method Details
-
copyBytes
public static void copyBytes(byte[] source, int srcStart, byte[] target, int tgtStart, int numBytes) Copies bytes from source to target with offsets on both the source and target.- Parameters:
source
- the given sourcesrcStart
- the source starting indextarget
- the give targettgtStart
- the target starting indexnumBytes
- the number of bytes to be transferred.
-
getShortLE
public static short getShortLE(byte[] array, int offset) Get a short from the given byte array starting at the given offset in little endian order. There is no bounds checking.- Parameters:
array
- source byte arrayoffset
- source offset- Returns:
- the short
-
putShortLE
public static void putShortLE(byte[] array, int offset, short value) Put the source short into the destination byte array starting at the given offset in little endian order. There is no bounds checking.- Parameters:
array
- destination byte arrayoffset
- destination offsetvalue
- source short
-
getShortBE
public static short getShortBE(byte[] array, int offset) Get a short from the given byte array starting at the given offset in big endian order. There is no bounds checking.- Parameters:
array
- source byte arrayoffset
- source offset- Returns:
- the short
-
putShortBE
public static void putShortBE(byte[] array, int offset, short value) Put the source short into the destination byte array starting at the given offset in big endian order. There is no bounds checking.- Parameters:
array
- destination byte arrayoffset
- destination offsetvalue
- source short
-
getIntLE
public static int getIntLE(byte[] array, int offset) Get a int from the given byte array starting at the given offset in little endian order. There is no bounds checking.- Parameters:
array
- source byte arrayoffset
- source offset- Returns:
- the int
-
putIntLE
public static void putIntLE(byte[] array, int offset, int value) Put the source int into the destination byte array starting at the given offset in little endian order. There is no bounds checking.- Parameters:
array
- destination byte arrayoffset
- destination offsetvalue
- source int
-
getIntBE
public static int getIntBE(byte[] array, int offset) Get a int from the given byte array starting at the given offset in big endian order. There is no bounds checking.- Parameters:
array
- source byte arrayoffset
- source offset- Returns:
- the int
-
putIntBE
public static void putIntBE(byte[] array, int offset, int value) Put the source int into the destination byte array starting at the given offset in big endian order. There is no bounds checking.- Parameters:
array
- destination byte arrayoffset
- destination offsetvalue
- source int
-
getLongLE
public static long getLongLE(byte[] array, int offset) Get a long from the given byte array starting at the given offset in little endian order. There is no bounds checking.- Parameters:
array
- source byte arrayoffset
- source offset- Returns:
- the long
-
putLongLE
public static void putLongLE(byte[] array, int offset, long value) Put the source long into the destination byte array starting at the given offset in little endian order. There is no bounds checking.- Parameters:
array
- destination byte arrayoffset
- destination offsetvalue
- source long
-
getLongBE
public static long getLongBE(byte[] array, int offset) Get a long from the source byte array starting at the given offset in big endian order. There is no bounds checking.- Parameters:
array
- source byte arrayoffset
- source starting point- Returns:
- the long
-
putLongBE
public static void putLongBE(byte[] array, int offset, long value) Put the source long into the destination byte array starting at the given offset in big endian order. There is no bounds checking.- Parameters:
array
- destination byte arrayoffset
- destination starting pointvalue
- source long
-
getFloatLE
public static float getFloatLE(byte[] array, int offset) Get a float from the given byte array starting at the given offset in little endian order. There is no bounds checking.- Parameters:
array
- source byte arrayoffset
- source offset- Returns:
- the float
-
putFloatLE
public static void putFloatLE(byte[] array, int offset, float value) Put the source float into the destination byte array starting at the given offset in little endian order. There is no bounds checking.- Parameters:
array
- destination byte arrayoffset
- destination offsetvalue
- source float
-
getFloatBE
public static float getFloatBE(byte[] array, int offset) Get a float from the given byte array starting at the given offset in big endian order. There is no bounds checking.- Parameters:
array
- source byte arrayoffset
- source offset- Returns:
- the float
-
putFloatBE
public static void putFloatBE(byte[] array, int offset, float value) Put the source float into the destination byte array starting at the given offset in big endian order. There is no bounds checking.- Parameters:
array
- destination byte arrayoffset
- destination offsetvalue
- source float
-
getDoubleLE
public static double getDoubleLE(byte[] array, int offset) Get a double from the given byte array starting at the given offset in little endian order. There is no bounds checking.- Parameters:
array
- source byte arrayoffset
- source offset- Returns:
- the double
-
putDoubleLE
public static void putDoubleLE(byte[] array, int offset, double value) Put the source double into the destination byte array starting at the given offset in little endian order. There is no bounds checking.- Parameters:
array
- destination byte arrayoffset
- destination offsetvalue
- source double
-
getDoubleBE
public static double getDoubleBE(byte[] array, int offset) Get a double from the given byte array starting at the given offset in big endian order. There is no bounds checking.- Parameters:
array
- source byte arrayoffset
- source offset- Returns:
- the double
-
putDoubleBE
public static void putDoubleBE(byte[] array, int offset, double value) Put the source double into the destination byte array starting at the given offset in big endian order. There is no bounds checking.- Parameters:
array
- destination byte arrayoffset
- destination offsetvalue
- source double
-