|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.levigo.jadice.document.io.ByteUtils
public class ByteUtils
some helpful utils for byte handling
Constructor Summary | |
---|---|
ByteUtils()
|
Method Summary | |
---|---|
static byte[] |
doShortAlignment(byte[] source)
this method checks if the length of the passed byte[] is a multiple of 2. |
static boolean |
getBoolean(byte[] b,
int off)
reads out a boolean value of the given byte[] at the offset specified
in the second parameter. |
static char |
getCharBigEndian(byte[] b,
int off)
reads out a char value in the given byte[] at the offset specified in
the second parameter. |
static char |
getCharLittleEndian(byte[] b,
int off)
reads out a char value in the given byte[] at the offset specified in
the second parameter. |
static double |
getDouble(byte[] b,
int off)
reads out a double value in the given byte[] at the offset specified
in the second parameter. |
static float |
getFloat(byte[] b,
int off)
reads out a float value in the given byte[] at the offset specified
in the second parameter. |
static int |
getInt(byte[] b,
int off)
reads out a int value in the given byte[] at the offset specified in
the second parameter. |
static long |
getLong(byte[] b,
int off)
reads out a long value in the given byte[] at the offset specified in
the second parameter. |
static short |
getShort(byte[] b,
int off)
reads out a short value in the given byte[] at the offset specified
in the second parameter. |
static void |
putBoolean(byte[] b,
int off,
boolean val)
writes a boolean value to the given byte[] at the offset specified in
the second parameter. |
static void |
putChar(byte[] b,
int off,
char val)
writes a char value to the given byte[] at the offset specified in
the second parameter. |
static void |
putDouble(byte[] b,
int off,
double val)
writes a double value to the given byte[] at the offset specified in
the second parameter. |
static void |
putFloat(byte[] b,
int off,
float val)
writes a float value to the given byte[] at the offset specified in
the second parameter. |
static void |
putInt(byte[] b,
int off,
int val)
writes a int value to the given byte[] at the offset specified in the
second parameter. |
static void |
putLong(byte[] b,
int off,
long val)
writes a long value to the given byte[] at the offset specified in
the second parameter. |
static void |
putShort(byte[] b,
int off,
short val)
writes a short value to the given byte[] at the offset specified in
the second parameter. |
static int |
signedByteToUnsignedInt(byte val)
this method converts a signed byte to a unsigned int |
static long |
signedIntToUnsignedLong(int val)
this method converts a signed byte to a unsigned int |
static int |
signedShortToUnsignedInt(short val)
this method converts a signed byte to a unsigned int |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ByteUtils()
Method Detail |
---|
public static final int signedByteToUnsignedInt(byte val)
byte
to a unsigned int
val
- the byte
value whished to get converted to an unsigned int
int
public static final int signedShortToUnsignedInt(short val)
byte
to a unsigned int
val
- the byte
value whished to get converted to an unsigned int
int
public static final long signedIntToUnsignedLong(int val)
byte
to a unsigned int
val
- the byte
value whished to get converted to an unsigned int
int
public static final boolean getBoolean(byte[] b, int off)
boolean
value of the given byte[]
at the offset specified
in the second parameter. A boolean
value is being read as a single byte value
where any non zero value is being interpreted as true
b
- the byte[]
the value is being read outoff
- the offset in the byte[]
where to find the value
boolean
value at the given offset in the byte[]
ArrayIndexOutOfBoundsException
- if the specified offset is out of rangepublic static final char getCharBigEndian(byte[] b, int off)
char
value in the given byte[]
at the offset specified in
the second parameter. The char
will be read out using BigEndian byte ordering. A
char
is being read as a double byte value.
b
- the byte[]
the value is being read outoff
- the offset in the byte[]
where to find the value
char
value at the given offset in the byte[]
ArrayIndexOutOfBoundsException
- if the specified offset is out of rangepublic static final char getCharLittleEndian(byte[] b, int off)
char
value in the given byte[]
at the offset specified in
the second parameter. The char
will be read out using LittleEndian byte ordering.
A char
is being read as a double byte value.
b
- the byte[]
the value is being read outoff
- the offset in the byte[]
where to find the value
char
value at the given offset in the byte[]
ArrayIndexOutOfBoundsException
- if the specified offset is out of rangepublic static final short getShort(byte[] b, int off)
short
value in the given byte[]
at the offset specified
in the second parameter. The short
will be read out using BigEndian byte ordering.
A short
is being read as a double byte value.
b
- the byte[]
the value is being read outoff
- the offset in the byte[]
where to find the value
short
value at the given offset in the byte[]
ArrayIndexOutOfBoundsException
- if the specified offset and the length is out of
rangepublic static final int getInt(byte[] b, int off)
int
value in the given byte[]
at the offset specified in
the second parameter. The int
will be read out using BigEndian byte ordering. A
int
is being read as a four byte value.
b
- the byte[]
the value is being read outoff
- the offset in the byte[]
where to find the value
int
value at the given offset in the byte[]
ArrayIndexOutOfBoundsException
- if the specified offset and the length is out of
rangepublic static final float getFloat(byte[] b, int off)
float
value in the given byte[]
at the offset specified
in the second parameter. The float
will be read out using BigEndian byte ordering.
A float
is being read as a four byte value.
b
- the byte[]
the value is being read outoff
- the offset in the byte[]
where to find the value
float
value at the given offset in the byte[]
ArrayIndexOutOfBoundsException
- if the specified offset and the length is out of
rangepublic static final long getLong(byte[] b, int off)
long
value in the given byte[]
at the offset specified in
the second parameter. The long
will be read out using BigEndian byte ordering. A
long
is being read as a eight byte value.
b
- the byte[]
the value is being read outoff
- the offset in the byte[]
where to find the value
long
value at the given offset in the byte[]
ArrayIndexOutOfBoundsException
- if the specified offset and the length is out of
rangepublic static final double getDouble(byte[] b, int off)
double
value in the given byte[]
at the offset specified
in the second parameter. The double
will be read out using BigEndian byte
ordering. A double
is being read as a eight byte value.
b
- the byte[]
the value is being read outoff
- the offset in the byte[]
where to find the value
double
value at the given offset in the byte[]
ArrayIndexOutOfBoundsException
- if the specified offset and the length is out of
rangepublic static final void putBoolean(byte[] b, int off, boolean val)
boolean
value to the given byte[]
at the offset specified in
the second parameter. A boolean
value is being written as a single byte value.
b
- the byte[]
the value is being read outoff
- the offset in the byte[]
where to find the value
ArrayIndexOutOfBoundsException
- if the specified offset is out of rangepublic static final void putChar(byte[] b, int off, char val)
char
value to the given byte[]
at the offset specified in
the second parameter. The char
will be written using BigEndian byte ordering. A
char
is being written as a two byte value.
b
- the byte[]
the value is being written tooff
- the offset in the byte[]
where to write the valueval
- the value to be written
ArrayIndexOutOfBoundsException
- if the specified offset and the length is out of
rangepublic static final void putShort(byte[] b, int off, short val)
short
value to the given byte[]
at the offset specified in
the second parameter. The short
will be written using BigEndian byte ordering. A
short
is being written as a two byte value.
b
- the byte[]
the value is being written tooff
- the offset in the byte[]
where to write the valueval
- the value to be written
ArrayIndexOutOfBoundsException
- if the specified offset and the length is out of
rangepublic static final void putInt(byte[] b, int off, int val)
int
value to the given byte[]
at the offset specified in the
second parameter. The int
will be written using BigEndian byte ordering. A
int
is being written as a four byte value.
b
- the byte[]
the value is being written tooff
- the offset in the byte[]
where to write the valueval
- the value to be written
ArrayIndexOutOfBoundsException
- if the specified offset and the length is out of
rangepublic static final void putFloat(byte[] b, int off, float val)
float
value to the given byte[]
at the offset specified in
the second parameter. The float
will be written using BigEndian byte ordering. A
float
is being written as a four byte value.
b
- the byte[]
the value is being written tooff
- the offset in the byte[]
where to write the valueval
- the value to be written
ArrayIndexOutOfBoundsException
- if the specified offset and the length is out of
rangepublic static final void putLong(byte[] b, int off, long val)
long
value to the given byte[]
at the offset specified in
the second parameter. The long
will be written using BigEndian byte ordering. A
long
is being written as a eight byte value.
b
- the byte[]
the value is being written tooff
- the offset in the byte[]
where to write the valueval
- the value to be written
ArrayIndexOutOfBoundsException
- if the specified offset and the length is out of
rangepublic static final void putDouble(byte[] b, int off, double val)
double
value to the given byte[]
at the offset specified in
the second parameter. The double
will be written using BigEndian byte ordering. A
double
is being written as a eight byte value.
b
- the byte[]
the value is being written tooff
- the offset in the byte[]
where to write the valueval
- the value to be written
ArrayIndexOutOfBoundsException
- if the specified offset and the length is out of
rangepublic static final byte[] doShortAlignment(byte[] source)
byte[]
is a multiple of 2. If not
it will create a new byte[] copy the source data to the new, append 0
and return
the resulting byte[]
source
- the byte[]
to be short aligned
byte[]
which is short aligned
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |