Class ByteConversions
java.lang.Object
org.apache.commons.imaging.common.ByteConversions
Convenience methods for converting data types to and from byte arrays.
-
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]
static byte[]
static byte[]
static byte[]
static byte[]
static byte[]
static byte[]
Encodes an eight-byte (long) into an array of bytes based on the specified byte order.static byte[]
static byte[]
static byte[]
toBytes
(RationalNumber[] values, ByteOrder byteOrder) static byte[]
toBytes
(RationalNumber value, ByteOrder byteOrder) static double
static double[]
static float
static float[]
static int
static int
static int[]
static long
Extracts an eight-byte long integer from the specified byte array.static long[]
Extracts an array of eight-byte long integers from the specified array of bytes.static RationalNumber
toRational
(byte[] bytes, ByteOrder byteOrder, boolean unsignedType) Interprets the content of a specified bytes array to create an instance of the RationalNumber class.static RationalNumber[]
toRationals
(byte[] bytes, ByteOrder byteOrder, boolean unsignedType) static short
static short[]
static int
static int
static int[]
-
Method Details
-
toBytes
-
toBytes
-
toBytes
-
toBytes
-
toBytes
-
toBytes
-
toBytes
Encodes an eight-byte (long) into an array of bytes based on the specified byte order.- Parameters:
value
- a standard data primitive of type longbyteOrder
- the byte order to be used for encoding- Returns:
- an array of length 8
-
toBytes
-
toBytes
-
toBytes
-
toBytes
-
toDouble
-
toDoubles
-
toFloat
-
toFloats
-
toInt
-
toInt
-
toInts
-
toLong
Extracts an eight-byte long integer from the specified byte array. This method assumes that the byte array is of sufficiently large size to encode a long integer.- Parameters:
bytes
- an array of size at least 8byteOrder
- the byte-order for interpreting the input bytes- Returns:
- an eight-byte signed integer
-
toLongs
Extracts an array of eight-byte long integers from the specified array of bytes. The size of the result array is computed based on the size of the input byte array.- Parameters:
bytes
- a valid arraybyteOrder
- the byte-order for interpreting the input bytes- Returns:
- an array of zero or more eight-byte signed integers
-
toRational
Interprets the content of a specified bytes array to create an instance of the RationalNumber class.- Parameters:
bytes
- a valid array dimensioned to at least 8.byteOrder
- the byte order for integer conversionunsignedType
- indicates whether the extracted value is an unsigned type.- Returns:
- a valid instance
-
toRationals
-
toShort
-
toShorts
-
toUInt16
-
toUInt16
-
toUInt16s
-