org.sakaiproject.metaobj.utils.id.guid
Class ByteOrder

java.lang.Object
  extended byorg.sakaiproject.metaobj.utils.id.guid.ByteOrder

public class ByteOrder
extends Object

Various static routines for solving endian problems.


Constructor Summary
ByteOrder()
           
 
Method Summary
static void int2leb(int x, byte[] buf, int offset)
          Int to little-endian bytes: writes x to buf[offset..]
static int leb2int(byte[] x, int offset)
          Little-endian bytes to int
static short leb2short(byte[] x, int offset)
          Little-endian bytes to short
static int long2int(long l)
          Returns the int value that is closest to l.
static byte[] reverse(byte[] x)
          Returns the reverse of x.
static void short2leb(short x, byte[] buf, int offset)
          Short to little-endian bytes: writes x to buf[offset...]
static int ubyte2int(byte x)
          Interprets the value of x as an unsigned byte, and returns it as integer.
static int ubytes2int(short x)
          Interprets the value of x as am unsigned two-byte number
static long ubytes2long(int x)
          Interprets the value of x as an unsigned two-byte number
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ByteOrder

public ByteOrder()
Method Detail

reverse

public static byte[] reverse(byte[] x)
Returns the reverse of x.


leb2short

public static short leb2short(byte[] x,
                              int offset)
Little-endian bytes to short


leb2int

public static int leb2int(byte[] x,
                          int offset)
Little-endian bytes to int


short2leb

public static void short2leb(short x,
                             byte[] buf,
                             int offset)
Short to little-endian bytes: writes x to buf[offset...]


int2leb

public static void int2leb(int x,
                           byte[] buf,
                           int offset)
Int to little-endian bytes: writes x to buf[offset..]


ubyte2int

public static int ubyte2int(byte x)
Interprets the value of x as an unsigned byte, and returns it as integer. For example, ubyte2int(0xFF)==255, not -1.


ubytes2int

public static int ubytes2int(short x)
Interprets the value of x as am unsigned two-byte number


ubytes2long

public static long ubytes2long(int x)
Interprets the value of x as an unsigned two-byte number


long2int

public static int long2int(long l)
Returns the int value that is closest to l. That is, if l can fit into a 32-bit unsigned number, returns (int)l. Otherwise, returns either Integer.MAX_VALUE or Integer.MIN_VALUE as appropriate.