com.levigo.jadice.document.io
Class ByteUtils

java.lang.Object
  extended by com.levigo.jadice.document.io.ByteUtils

public class ByteUtils
extends Object

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

ByteUtils

public ByteUtils()
Method Detail

signedByteToUnsignedInt

public static final int signedByteToUnsignedInt(byte val)
this method converts a signed byte to a unsigned int

Parameters:
val - the byte value whished to get converted to an unsigned int
Returns:
an unsigned int

signedShortToUnsignedInt

public static final int signedShortToUnsignedInt(short val)
this method converts a signed byte to a unsigned int

Parameters:
val - the byte value whished to get converted to an unsigned int
Returns:
an unsigned int

signedIntToUnsignedLong

public static final long signedIntToUnsignedLong(int val)
this method converts a signed byte to a unsigned int

Parameters:
val - the byte value whished to get converted to an unsigned int
Returns:
an unsigned int

getBoolean

public static final boolean getBoolean(byte[] b,
                                       int off)
reads out a 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

Parameters:
b - the byte[] the value is being read out
off - the offset in the byte[] where to find the value
Returns:
the boolean value at the given offset in the byte[]
Throws:
ArrayIndexOutOfBoundsException - if the specified offset is out of range

getCharBigEndian

public static final char getCharBigEndian(byte[] b,
                                          int off)
reads out a 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.
ByteOrdering: BigEndian (most significant value first)

Parameters:
b - the byte[] the value is being read out
off - the offset in the byte[] where to find the value
Returns:
the char value at the given offset in the byte[]
Throws:
ArrayIndexOutOfBoundsException - if the specified offset is out of range

getCharLittleEndian

public static final char getCharLittleEndian(byte[] b,
                                             int off)
reads out a 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.
ByteOrdering: LittleEndian (less significant value first)

Parameters:
b - the byte[] the value is being read out
off - the offset in the byte[] where to find the value
Returns:
the char value at the given offset in the byte[]
Throws:
ArrayIndexOutOfBoundsException - if the specified offset is out of range

getShort

public static final short getShort(byte[] b,
                                   int off)
reads out a 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.
ByteOrdering: BigEndian (most significant value first)

Parameters:
b - the byte[] the value is being read out
off - the offset in the byte[] where to find the value
Returns:
the short value at the given offset in the byte[]
Throws:
ArrayIndexOutOfBoundsException - if the specified offset and the length is out of range

getInt

public static final int getInt(byte[] b,
                               int off)
reads out a 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.
ByteOrdering: BigEndian (most significant value first)

Parameters:
b - the byte[] the value is being read out
off - the offset in the byte[] where to find the value
Returns:
the int value at the given offset in the byte[]
Throws:
ArrayIndexOutOfBoundsException - if the specified offset and the length is out of range

getFloat

public static final float getFloat(byte[] b,
                                   int off)
reads out a 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.
ByteOrdering: BigEndian (most significant value first)

Parameters:
b - the byte[] the value is being read out
off - the offset in the byte[] where to find the value
Returns:
the float value at the given offset in the byte[]
Throws:
ArrayIndexOutOfBoundsException - if the specified offset and the length is out of range

getLong

public static final long getLong(byte[] b,
                                 int off)
reads out a 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.
ByteOrdering: BigEndian (most significant value first)

Parameters:
b - the byte[] the value is being read out
off - the offset in the byte[] where to find the value
Returns:
the long value at the given offset in the byte[]
Throws:
ArrayIndexOutOfBoundsException - if the specified offset and the length is out of range

getDouble

public static final double getDouble(byte[] b,
                                     int off)
reads out a 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.
ByteOrdering: BigEndian (most significant value first)

Parameters:
b - the byte[] the value is being read out
off - the offset in the byte[] where to find the value
Returns:
the double value at the given offset in the byte[]
Throws:
ArrayIndexOutOfBoundsException - if the specified offset and the length is out of range

putBoolean

public static final void putBoolean(byte[] b,
                                    int off,
                                    boolean val)
writes a 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.

Parameters:
b - the byte[] the value is being read out
off - the offset in the byte[] where to find the value
Throws:
ArrayIndexOutOfBoundsException - if the specified offset is out of range

putChar

public static final void putChar(byte[] b,
                                 int off,
                                 char val)
writes a 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.
ByteOrdering: BigEndian (most significant value first)

Parameters:
b - the byte[] the value is being written to
off - the offset in the byte[] where to write the value
val - the value to be written
Throws:
ArrayIndexOutOfBoundsException - if the specified offset and the length is out of range

putShort

public static final void putShort(byte[] b,
                                  int off,
                                  short val)
writes a 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.
ByteOrdering: BigEndian (most significant value first)

Parameters:
b - the byte[] the value is being written to
off - the offset in the byte[] where to write the value
val - the value to be written
Throws:
ArrayIndexOutOfBoundsException - if the specified offset and the length is out of range

putInt

public static final void putInt(byte[] b,
                                int off,
                                int val)
writes a 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.
ByteOrdering: BigEndian (most significant value first)

Parameters:
b - the byte[] the value is being written to
off - the offset in the byte[] where to write the value
val - the value to be written
Throws:
ArrayIndexOutOfBoundsException - if the specified offset and the length is out of range

putFloat

public static final void putFloat(byte[] b,
                                  int off,
                                  float val)
writes a 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.
ByteOrdering: BigEndian (most significant value first)

Parameters:
b - the byte[] the value is being written to
off - the offset in the byte[] where to write the value
val - the value to be written
Throws:
ArrayIndexOutOfBoundsException - if the specified offset and the length is out of range

putLong

public static final void putLong(byte[] b,
                                 int off,
                                 long val)
writes a 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.
ByteOrdering: BigEndian (most significant value first)

Parameters:
b - the byte[] the value is being written to
off - the offset in the byte[] where to write the value
val - the value to be written
Throws:
ArrayIndexOutOfBoundsException - if the specified offset and the length is out of range

putDouble

public static final void putDouble(byte[] b,
                                   int off,
                                   double val)
writes a 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.
ByteOrdering: BigEndian (most significant value first)

Parameters:
b - the byte[] the value is being written to
off - the offset in the byte[] where to write the value
val - the value to be written
Throws:
ArrayIndexOutOfBoundsException - if the specified offset and the length is out of range

doShortAlignment

public static final byte[] doShortAlignment(byte[] source)
this method checks if the length of the passed 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[]

Parameters:
source - the byte[] to be short aligned
Returns:
a byte[] which is short aligned


Copyright © 1995-2020 levigo holding gmbh. All Rights Reserved.