Top Description Inners Constructors Methods
org.apache.poi.util

public final Class LittleEndian

extends Object
implements LittleEndianConsts
Class Inheritance
All Implemented Interfaces
org.apache.poi.util.LittleEndianConsts
Annotations
@Internal
Imports
java.io.IOException, .InputStream, .OutputStream, .Serializable

a utility class for handling little-endian numbers, which the 80x86 world is replete with. The methods are all static, and input/output is from/to byte arrays, or from InputStreams.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
LittleEndian.BufferUnderrunException

Exception to handle buffer underruns

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static double

Returns:

the double (64-bit) value
getDouble
(byte[]
the byte array
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

public static double

Returns:

the double (64-bit) value
getDouble
(byte[]
the byte array
data
,
int
a starting offset into the byte array
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

public static float

Returns:

the double (64-bit) value
getFloat
(byte[]
the byte array
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

public static float

Returns:

the double (64-bit) value
getFloat
(byte[]
the byte array
data
,
int
a starting offset into the byte array
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

public static int

Returns:

the int (32-bit) value
getInt
(byte[]
the byte array
data
)

get an int value from the beginning of a byte array

public static int

Returns:

the int (32-bit) value
getInt
(byte[]
the byte array
data
,
int
a starting offset into the byte array
offset
)

get an int value from a byte array

public static long

Returns:

the long (64-bit) value
getLong
(byte[]
the byte array
data
)

get a long value from a byte array

public static long

Returns:

the long (64-bit) value
getLong
(byte[]
the byte array
data
,
int
a starting offset into the byte array
offset
)

get a long value from a byte array

public static short

Returns:

the short (16-bit) value
getShort
(byte[]
the byte array
data
)

get a short value from the beginning of a byte array

public static short

Returns:

the short (16-bit) value
getShort
(byte[]
the byte array
data
,
int
a starting offset into the byte array
offset
)

get a short value from a byte array

public static short[]
getShortArray(byte[]
the original byte array
data
,
int
Where to start copying from.
offset
,
int
Number of bytes to copy.
size
)

Read short array

public static short

Returns:

the unsigned value of the byte as a 16 bit short
getUByte
(byte[]
the byte array.
data
)

get the unsigned value of a byte.

public static short

Returns:

the unsigned value of the byte as a 16 bit short
getUByte
(byte[]
the byte array.
data
,
int
a starting offset into the byte array.
offset
)

get the unsigned value of a byte.

public static long

Returns:

the unsigned int (32-bit) value in a long
getUInt
(byte[]
the byte array
data
)

get an unsigned int value from a byte array

public static long

Returns:

the unsigned int (32-bit) value in a long
getUInt
(byte[]
the byte array
data
,
int
a starting offset into the byte array
offset
)

get an unsigned int value from a byte array

public static int

Returns:

the unsigned short (16-bit) value in an int
getUShort
(byte[]
the byte array
data
)

get an unsigned short value from the beginning of a byte array

public static int

Returns:

the unsigned short (16-bit) value in an integer
getUShort
(byte[]
the byte array
data
,
int
a starting offset into the byte array
offset
)

get an unsigned short value from a byte array

public static void
putByte(byte[] data, int offset, int value)

executes:

data[offset] = (byte)value; Added for consistency with other put~() methods

public static void
putDouble(byte[]
the byte array
data
,
int
a starting offset into the byte array
offset
,
double
the double (64-bit) value
value
)

put a double value into a byte array

public static void
putDouble(double
the double (64-bit) value
value
,
OutputStream
output stream
outputStream
)

put a double value into a byte array

public static void
putFloat(byte[]
the byte array
data
,
int
a starting offset into the byte array
offset
,
float
the float (32-bit) value
value
)

put a float value into a byte array

public static void
putFloat(float
the float (32-bit) value
value
,
OutputStream
output stream
outputStream
)

put a float value into a byte array

public static void
putInt(byte[]
the byte array
data
,
int
a starting offset into the byte array
offset
,
int
the int (32-bit) value
value
)

put an int value into a byte array

public static void
putInt(int
the int (32-bit) value
value
,
OutputStream
output stream
outputStream
)

Put int into output stream

public static void
putLong(byte[]
the byte array
data
,
int
a starting offset into the byte array
offset
,
long
the long (64-bit) value
value
)

put a long value into a byte array

public static void
putLong(long
the long (64-bit) value
value
,
OutputStream
output stream
outputStream
)

Put long into output stream

public static void
putShort(byte[]
the byte array
data
,
int
a starting offset into the byte array
offset
,
short
the short (16-bit) value
value
)

put a short value into a byte array

public static void
putShort(OutputStream
output stream
outputStream
,
short
the short (16-bit) value
value
)

Put signed short into output stream

public static void
putShortArray(byte[]
the byte array
data
,
int
a starting offset into the byte array
startOffset
,
short[]
the short (16-bit) values
value
)

Stores short array in buffer

public static void
putUByte(byte[]
the byte array
data
,
int
a starting offset into the byte array
offset
,
short
the short (16-bit) value
value
)

put an unsigned byte value into a byte array

public static void
putUInt(byte[]
the byte array
data
,
int
a starting offset into the byte array
offset
,
long
the int (32-bit) value
value
)

put an unsigned int value into a byte array

public static void
putUInt(long
the int (32-bit) value
value
,
OutputStream
output stream
outputStream
)

Put unsigned int into output stream

public static void
putUShort(byte[]
the byte array
data
,
int
a starting offset into the byte array
offset
,
int
the short (16-bit) value
value
)

put an unsigned short value into a byte array

public static void
putUShort(int
the unsigned short (16-bit) value
value
,
OutputStream
output stream
outputStream
)

Put unsigned short into output stream

public static int

Returns:

the int (32-bit) value
readInt
(InputStream
the InputStream from which the int is to be read
stream
)

get an int value from an InputStream

public static long

Returns:

the long (64-bit) value
readLong
(InputStream
the InputStream from which the long is to be read
stream
)

get a long value from an InputStream

public static short

Returns:

the short (16-bit) value
readShort
(InputStream
the InputStream from which the short is to be read
stream
)

get a short value from an InputStream

public static long

Returns:

the unsigned int (32-bit) value
readUInt
(InputStream
the InputStream from which the int is to be read
stream
)

get an unsigned int value from an InputStream

public static int
public static int

Returns:

Description of the Return Value
ubyteToInt
(byte
Description of the Parameter
b
)

Convert an 'unsigned' byte to an integer.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

LittleEndianback to summary
private LittleEndian()

Method Detail

getDoubleback to summary
public 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

Parameters
data:byte[]

the byte array

Returns:double

the double (64-bit) value

getDoubleback to summary
public 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

Parameters
data:byte[]

the byte array

offset:int

a starting offset into the byte array

Returns:double

the double (64-bit) value

getFloatback to summary
public 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

Parameters
data:byte[]

the byte array

Returns:float

the double (64-bit) value

getFloatback to summary
public 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

Parameters
data:byte[]

the byte array

offset:int

a starting offset into the byte array

Returns:float

the double (64-bit) value

getIntback to summary
public static int getInt(byte[] data)

get an int value from the beginning of a byte array

Parameters
data:byte[]

the byte array

Returns:int

the int (32-bit) value

getIntback to summary
public static int getInt(byte[] data, int offset)

get an int value from a byte array

Parameters
data:byte[]

the byte array

offset:int

a starting offset into the byte array

Returns:int

the int (32-bit) value

getLongback to summary
public static long getLong(byte[] data)

get a long value from a byte array

Parameters
data:byte[]

the byte array

Returns:long

the long (64-bit) value

getLongback to summary
public static long getLong(byte[] data, int offset)

get a long value from a byte array

Parameters
data:byte[]

the byte array

offset:int

a starting offset into the byte array

Returns:long

the long (64-bit) value

getShortback to summary
public static short getShort(byte[] data)

get a short value from the beginning of a byte array

Parameters
data:byte[]

the byte array

Returns:short

the short (16-bit) value

getShortback to summary
public static short getShort(byte[] data, int offset)

get a short value from a byte array

Parameters
data:byte[]

the byte array

offset:int

a starting offset into the byte array

Returns:short

the short (16-bit) value

getShortArrayback to summary
public static short[] getShortArray(byte[] data, int offset, int size)

Read short array

Parameters
data:byte[]

the original byte array

offset:int

Where to start copying from.

size:int

Number of bytes to copy.

Exceptions
IndexOutOfBoundsException:
- if read would cause access of data outside array bounds.
getUByteback to summary
public static short getUByte(byte[] data)

get the unsigned value of a byte.

Parameters
data:byte[]

the byte array.

Returns:short

the unsigned value of the byte as a 16 bit short

getUByteback to summary
public static short getUByte(byte[] data, int offset)

get the unsigned value of a byte.

Parameters
data:byte[]

the byte array.

offset:int

a starting offset into the byte array.

Returns:short

the unsigned value of the byte as a 16 bit short

getUIntback to summary
public static long getUInt(byte[] data)

get an unsigned int value from a byte array

Parameters
data:byte[]

the byte array

Returns:long

the unsigned int (32-bit) value in a long

getUIntback to summary
public static long getUInt(byte[] data, int offset)

get an unsigned int value from a byte array

Parameters
data:byte[]

the byte array

offset:int

a starting offset into the byte array

Returns:long

the unsigned int (32-bit) value in a long

getUShortback to summary
public static int getUShort(byte[] data)

get an unsigned short value from the beginning of a byte array

Parameters
data:byte[]

the byte array

Returns:int

the unsigned short (16-bit) value in an int

getUShortback to summary
public static int getUShort(byte[] data, int offset)

get an unsigned short value from a byte array

Parameters
data:byte[]

the byte array

offset:int

a starting offset into the byte array

Returns:int

the unsigned short (16-bit) value in an integer

putByteback to summary
public static void putByte(byte[] data, int offset, int value)

executes:

data[offset] = (byte)value;

Added for consistency with other put~() methods
putDoubleback to summary
public static void putDouble(byte[] data, int offset, double value)

put a double value into a byte array

Parameters
data:byte[]

the byte array

offset:int

a starting offset into the byte array

value:double

the double (64-bit) value

putDoubleback to summary
public static void putDouble(double value, OutputStream outputStream) throws IOException

put a double value into a byte array

Parameters
value:double

the double (64-bit) value

outputStream:OutputStream

output stream

Exceptions
IOException:
if an I/O error occurs
putFloatback to summary
public static void putFloat(byte[] data, int offset, float value)

put a float value into a byte array

Parameters
data:byte[]

the byte array

offset:int

a starting offset into the byte array

value:float

the float (32-bit) value

putFloatback to summary
public static void putFloat(float value, OutputStream outputStream) throws IOException

put a float value into a byte array

Parameters
value:float

the float (32-bit) value

outputStream:OutputStream

output stream

Annotations
@SuppressWarnings:unused
Exceptions
IOException:
if an I/O error occurs
putIntback to summary
public static void putInt(byte[] data, int offset, int value)

put an int value into a byte array

Parameters
data:byte[]

the byte array

offset:int

a starting offset into the byte array

value:int

the int (32-bit) value

putIntback to summary
public static void putInt(int value, OutputStream outputStream) throws IOException

Put int into output stream

Parameters
value:int

the int (32-bit) value

outputStream:OutputStream

output stream

Exceptions
IOException:
if an I/O error occurs
putLongback to summary
public static void putLong(byte[] data, int offset, long value)

put a long value into a byte array

Parameters
data:byte[]

the byte array

offset:int

a starting offset into the byte array

value:long

the long (64-bit) value

putLongback to summary
public static void putLong(long value, OutputStream outputStream) throws IOException

Put long into output stream

Parameters
value:long

the long (64-bit) value

outputStream:OutputStream

output stream

Exceptions
IOException:
if an I/O error occurs
putShortback to summary
public static void putShort(byte[] data, int offset, short value)

put a short value into a byte array

Parameters
data:byte[]

the byte array

offset:int

a starting offset into the byte array

value:short

the short (16-bit) value

putShortback to summary
public static void putShort(OutputStream outputStream, short value) throws IOException

Put signed short into output stream

Parameters
outputStream:OutputStream

output stream

value:short

the short (16-bit) value

Exceptions
IOException:
if an I/O error occurs
putShortArrayback to summary
public static void putShortArray(byte[] data, int startOffset, short[] value)

Stores short array in buffer

Parameters
data:byte[]

the byte array

startOffset:int

a starting offset into the byte array

value:short[]

the short (16-bit) values

putUByteback to summary
public static void putUByte(byte[] data, int offset, short value)

put an unsigned byte value into a byte array

Parameters
data:byte[]

the byte array

offset:int

a starting offset into the byte array

value:short

the short (16-bit) value

Exceptions
ArrayIndexOutOfBoundsException:
may be thrown
putUIntback to summary
public static void putUInt(byte[] data, int offset, long value)

put an unsigned int value into a byte array

Parameters
data:byte[]

the byte array

offset:int

a starting offset into the byte array

value:long

the int (32-bit) value

Exceptions
ArrayIndexOutOfBoundsException:
may be thrown
putUIntback to summary
public static void putUInt(long value, OutputStream outputStream) throws IOException

Put unsigned int into output stream

Parameters
value:long

the int (32-bit) value

outputStream:OutputStream

output stream

Exceptions
IOException:
if an I/O error occurs
putUShortback to summary
public static void putUShort(byte[] data, int offset, int value)

put an unsigned short value into a byte array

Parameters
data:byte[]

the byte array

offset:int

a starting offset into the byte array

value:int

the short (16-bit) value

Exceptions
ArrayIndexOutOfBoundsException:
may be thrown
putUShortback to summary
public static void putUShort(int value, OutputStream outputStream) throws IOException

Put unsigned short into output stream

Parameters
value:int

the unsigned short (16-bit) value

outputStream:OutputStream

output stream

Exceptions
IOException:
if an I/O error occurs
readIntback to summary
public static int readInt(InputStream stream) throws IOException

get an int value from an InputStream

Parameters
stream:InputStream

the InputStream from which the int is to be read

Returns:int

the int (32-bit) value

Exceptions
IOException:
will be propagated back to the caller
BufferUnderrunException:
if the stream cannot provide enough bytes
readLongback to summary
public static long readLong(InputStream stream) throws IOException

get a long value from an InputStream

Parameters
stream:InputStream

the InputStream from which the long is to be read

Returns:long

the long (64-bit) value

Exceptions
IOException:
will be propagated back to the caller
BufferUnderrunException:
if the stream cannot provide enough bytes
readShortback to summary
public static short readShort(InputStream stream) throws IOException

get a short value from an InputStream

Parameters
stream:InputStream

the InputStream from which the short is to be read

Returns:short

the short (16-bit) value

Exceptions
IOException:
will be propagated back to the caller
BufferUnderrunException:
if the stream cannot provide enough bytes
readUIntback to summary
public static long readUInt(InputStream stream) throws IOException

get an unsigned int value from an InputStream

Parameters
stream:InputStream

the InputStream from which the int is to be read

Returns:long

the unsigned int (32-bit) value

Exceptions
IOException:
will be propagated back to the caller
BufferUnderrunException:
if the stream cannot provide enough bytes
readUShortback to summary
public static int readUShort(InputStream stream) throws IOException
ubyteToIntback to summary
public static int ubyteToInt(byte b)

Convert an 'unsigned' byte to an integer. ie, don't carry across the sign.

Parameters
b:byte

Description of the Parameter

Returns:int

Description of the Return Value

org.apache.poi.util back to summary

public final Class LittleEndian.BufferUnderrunException

extends IOException
Class Inheritance

Exception to handle buffer underruns

Field Summary

Modifier and TypeField and Description
private static final long

Constructor Summary

AccessConstructor and Description
pack-priv

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.io.IOException.serialVersionUID.

Serial version UID

See Also
Serializable

Constructor Detail

BufferUnderrunExceptionback to summary
pack-priv BufferUnderrunException()