Package com.pixelmed.utils
Class ByteArray
java.lang.Object
com.pixelmed.utils.ByteArray
Various static methods helpful for manipulating arrays of bytes and extracting values from them.
-
Method Summary
Modifier and TypeMethodDescriptionstatic final int
bigEndianToUnsignedInt
(byte[] b) Extract an unsigned big endian integer from an entire byte array.static final int
bigEndianToUnsignedInt
(byte[] b, int offset, int length) Extract an unsigned big endian integer from a byte array.static final byte[]
concatenate
(byte[] src1, byte[] src2) Concatenate the entire contents of two byte arrays into a new byte array.static final byte[]
concatenate
(byte[] src1, int offset1, int length1, byte[] src2, int offset2, int length2) Concatenate portions of two byte arrays into a new byte array.static final byte[]
extractBytes
(byte[] src, int offset, int length) Extract a portion of a byte array into a new byte array.static final byte[]
intToBigEndianArray
(int value, int length) Extract an integer into a big endian byte array.static final byte[]
intToLittleEndianArray
(int value, int length) Extract an integer into a little endian byte array.static void
Testing.static final byte[]
static final void
swapEndianness
(byte[] src, int byteCount, int wordLength) Swap the byte order (endianness) of fixed length words within a byte array.
-
Method Details
-
readFully
- Throws:
IOException
-
bigEndianToUnsignedInt
public static final int bigEndianToUnsignedInt(byte[] b, int offset, int length) Extract an unsigned big endian integer from a byte array.
- Parameters:
b
- the byte array containing the big endian encoded integeroffset
- the offset of the start of the integer in the byte arraylength
- the number of bytes that the integer occupies in the byte array- Returns:
- the unsigned integer value
-
bigEndianToUnsignedInt
public static final int bigEndianToUnsignedInt(byte[] b) Extract an unsigned big endian integer from an entire byte array.
- Parameters:
b
- the byte array which is the big endian encoded integer- Returns:
- the unsigned integer value
-
intToBigEndianArray
public static final byte[] intToBigEndianArray(int value, int length) Extract an integer into a big endian byte array.
- Parameters:
value
- the integer valuelength
- the length of the byte array- Returns:
- the byte array which is the big endian encoded integer
-
intToLittleEndianArray
public static final byte[] intToLittleEndianArray(int value, int length) Extract an integer into a little endian byte array.
- Parameters:
value
- the integer valuelength
- the length of the byte array- Returns:
- the byte array which is the little endian encoded integer
-
extractBytes
public static final byte[] extractBytes(byte[] src, int offset, int length) Extract a portion of a byte array into a new byte array.
- Parameters:
src
- the source byte arrayoffset
- the offset of the bytes to be extractedlength
- the number of bytes to be extracted- Returns:
- a new byte array containing the extracted bytes
-
concatenate
public static final byte[] concatenate(byte[] src1, int offset1, int length1, byte[] src2, int offset2, int length2) Concatenate portions of two byte arrays into a new byte array.
- Parameters:
src1
- the first byte arrayoffset1
- the offset of the bytes to be extracted from the first byte arraylength1
- the number of bytes to be extracted from the first byte arraysrc2
- the second byte arrayoffset2
- the offset of the bytes to be extracted from the second byte arraylength2
- the number of bytes to be extracted from the second byte array- Returns:
- a new byte array containing the bytes extracted from the first array followed by the bytes extracted from the second array
-
concatenate
public static final byte[] concatenate(byte[] src1, byte[] src2) Concatenate the entire contents of two byte arrays into a new byte array.
- Parameters:
src1
- the first byte arraysrc2
- the second byte array- Returns:
- a new byte array containing the bytes extracted from the first array followed by the bytes extracted from the second array
-
swapEndianness
public static final void swapEndianness(byte[] src, int byteCount, int wordLength) Swap the byte order (endianness) of fixed length words within a byte array.
- Parameters:
src
- the byte array (swapped in place)byteCount
- the number of bytes in the array to swapwordLength
- the length in bytes of each word
-
main
Testing.
- Parameters:
arg
- ignored
-