Package org.apache.commons.io
Class EndianUtils
java.lang.Object
org.apache.commons.io.EndianUtils
Helps with different endian systems.
Different computer architectures adopt different conventions for byte ordering. In so-called "Little Endian" architectures (eg Intel), the low-order byte is stored in memory at the lowest address, and subsequent bytes at higher addresses. For "Big Endian" architectures (eg Motorola), the situation is reversed. This class helps you solve this incompatibility.
Provenance: Excalibur
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic doublereadSwappedDouble(byte[] data, int offset) Reads a "double" value from a byte array at a given offset.static doublereadSwappedDouble(InputStream input) Reads a "double" value from an InputStream.static floatreadSwappedFloat(byte[] data, int offset) Reads a "float" value from a byte array at a given offset.static floatreadSwappedFloat(InputStream input) Reads a "float" value from an InputStream.static intreadSwappedInteger(byte[] data, int offset) Reads an "int" value from a byte array at a given offset.static intreadSwappedInteger(InputStream input) Reads an "int" value from an InputStream.static longreadSwappedLong(byte[] data, int offset) Reads a "long" value from a byte array at a given offset.static longreadSwappedLong(InputStream input) Reads a "long" value from an InputStream.static shortreadSwappedShort(byte[] data, int offset) Reads a "short" value from a byte array at a given offset.static shortreadSwappedShort(InputStream input) Reads a "short" value from an InputStream.static longreadSwappedUnsignedInteger(byte[] data, int offset) Reads an unsigned integer (32-bit) value from a byte array at a given offset.static longReads an unsigned integer (32-bit) from an InputStream.static intreadSwappedUnsignedShort(byte[] data, int offset) Reads an unsigned short (16-bit) value from a byte array at a given offset.static intReads an unsigned short (16-bit) from an InputStream.static doubleswapDouble(double value) Converts a "double" value between endian systems.static floatswapFloat(float value) Converts a "float" value between endian systems.static intswapInteger(int value) Converts an "int" value between endian systems.static longswapLong(long value) Converts a "long" value between endian systems.static shortswapShort(short value) Converts a "short" value between endian systems.static voidwriteSwappedDouble(byte[] data, int offset, double value) Writes a "double" value to a byte array at a given offset.static voidwriteSwappedDouble(OutputStream output, double value) Writes a "double" value to an OutputStream.static voidwriteSwappedFloat(byte[] data, int offset, float value) Writes a "float" value to a byte array at a given offset.static voidwriteSwappedFloat(OutputStream output, float value) Writes a "float" value to an OutputStream.static voidwriteSwappedInteger(byte[] data, int offset, int value) Writes an "int" value to a byte array at a given offset.static voidwriteSwappedInteger(OutputStream output, int value) Writes an "int" value to an OutputStream.static voidwriteSwappedLong(byte[] data, int offset, long value) Writes a "long" value to a byte array at a given offset.static voidwriteSwappedLong(OutputStream output, long value) Writes a "long" value to an OutputStream.static voidwriteSwappedShort(byte[] data, int offset, short value) Writes a "short" value to a byte array at a given offset.static voidwriteSwappedShort(OutputStream output, short value) Writes a "short" value to an OutputStream.
-
Constructor Details
-
EndianUtils
public EndianUtils()Instances should NOT be constructed in standard programming.
-
-
Method Details
-
readSwappedDouble
Reads a "double" value from a byte array at a given offset. The value is converted to the opposed endian system while reading.- Parameters:
data- source byte arrayoffset- starting offset in the byte array- Returns:
- the value read
-
readSwappedDouble
Reads a "double" value from an InputStream. The value is converted to the opposed endian system while reading.- Parameters:
input- source InputStream- Returns:
- the value just read
- Throws:
IOException- in case of an I/O problem
-
readSwappedFloat
Reads a "float" value from a byte array at a given offset. The value is converted to the opposed endian system while reading.- Parameters:
data- source byte arrayoffset- starting offset in the byte array- Returns:
- the value read
-
readSwappedFloat
Reads a "float" value from an InputStream. The value is converted to the opposed endian system while reading.- Parameters:
input- source InputStream- Returns:
- the value just read
- Throws:
IOException- in case of an I/O problem
-
readSwappedInteger
Reads an "int" value from a byte array at a given offset. The value is converted to the opposed endian system while reading.- Parameters:
data- source byte arrayoffset- starting offset in the byte array- Returns:
- the value read
-
readSwappedInteger
Reads an "int" value from an InputStream. The value is converted to the opposed endian system while reading.- Parameters:
input- source InputStream- Returns:
- the value just read
- Throws:
IOException- in case of an I/O problem
-
readSwappedLong
Reads a "long" value from a byte array at a given offset. The value is converted to the opposed endian system while reading.- Parameters:
data- source byte arrayoffset- starting offset in the byte array- Returns:
- the value read
-
readSwappedLong
Reads a "long" value from an InputStream. The value is converted to the opposed endian system while reading.- Parameters:
input- source InputStream- Returns:
- the value just read
- Throws:
IOException- in case of an I/O problem
-
readSwappedShort
Reads a "short" value from a byte array at a given offset. The value is converted to the opposed endian system while reading.- Parameters:
data- source byte arrayoffset- starting offset in the byte array- Returns:
- the value read
-
readSwappedShort
Reads a "short" value from an InputStream. The value is converted to the opposed endian system while reading.- Parameters:
input- source InputStream- Returns:
- the value just read
- Throws:
IOException- in case of an I/O problem
-
readSwappedUnsignedInteger
Reads an unsigned integer (32-bit) value from a byte array at a given offset. The value is converted to the opposed endian system while reading.- Parameters:
data- source byte arrayoffset- starting offset in the byte array- Returns:
- the value read
-
readSwappedUnsignedInteger
Reads an unsigned integer (32-bit) from an InputStream. The value is converted to the opposed endian system while reading.- Parameters:
input- source InputStream- Returns:
- the value just read
- Throws:
IOException- in case of an I/O problem
-
readSwappedUnsignedShort
Reads an unsigned short (16-bit) value from a byte array at a given offset. The value is converted to the opposed endian system while reading.- Parameters:
data- source byte arrayoffset- starting offset in the byte array- Returns:
- the value read
-
readSwappedUnsignedShort
Reads an unsigned short (16-bit) from an InputStream. The value is converted to the opposed endian system while reading.- Parameters:
input- source InputStream- Returns:
- the value just read
- Throws:
IOException- in case of an I/O problem
-
swapDouble
Converts a "double" value between endian systems.- Parameters:
value- value to convert- Returns:
- the converted value
-
swapFloat
Converts a "float" value between endian systems.- Parameters:
value- value to convert- Returns:
- the converted value
-
swapInteger
Converts an "int" value between endian systems.- Parameters:
value- value to convert- Returns:
- the converted value
-
swapLong
Converts a "long" value between endian systems.- Parameters:
value- value to convert- Returns:
- the converted value
-
swapShort
Converts a "short" value between endian systems.- Parameters:
value- value to convert- Returns:
- the converted value
-
writeSwappedDouble
Writes a "double" value to a byte array at a given offset. The value is converted to the opposed endian system while writing.- Parameters:
data- target byte arrayoffset- starting offset in the byte arrayvalue- value to write
-
writeSwappedDouble
Writes a "double" value to an OutputStream. The value is converted to the opposed endian system while writing.- Parameters:
output- target OutputStreamvalue- value to write- Throws:
IOException- in case of an I/O problem
-
writeSwappedFloat
Writes a "float" value to a byte array at a given offset. The value is converted to the opposed endian system while writing.- Parameters:
data- target byte arrayoffset- starting offset in the byte arrayvalue- value to write
-
writeSwappedFloat
Writes a "float" value to an OutputStream. The value is converted to the opposed endian system while writing.- Parameters:
output- target OutputStreamvalue- value to write- Throws:
IOException- in case of an I/O problem
-
writeSwappedInteger
Writes an "int" value to a byte array at a given offset. The value is converted to the opposed endian system while writing.- Parameters:
data- target byte arrayoffset- starting offset in the byte arrayvalue- value to write
-
writeSwappedInteger
Writes an "int" value to an OutputStream. The value is converted to the opposed endian system while writing.- Parameters:
output- target OutputStreamvalue- value to write- Throws:
IOException- in case of an I/O problem
-
writeSwappedLong
Writes a "long" value to a byte array at a given offset. The value is converted to the opposed endian system while writing.- Parameters:
data- target byte arrayoffset- starting offset in the byte arrayvalue- value to write
-
writeSwappedLong
Writes a "long" value to an OutputStream. The value is converted to the opposed endian system while writing.- Parameters:
output- target OutputStreamvalue- value to write- Throws:
IOException- in case of an I/O problem
-
writeSwappedShort
Writes a "short" value to a byte array at a given offset. The value is converted to the opposed endian system while writing.- Parameters:
data- target byte arrayoffset- starting offset in the byte arrayvalue- value to write
-
writeSwappedShort
Writes a "short" value to an OutputStream. The value is converted to the opposed endian system while writing.- Parameters:
output- target OutputStreamvalue- value to write- Throws:
IOException- in case of an I/O problem
-