org.apache.poi.util
public class LittleEndian extends java.lang.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,
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,
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 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)
get the unsigned value of a byte.
|
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 |
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 |
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 |
putUShort(byte[] data,
int offset,
int value)
put an unsigned short value into a byte array
|
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 |
readUShort(java.io.InputStream stream) |
static int |
ubyteToInt(byte b)
Convert an 'unsigned' byte to an integer.
|
public static short getShort(byte[] data, int offset)
data
- the byte arrayoffset
- a starting offset into the byte arraypublic static int getUShort(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 int getUShort(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 int getInt(byte[] data)
data
- the byte arraypublic static long getUInt(byte[] data, int offset)
data
- the byte arrayoffset
- a starting offset into the byte arraypublic static long getUInt(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 double getDouble(byte[] data, int offset)
data
- the byte arrayoffset
- a starting offset into the byte arraypublic static void putShort(byte[] data, int offset, short value)
data
- the byte arrayoffset
- a starting offset into the byte arrayvalue
- the short (16-bit) valuepublic static void putByte(byte[] data, int offset, int value)
data[offset] = (byte)value;
Added for consistency with other put~() methodspublic 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 putShort(byte[] data, short value)
data
- the byte arrayvalue
- the short (16-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(byte[] data, int value)
data
- the byte arrayvalue
- the int (32-bit) valuepublic 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 putDouble(byte[] data, int offset, double value)
data
- the byte arrayoffset
- a starting offset into the byte arrayvalue
- the double (64-bit) valuepublic 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 readUShort(java.io.InputStream stream) throws java.io.IOException, LittleEndian.BufferUnderrunException
java.io.IOException
LittleEndian.BufferUnderrunException
public 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 int ubyteToInt(byte b)
b
- Description of the Parameterpublic static int getUnsignedByte(byte[] data, int offset)
data
- the byte array.offset
- a starting offset into the byte array.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.java.lang.IndexOutOfBoundsException
- - if copying would cause access of
data outside array bounds.Copyright 2014 The Apache Software Foundation or its licensors, as applicable.