Package org.apache.datasketches.common
Class ByteArrayUtil
- java.lang.Object
-
- org.apache.datasketches.common.ByteArrayUtil
-
public final class ByteArrayUtil extends Object
Useful methods for byte arrays.- Author:
- Lee Rhodes
-
-
Constructor Summary
Constructors Constructor Description ByteArrayUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcopyBytes(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 doublegetDoubleBE(byte[] array, int offset)Get a double from the given byte array starting at the given offset in big endian order.static doublegetDoubleLE(byte[] array, int offset)Get a double from the given byte array starting at the given offset in little endian order.static floatgetFloatBE(byte[] array, int offset)Get a float from the given byte array starting at the given offset in big endian order.static floatgetFloatLE(byte[] array, int offset)Get a float from the given byte array starting at the given offset in little endian order.static intgetIntBE(byte[] array, int offset)Get a int from the given byte array starting at the given offset in big endian order.static intgetIntLE(byte[] array, int offset)Get a int from the given byte array starting at the given offset in little endian order.static longgetLongBE(byte[] array, int offset)Get a long from the source byte array starting at the given offset in big endian order.static longgetLongLE(byte[] array, int offset)Get a long from the given byte array starting at the given offset in little endian order.static shortgetShortBE(byte[] array, int offset)Get a short from the given byte array starting at the given offset in big endian order.static shortgetShortLE(byte[] array, int offset)Get a short from the given byte array starting at the given offset in little endian order.static voidputDoubleBE(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 voidputDoubleLE(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 voidputFloatBE(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 voidputFloatLE(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 voidputIntBE(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 voidputIntLE(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 voidputLongBE(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 voidputLongLE(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 voidputShortBE(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 voidputShortLE(byte[] array, int offset, short value)Put the source short into the destination byte array starting at the given offset in little endian order.
-
-
-
Method Detail
-
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
-
-