public class LittleEndian extends Object implements LittleEndianConsts
Modifier and Type | Class and Description |
---|---|
static class |
LittleEndian.BufferUnderrunException
Exception to handle buffer underruns
|
BYTE_SIZE, DOUBLE_SIZE, INT_SIZE, LONG_SIZE, SHORT_SIZE
Modifier and Type | Method and Description |
---|---|
static byte[] |
getByteArray(byte[] data,
int offset,
int size)
Copy a portion of a byte array
|
static double |
getDouble(byte[] data)
get a double value from a byte array, reads it in little endian format
then converts the resulting revolting IEEE 754 (curse them) floating
point number to a happy java double
|
static double |
getDouble(byte[] data,
int offset)
get a double value from a byte array, reads it in little endian format
then converts the resulting revolting IEEE 754 (curse them) floating
point number to a happy java double
|
static float |
getFloat(byte[] data)
get a float value from a byte array, reads it in little endian format
then converts the resulting revolting IEEE 754 (curse them) floating
point number to a happy java float
|
static float |
getFloat(byte[] data,
int offset)
get a float value from a byte array, reads it in little endian format
then converts the resulting revolting IEEE 754 (curse them) floating
point number to a happy java float
|
static int |
getInt(byte[] data)
get an int value from the beginning of a byte array
|
static int |
getInt(byte[] data,
int offset)
get an int value from a byte array
|
static long |
getLong(byte[] data)
get a long value from a byte array
|
static long |
getLong(byte[] data,
int offset)
get a long value from a byte array
|
static short |
getShort(byte[] data)
get a short value from the beginning of a byte array
|
static short |
getShort(byte[] data,
int offset)
get a short value from a byte array
|
static short[] |
getShortArray(byte[] data,
int offset,
int size)
Read short array
|
static short |
getUByte(byte[] data)
get the unsigned value of a byte.
|
static short |
getUByte(byte[] data,
int offset)
get the unsigned value of a byte.
|
static long |
getUInt(byte[] data)
get an unsigned int value from a byte array
|
static long |
getUInt(byte[] data,
int offset)
get an unsigned int value from a byte array
|
static int |
getUnsignedByte(byte[] data,
int offset)
Deprecated.
Use
getUByte(byte[], int) instead |
static int |
getUShort(byte[] data)
get an unsigned short value from the beginning of a byte array
|
static int |
getUShort(byte[] data,
int offset)
get an unsigned short value from a byte array
|
static void |
putByte(byte[] data,
int offset,
int value)
executes:
data[offset] = (byte)value;
|
static void |
putDouble(byte[] data,
int offset,
double value)
put a double value into a byte array
|
static void |
putDouble(double value,
OutputStream outputStream)
put a double value into a byte array
|
static void |
putFloat(byte[] data,
int offset,
float value)
put a float value into a byte array
|
static void |
putFloat(float value,
OutputStream outputStream)
put a float value into a byte array
|
static void |
putInt(byte[] data,
int value)
Deprecated.
Use
putInt(byte[], int, int) instead |
static void |
putInt(byte[] data,
int offset,
int value)
put an int value into a byte array
|
static void |
putInt(int value,
OutputStream outputStream)
Put int into output stream
|
static void |
putLong(byte[] data,
int offset,
long value)
put a long value into a byte array
|
static void |
putLong(long value,
OutputStream outputStream)
Put long into output stream
|
static void |
putShort(byte[] data,
int offset,
short value)
put a short value into a byte array
|
static void |
putShort(byte[] data,
short value)
Deprecated.
Use
putShort(byte[], int, short) instead |
static void |
putShort(OutputStream outputStream,
short value)
Put signed short into output stream
|
static void |
putShortArray(byte[] data,
int startOffset,
short[] value)
Stores short array in buffer
|
static void |
putUByte(byte[] data,
int offset,
short value)
put an unsigned byte value into a byte array
|
static void |
putUInt(byte[] data,
int offset,
long value)
put an unsigned int value into a byte array
|
static void |
putUInt(byte[] data,
long value)
Deprecated.
Use
putUInt(byte[], int, long) instead |
static void |
putUInt(long value,
OutputStream outputStream)
Put unsigned int into output stream
|
static void |
putUShort(byte[] data,
int offset,
int value)
put an unsigned short value into a byte array
|
static void |
putUShort(int value,
OutputStream outputStream)
Put unsigned short into output stream
|
static int |
readInt(InputStream stream)
get an int value from an InputStream
|
static long |
readLong(InputStream stream)
get a long value from an InputStream
|
static short |
readShort(InputStream stream)
get a short value from an InputStream
|
static long |
readUInt(InputStream stream)
get an unsigned int value from an InputStream
|
static int |
readUShort(InputStream stream) |
static int |
ubyteToInt(byte b)
Convert an 'unsigned' byte to an integer.
|
public static byte[] getByteArray(byte[] data, int offset, int size)
data
- the original byte arrayoffset
- Where to start copying from.size
- Number of bytes to copy.IndexOutOfBoundsException
- - if copying would cause access of data outside array bounds.public static double getDouble(byte[] data)
data
- the byte arraypublic static double getDouble(byte[] data, int offset)
data
- the byte arrayoffset
- a starting offset into the byte arraypublic static float getFloat(byte[] data)
data
- the byte arraypublic static float getFloat(byte[] data, int offset)
data
- the byte arrayoffset
- a starting offset into the byte arraypublic static int getInt(byte[] data)
data
- the byte arraypublic static int getInt(byte[] data, int offset)
data
- the byte arrayoffset
- a starting offset into the byte arraypublic static long getLong(byte[] data)
data
- the byte arraypublic static long getLong(byte[] data, int offset)
data
- the byte arrayoffset
- a starting offset into the byte arraypublic static short getShort(byte[] data)
data
- the byte arraypublic static short getShort(byte[] data, int offset)
data
- the byte arrayoffset
- a starting offset into the byte arraypublic static short[] getShortArray(byte[] data, int offset, int size)
data
- the original byte arrayoffset
- Where to start copying from.size
- Number of bytes to copy.IndexOutOfBoundsException
- - if read would cause access of data outside array bounds.public static short getUByte(byte[] data)
data
- the byte array.public static short getUByte(byte[] data, int offset)
data
- the byte array.offset
- a starting offset into the byte array.public static long getUInt(byte[] data)
data
- the byte arraypublic static long getUInt(byte[] data, int offset)
data
- the byte arrayoffset
- a starting offset into the byte array@Deprecated public static int getUnsignedByte(byte[] data, int offset)
getUByte(byte[], int)
insteaddata
- the byte array.offset
- a starting offset into the byte array.public static int getUShort(byte[] data)
data
- the byte arraypublic static int getUShort(byte[] data, int offset)
data
- the byte arrayoffset
- a starting offset into the byte arraypublic static void putByte(byte[] data, int offset, int value)
data[offset] = (byte)value;
Added for consistency with other put~() methodspublic static void putDouble(byte[] data, int offset, double value)
data
- the byte arrayoffset
- a starting offset into the byte arrayvalue
- the double (64-bit) valuepublic static void putDouble(double value, OutputStream outputStream) throws IOException
value
- the double (64-bit) valueoutputStream
- output streamIOException
- if an I/O error occurspublic static void putFloat(byte[] data, int offset, float value)
data
- the byte arrayoffset
- a starting offset into the byte arrayvalue
- the float (32-bit) valuepublic static void putFloat(float value, OutputStream outputStream) throws IOException
value
- the float (32-bit) valueoutputStream
- output streamIOException
- if an I/O error occurs@Deprecated public static void putInt(byte[] data, int value)
putInt(byte[], int, int)
insteaddata
- the byte arrayvalue
- the int (32-bit) valuepublic static void putInt(byte[] data, int offset, int value)
data
- the byte arrayoffset
- a starting offset into the byte arrayvalue
- the int (32-bit) valuepublic static void putInt(int value, OutputStream outputStream) throws IOException
value
- the int (32-bit) valueoutputStream
- output streamIOException
- if an I/O error occurspublic static void putLong(byte[] data, int offset, long value)
data
- the byte arrayoffset
- a starting offset into the byte arrayvalue
- the long (64-bit) valuepublic static void putLong(long value, OutputStream outputStream) throws IOException
value
- the long (64-bit) valueoutputStream
- output streamIOException
- if an I/O error occurspublic static void putShort(byte[] data, int offset, short value)
data
- the byte arrayoffset
- a starting offset into the byte arrayvalue
- the short (16-bit) value@Deprecated public static void putShort(byte[] data, short value)
putShort(byte[], int, short)
insteaddata
- the byte arrayvalue
- the short (16-bit) valuepublic static void putShort(OutputStream outputStream, short value) throws IOException
value
- the short (16-bit) valueoutputStream
- output streamIOException
- if an I/O error occurspublic static void putShortArray(byte[] data, int startOffset, short[] value)
data
- the byte arraystartOffset
- a starting offset into the byte arrayvalue
- the short (16-bit) valuespublic static void putUByte(byte[] data, int offset, short value)
data
- the byte arrayoffset
- a starting offset into the byte arrayvalue
- the short (16-bit) valueArrayIndexOutOfBoundsException
- may be thrownpublic static void putUInt(byte[] data, int offset, long value)
data
- the byte arrayoffset
- a starting offset into the byte arrayvalue
- the int (32-bit) valueArrayIndexOutOfBoundsException
- may be thrown@Deprecated public static void putUInt(byte[] data, long value)
putUInt(byte[], int, long)
insteaddata
- the byte arrayvalue
- the int (32-bit) valuepublic static void putUInt(long value, OutputStream outputStream) throws IOException
value
- the int (32-bit) valueoutputStream
- output streamIOException
- if an I/O error occurspublic static void putUShort(byte[] data, int offset, int value)
data
- the byte arrayoffset
- a starting offset into the byte arrayvalue
- the short (16-bit) valueArrayIndexOutOfBoundsException
- may be thrownpublic static void putUShort(int value, OutputStream outputStream) throws IOException
value
- the unsigned short (16-bit) valueoutputStream
- output streamIOException
- if an I/O error occurspublic static int readInt(InputStream stream) throws IOException, LittleEndian.BufferUnderrunException
stream
- the InputStream from which the int is to be readIOException
- will be propagated back to the callerLittleEndian.BufferUnderrunException
- if the stream cannot provide enough bytespublic static long readUInt(InputStream stream) throws IOException, LittleEndian.BufferUnderrunException
stream
- the InputStream from which the int is to be readIOException
- will be propagated back to the callerLittleEndian.BufferUnderrunException
- if the stream cannot provide enough bytespublic static long readLong(InputStream stream) throws IOException, LittleEndian.BufferUnderrunException
stream
- the InputStream from which the long is to be readIOException
- will be propagated back to the callerLittleEndian.BufferUnderrunException
- if the stream cannot provide enough bytespublic static short readShort(InputStream stream) throws IOException, LittleEndian.BufferUnderrunException
stream
- the InputStream from which the short is to be readIOException
- will be propagated back to the callerLittleEndian.BufferUnderrunException
- if the stream cannot provide enough bytespublic static int readUShort(InputStream stream) throws IOException, LittleEndian.BufferUnderrunException
public static int ubyteToInt(byte b)
b
- Description of the ParameterCopyright © 2020. All rights reserved.