edu.virginia.cs.mng.hypercast
Class ByteArrayUtility

java.lang.Object
  |
  +--edu.virginia.cs.mng.hypercast.ByteArrayUtility

public class ByteArrayUtility
extends java.lang.Object

This class contains some general functions for reading values from a byte array and for writing values to a byte array.


Constructor Summary
ByteArrayUtility()
           
 
Method Summary
static boolean isBytesZero(byte[] data, int start_index, int length)
          Checks out if a certain part of a byte array is all zero or not
static void setBytesZero(byte[] data, int start_index, int length)
          Sets a certain part of a byte array to all zeros
static byte[] toByteArray(int value)
          Converts an integer to a byte array
static byte[] toByteArray(long value)
          Converts a long to a byte array
static byte[] toByteArray(short value)
          Converts an short integer to a byte array
static int toInteger(byte[] data, int index)
          Converts a byte array to an integer
static long toLong(byte[] data, int index)
          Converts a byte array to a long integer
static short toShort(byte[] data, int index)
          Converts a byte array to a short integer
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Constructor Detail

ByteArrayUtility

public ByteArrayUtility()
Method Detail

toShort

public static short toShort(byte[] data,
                            int index)
Converts a byte array to a short integer
Parameters:
data - a byte array
index - a starting index in the array
Returns:
a short integer
Throws:
ArrayOutofBounds -  

toInteger

public static int toInteger(byte[] data,
                            int index)
Converts a byte array to an integer
Parameters:
data - a byte array
index - a starting index in the array
Returns:
an integer
Throws:
ArrayOutofBounds -  

toLong

public static long toLong(byte[] data,
                          int index)
Converts a byte array to a long integer
Parameters:
data - a byte array
index - a starting index in the array
Returns:
a long integer
Throws:
ArrayOutofBounds -  

toByteArray

public static byte[] toByteArray(short value)
Converts an short integer to a byte array
Parameters:
value - a short integer
Returns:
a byte array representing the short integer

toByteArray

public static byte[] toByteArray(int value)
Converts an integer to a byte array
Parameters:
value - an integer
Returns:
a byte array representing the integer

toByteArray

public static byte[] toByteArray(long value)
Converts a long to a byte array
Parameters:
longvalue - a long integer
Returns:
a byte array representing the long integer

isBytesZero

public static boolean isBytesZero(byte[] data,
                                  int start_index,
                                  int length)
Checks out if a certain part of a byte array is all zero or not
Parameters:
data - a byte array
start_index - the start position to check
length - the total length of bytes to be checked
Returns:
true, if all the bytes checked out to be all zero, false if not

setBytesZero

public static void setBytesZero(byte[] data,
                                int start_index,
                                int length)
Sets a certain part of a byte array to all zeros
Parameters:
data - a byte array
start_index - the start position to set
length - the total length of bytes to be set