oemware.core.util
Class ByteNumberUtils

java.lang.Object
  extended by oemware.core.util.ByteNumberUtils
Direct Known Subclasses:
ByteUtils

public class ByteNumberUtils
extends java.lang.Object

The byte number utils. Most of these came from the Sun DNS classes. They were modified to work with our needs. The Java SDK source is released under GPL. You can download the Sun JDK source from http://java.sun.com.


Constructor Summary
ByteNumberUtils()
           
 
Method Summary
static byte[] createInt(int value)
          Returns a new byte array with the passed value.
static byte[] createIntB(int value)
          Returns a new byte array (big endian) with the value.
static byte[] createUInt(long value)
          Returns a new byte array with the passed value.
static int getInt(byte[] data, int pos)
          Returns the 4-byte signed value at msg[pos].
static long getLongL(byte[] data, int pos)
          Returns the eight byte long (little endian).
static int getUByte(byte[] data, int pos)
          Returns the 1-byte unsigned value at msg[pos].
static int getUInt(byte pValue)
          Returns an unsigned int for the byte passed.
static long getUInt(byte[] data, int pos)
          Returns the 4-byte unsigned value at msg[pos].
static int getUShort(byte[] data, int pos)
          Returns the 2-byte unsigned value at msg[pos].
static char getUShortChar(byte[] data, int pos)
          Returns the 2-byte unsigned char at the pos.
static void setIntB(byte[] data, int pos, int value)
          Set a int value in a byte array (big endian).
static void setLongL(byte[] data, int pos, long value)
          Set the 8-byte long (little endian).
static void setUInt(byte[] data, int pos, long value)
          Set the 4-byte unsigned short at the position.
static void setUShort(byte[] data, int pos, int value)
          Set the 2-byte unsigned short at the position.
static void setUShortChar(byte[] data, int pos, char value)
          Set the 2-byte unsigned short at the position.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ByteNumberUtils

public ByteNumberUtils()
Method Detail

getUShort

public static final int getUShort(byte[] data,
                                  int pos)
Returns the 2-byte unsigned value at msg[pos]. The high order byte comes first. This has a range of 0 - Short.MAX_VALUE.


getUShortChar

public static final char getUShortChar(byte[] data,
                                       int pos)
Returns the 2-byte unsigned char at the pos. This reads from 0 - Short.MAX_VALUE * 2.


setUShort

public static final void setUShort(byte[] data,
                                   int pos,
                                   int value)
Set the 2-byte unsigned short at the position.


setUShortChar

public static final void setUShortChar(byte[] data,
                                       int pos,
                                       char value)
Set the 2-byte unsigned short at the position.


getUInt

public static final int getUInt(byte pValue)
Returns an unsigned int for the byte passed.

Parameters:
pValue - The byte.
Returns:
The unsigned int.

createIntB

public static final byte[] createIntB(int value)
Returns a new byte array (big endian) with the value.

Parameters:
value - The int to convert.

createInt

public static final byte[] createInt(int value)
Returns a new byte array with the passed value.


createUInt

public static final byte[] createUInt(long value)
Returns a new byte array with the passed value.


getUByte

public static final int getUByte(byte[] data,
                                 int pos)
Returns the 1-byte unsigned value at msg[pos].


setUInt

public static final void setUInt(byte[] data,
                                 int pos,
                                 long value)
Set the 4-byte unsigned short at the position.


getInt

public static final int getInt(byte[] data,
                               int pos)
Returns the 4-byte signed value at msg[pos]. The high order byte comes first.


setIntB

public static void setIntB(byte[] data,
                           int pos,
                           int value)
Set a int value in a byte array (big endian).

Parameters:
data - The value.
pos - The position.
value - The value.

getUInt

public static final long getUInt(byte[] data,
                                 int pos)
Returns the 4-byte unsigned value at msg[pos]. The high order byte comes first.


setLongL

public static final void setLongL(byte[] data,
                                  int pos,
                                  long value)
Set the 8-byte long (little endian).


getLongL

public static final long getLongL(byte[] data,
                                  int pos)
Returns the eight byte long (little endian). This came from: java.nio.Bits.

Parameters:
data - The place to read from.
pos - The position in the data.
Returns:
The little endian long.


Copyright © 2009 Deft Labs - Released under LGPL, Version 3.0