|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.apache.poi.util.LittleEndian
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.
Inner Class Summary | |
static class |
LittleEndian.BufferUnderrunException
Exception to handle buffer underruns |
Fields inherited from interface org.apache.poi.util.LittleEndianConsts |
BYTE_SIZE, DOUBLE_SIZE, INT_SIZE, LONG_SIZE, SHORT_SIZE |
Method Summary | |
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 the beginning of a byte array |
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 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 the beginning of 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)
get a short array from a byte array. |
static short[] |
getSimpleShortArray(byte[] data,
int offset,
int size)
get a short array from a byte array. |
static int |
getUnsignedByte(byte[] data)
get the unsigned value of a byte. |
static int |
getUnsignedByte(byte[] data,
int offset)
get the unsigned value of a byte. |
static int |
getUShort(byte[] data,
int offset)
Retrieves and unsigned short. |
static void |
putDouble(byte[] data,
double value)
put a double value into beginning of a byte array |
static void |
putDouble(byte[] data,
int offset,
double value)
put a double value into a byte array |
static void |
putInt(byte[] data,
int value)
put an int value into beginning of a byte array |
static void |
putInt(byte[] data,
int offset,
int value)
put an int value into a byte array |
static void |
putLong(byte[] data,
int offset,
long value)
put a long value into a byte array |
static void |
putLong(byte[] data,
long value)
put a long value into beginning of a byte array |
static void |
putShort(byte[] data,
int offset,
short value)
put a short value into a byte array |
static void |
putShort(byte[] data,
short value)
put a short value into beginning of a byte array |
static void |
putShortArray(byte[] data,
int offset,
short[] value)
put a array of shorts into a byte array |
static void |
putUShort(byte[] data,
int offset,
int value)
put an unsigned short value into a byte array |
static byte[] |
readFromStream(java.io.InputStream stream,
int size)
Read the appropriate number of bytes from the stream and return them to the caller. |
static int |
readInt(java.io.InputStream stream)
get an int value from an InputStream |
static long |
readLong(java.io.InputStream stream)
get a long value from an InputStream |
static short |
readShort(java.io.InputStream stream)
get a short value from an InputStream |
static int |
ubyteToInt(byte b)
Convert an 'unsigned' byte to an integer. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
public static short getShort(byte[] data, int offset)
data
- the byte arrayoffset
- a starting offset into the byte arrayjava.lang.ArrayIndexOutOfBoundsException
- may be thrownpublic static short[] getSimpleShortArray(byte[] data, int offset, int size)
public static short[] getShortArray(byte[] data, int offset)
public static short getShort(byte[] data)
data
- the byte arrayjava.lang.ArrayIndexOutOfBoundsException
- may be thrownpublic static int getInt(byte[] data, int offset)
data
- the byte arrayoffset
- a starting offset into the byte arrayjava.lang.ArrayIndexOutOfBoundsException
- may be thrownpublic static int getInt(byte[] data)
data
- the byte arrayjava.lang.ArrayIndexOutOfBoundsException
- may be thrownpublic static long getLong(byte[] data, int offset)
data
- the byte arrayoffset
- a starting offset into the byte arrayjava.lang.ArrayIndexOutOfBoundsException
- may be thrownpublic static long getLong(byte[] data)
data
- the byte arrayjava.lang.ArrayIndexOutOfBoundsException
- may be thrownpublic static double getDouble(byte[] data, int offset)
data
- the byte arrayoffset
- a starting offset into the byte arrayjava.lang.ArrayIndexOutOfBoundsException
- may be thrownpublic static double getDouble(byte[] data)
data
- the byte arrayjava.lang.ArrayIndexOutOfBoundsException
- may be thrownpublic static void putShort(byte[] data, int offset, short value)
data
- the byte arrayoffset
- a starting offset into the byte arrayvalue
- the short (16-bit) valuejava.lang.ArrayIndexOutOfBoundsException
- may be thrownpublic static void putUShort(byte[] data, int offset, int value)
data
- the byte arrayoffset
- a starting offset into the byte arrayvalue
- the short (16-bit) valuejava.lang.ArrayIndexOutOfBoundsException
- may be thrownpublic static void putShortArray(byte[] data, int offset, short[] value)
data
- the byte arrayoffset
- a starting offset into the byte arrayvalue
- the short arrayjava.lang.ArrayIndexOutOfBoundsException
- may be thrownpublic static void putShort(byte[] data, short value)
data
- the byte arrayvalue
- the short (16-bit) valuejava.lang.ArrayIndexOutOfBoundsException
- may be thrownpublic static void putInt(byte[] data, int offset, int value)
data
- the byte arrayoffset
- a starting offset into the byte arrayvalue
- the int (32-bit) valuejava.lang.ArrayIndexOutOfBoundsException
- may be thrownpublic static void putInt(byte[] data, int value)
data
- the byte arrayvalue
- the int (32-bit) valuejava.lang.ArrayIndexOutOfBoundsException
- may be thrownpublic static void putLong(byte[] data, int offset, long value)
data
- the byte arrayoffset
- a starting offset into the byte arrayvalue
- the long (64-bit) valuejava.lang.ArrayIndexOutOfBoundsException
- may be thrownpublic static void putLong(byte[] data, long value)
data
- the byte arrayvalue
- the long (64-bit) valuejava.lang.ArrayIndexOutOfBoundsException
- may be thrownpublic static void putDouble(byte[] data, int offset, double value)
data
- the byte arrayoffset
- a starting offset into the byte arrayvalue
- the double (64-bit) valuejava.lang.ArrayIndexOutOfBoundsException
- may be thrownpublic static void putDouble(byte[] data, double value)
data
- the byte arrayvalue
- the double (64-bit) valuejava.lang.ArrayIndexOutOfBoundsException
- may be thrownpublic static short readShort(java.io.InputStream stream) throws java.io.IOException, LittleEndian.BufferUnderrunException
stream
- the InputStream from which the short is to be
readjava.io.IOException
- will be propagated back to the callerLittleEndian.BufferUnderrunException
- if the stream cannot provide
enough bytespublic static int readInt(java.io.InputStream stream) throws java.io.IOException, LittleEndian.BufferUnderrunException
stream
- the InputStream from which the int is to be readjava.io.IOException
- will be propagated back to the callerLittleEndian.BufferUnderrunException
- if the stream cannot provide
enough bytespublic static long readLong(java.io.InputStream stream) throws java.io.IOException, LittleEndian.BufferUnderrunException
stream
- the InputStream from which the long is to be readjava.io.IOException
- will be propagated back to the callerLittleEndian.BufferUnderrunException
- if the stream cannot provide
enough bytespublic static byte[] readFromStream(java.io.InputStream stream, int size) throws java.io.IOException, LittleEndian.BufferUnderrunException
It should be noted that, in an attempt to improve system performance and to prevent a transient explosion of discarded byte arrays to be garbage collected, static byte arrays are employed for the standard cases of reading a short, an int, or a long.
THIS INTRODUCES A RISK FOR THREADED OPERATIONS!
However, for the purposes of the POI project, this risk is deemed negligible. It is, however, so noted.
stream
- the InputStream we're reading fromsize
- the number of bytes to read; in 99.99% of cases,
this will be SHORT_SIZE, INT_SIZE, or LONG_SIZE --
but it doesn't have to be.java.io.IOException
- will be propagated back to the callerLittleEndian.BufferUnderrunException
- if the stream cannot provide
enough bytespublic static int ubyteToInt(byte b)
public static int getUnsignedByte(byte[] data, int offset)
data
- the byte array.offset
- a starting offset into the byte array.java.lang.ArrayIndexOutOfBoundsException
- may be thrownpublic static int getUnsignedByte(byte[] data)
data
- the byte arrayjava.lang.ArrayIndexOutOfBoundsException
- may be thrownpublic 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.java.lang.IndexOutOfBoundsException
- - if copying would cause access of data
outside array bounds.public static int getUShort(byte[] data, int offset)
data
- The data to readoffset
- The offset to read the short from
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |