public class EndianUtils
extends java.lang.Object
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.
Origin of code: Excalibur
SwappedDataInputStream
Constructor and Description |
---|
EndianUtils()
Instances should NOT be constructed in standard programming.
|
Modifier and Type | Method and Description |
---|---|
static double |
readSwappedDouble(byte[] data,
int offset)
Reads a "double" value from a byte array at a given offset.
|
static double |
readSwappedDouble(java.io.InputStream input)
Reads a "double" value from an InputStream.
|
static float |
readSwappedFloat(byte[] data,
int offset)
Reads a "float" value from a byte array at a given offset.
|
static float |
readSwappedFloat(java.io.InputStream input)
Reads a "float" value from an InputStream.
|
static int |
readSwappedInteger(byte[] data,
int offset)
Reads a "int" value from a byte array at a given offset.
|
static int |
readSwappedInteger(java.io.InputStream input)
Reads a "int" value from an InputStream.
|
static long |
readSwappedLong(byte[] data,
int offset)
Reads a "long" value from a byte array at a given offset.
|
static long |
readSwappedLong(java.io.InputStream input)
Reads a "long" value from an InputStream.
|
static short |
readSwappedShort(byte[] data,
int offset)
Reads a "short" value from a byte array at a given offset.
|
static short |
readSwappedShort(java.io.InputStream input)
Reads a "short" value from an InputStream.
|
static long |
readSwappedUnsignedInteger(byte[] data,
int offset)
Reads an unsigned integer (32-bit) value from a byte array at a given
offset.
|
static long |
readSwappedUnsignedInteger(java.io.InputStream input)
Reads a unsigned integer (32-bit) from an InputStream.
|
static int |
readSwappedUnsignedShort(byte[] data,
int offset)
Reads an unsigned short (16-bit) value from a byte array at a given
offset.
|
static int |
readSwappedUnsignedShort(java.io.InputStream input)
Reads a unsigned short (16-bit) from an InputStream.
|
static double |
swapDouble(double value)
Converts a "double" value between endian systems.
|
static float |
swapFloat(float value)
Converts a "float" value between endian systems.
|
static int |
swapInteger(int value)
Converts a "int" value between endian systems.
|
static long |
swapLong(long value)
Converts a "long" value between endian systems.
|
static short |
swapShort(short value)
Converts a "short" value between endian systems.
|
static void |
writeSwappedDouble(byte[] data,
int offset,
double value)
Writes a "double" value to a byte array at a given offset.
|
static void |
writeSwappedDouble(java.io.OutputStream output,
double value)
Writes a "double" value to an OutputStream.
|
static void |
writeSwappedFloat(byte[] data,
int offset,
float value)
Writes a "float" value to a byte array at a given offset.
|
static void |
writeSwappedFloat(java.io.OutputStream output,
float value)
Writes a "float" value to an OutputStream.
|
static void |
writeSwappedInteger(byte[] data,
int offset,
int value)
Writes a "int" value to a byte array at a given offset.
|
static void |
writeSwappedInteger(java.io.OutputStream output,
int value)
Writes a "int" value to an OutputStream.
|
static void |
writeSwappedLong(byte[] data,
int offset,
long value)
Writes a "long" value to a byte array at a given offset.
|
static void |
writeSwappedLong(java.io.OutputStream output,
long value)
Writes a "long" value to an OutputStream.
|
static void |
writeSwappedShort(byte[] data,
int offset,
short value)
Writes a "short" value to a byte array at a given offset.
|
static void |
writeSwappedShort(java.io.OutputStream output,
short value)
Writes a "short" value to an OutputStream.
|
public EndianUtils()
public static short swapShort(short value)
value
- value to convertpublic static int swapInteger(int value)
value
- value to convertpublic static long swapLong(long value)
value
- value to convertpublic static float swapFloat(float value)
value
- value to convertpublic static double swapDouble(double value)
value
- value to convertpublic static void writeSwappedShort(byte[] data, int offset, short value)
data
- target byte arrayoffset
- starting offset in the byte arrayvalue
- value to writepublic static short readSwappedShort(byte[] data, int offset)
data
- source byte arrayoffset
- starting offset in the byte arraypublic static int readSwappedUnsignedShort(byte[] data, int offset)
data
- source byte arrayoffset
- starting offset in the byte arraypublic static void writeSwappedInteger(byte[] data, int offset, int value)
data
- target byte arrayoffset
- starting offset in the byte arrayvalue
- value to writepublic static int readSwappedInteger(byte[] data, int offset)
data
- source byte arrayoffset
- starting offset in the byte arraypublic static long readSwappedUnsignedInteger(byte[] data, int offset)
data
- source byte arrayoffset
- starting offset in the byte arraypublic static void writeSwappedLong(byte[] data, int offset, long value)
data
- target byte arrayoffset
- starting offset in the byte arrayvalue
- value to writepublic static long readSwappedLong(byte[] data, int offset)
data
- source byte arrayoffset
- starting offset in the byte arraypublic static void writeSwappedFloat(byte[] data, int offset, float value)
data
- target byte arrayoffset
- starting offset in the byte arrayvalue
- value to writepublic static float readSwappedFloat(byte[] data, int offset)
data
- source byte arrayoffset
- starting offset in the byte arraypublic static void writeSwappedDouble(byte[] data, int offset, double value)
data
- target byte arrayoffset
- starting offset in the byte arrayvalue
- value to writepublic static double readSwappedDouble(byte[] data, int offset)
data
- source byte arrayoffset
- starting offset in the byte arraypublic static void writeSwappedShort(java.io.OutputStream output, short value) throws java.io.IOException
output
- target OutputStreamvalue
- value to writejava.io.IOException
- in case of an I/O problempublic static short readSwappedShort(java.io.InputStream input) throws java.io.IOException
input
- source InputStreamjava.io.IOException
- in case of an I/O problempublic static int readSwappedUnsignedShort(java.io.InputStream input) throws java.io.IOException
input
- source InputStreamjava.io.IOException
- in case of an I/O problempublic static void writeSwappedInteger(java.io.OutputStream output, int value) throws java.io.IOException
output
- target OutputStreamvalue
- value to writejava.io.IOException
- in case of an I/O problempublic static int readSwappedInteger(java.io.InputStream input) throws java.io.IOException
input
- source InputStreamjava.io.IOException
- in case of an I/O problempublic static long readSwappedUnsignedInteger(java.io.InputStream input) throws java.io.IOException
input
- source InputStreamjava.io.IOException
- in case of an I/O problempublic static void writeSwappedLong(java.io.OutputStream output, long value) throws java.io.IOException
output
- target OutputStreamvalue
- value to writejava.io.IOException
- in case of an I/O problempublic static long readSwappedLong(java.io.InputStream input) throws java.io.IOException
input
- source InputStreamjava.io.IOException
- in case of an I/O problempublic static void writeSwappedFloat(java.io.OutputStream output, float value) throws java.io.IOException
output
- target OutputStreamvalue
- value to writejava.io.IOException
- in case of an I/O problempublic static float readSwappedFloat(java.io.InputStream input) throws java.io.IOException
input
- source InputStreamjava.io.IOException
- in case of an I/O problempublic static void writeSwappedDouble(java.io.OutputStream output, double value) throws java.io.IOException
output
- target OutputStreamvalue
- value to writejava.io.IOException
- in case of an I/O problempublic static double readSwappedDouble(java.io.InputStream input) throws java.io.IOException
input
- source InputStreamjava.io.IOException
- in case of an I/O problem"Copyright © 2010 - 2020 Adobe Systems Incorporated. All Rights Reserved"