jist.runtime
Class Pickle

java.lang.Object
  extended by jist.runtime.Pickle

final class Pickle
extends java.lang.Object

Support for pickling and unpickling common data objects.

Since:
JIST1.0
Version:
$Id: Pickle.java,v 1.10 2004/04/06 16:07:43 barr Exp $
Author:
Rimon Barr <barr+jist@cs.cornell.edu>

Constructor Summary
Pickle()
           
 
Method Summary
static java.net.InetAddress arrayToInetAddress(byte[] b, int offset)
          Reconstruct Internet address from bytes.
static int arrayToInteger(byte[] b, int offset)
          Reconstruct integer from bytes.
static java.lang.Object arrayToObject(byte[] b)
          Reconstruct object from bytes.
static java.lang.Object arrayToObject(byte[] b, int offset)
          Reconstruct object from bytes.
static short arrayToShort(byte[] b, int offset)
          Reconstruct short from bytes.
static java.lang.String arrayToString(byte[] b, int offset)
          Reconstruct string from bytes.
static int[] byteToIntArray(byte[] data)
          Convert unsigned bytes to ints.
static int[] byteToIntArray(byte[] data, int offset, int length)
          Convert unsigned bytes to ints.
static byte[] concat(byte[] b1, byte[] b2)
          Concatenate two byte arrays.
static java.util.Vector Enum2Vector(java.util.Enumeration e)
          Utility method to stuff an entire enumeration into a vector.
static void InetAddressToArray(java.net.InetAddress inet, byte[] b, int offset)
          Store Internet address as bytes.
static void integerToArray(int integer, byte[] b, int offset)
          Store integer as bytes.
static byte[] intToByteArray(int[] data)
          Convert ints into unsigned bytes.
static byte[] intToByteArray(int[] data, int offset, int length)
          Convert ints into unsigned bytes.
static byte[] objectToArray(java.lang.Object s)
          Store object as bytes.
static void printByteArrayNicely(byte[] a)
          Print a hex-dump of a byte-array to System standard output stream.
static void printByteArrayNicely(byte[] a, int offset, int length)
          Print a hex-dump of some portion of a byte-array to System standard output stream.
static void printlnByteArrayNicely(byte[] a)
          Print a hex-dump of a byte-array to System.out followed by a new line.
static void printlnByteArrayNicely(byte[] a, int offset, int length)
          Print a hex-dump of some portion of a byte-array to System.out followed by a new line.
static void shortToArray(short i, byte[] b, int offset)
          Store integer as bytes.
static byte[] stringToArray(java.lang.String s)
          Store string as bytes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Pickle

Pickle()
Method Detail

printByteArrayNicely

public static void printByteArrayNicely(byte[] a)
Print a hex-dump of a byte-array to System standard output stream.

Parameters:
a - array to print

printByteArrayNicely

public static void printByteArrayNicely(byte[] a,
                                        int offset,
                                        int length)
Print a hex-dump of some portion of a byte-array to System standard output stream.

Parameters:
a - array to print
offset - starting offset
length - number of bytes of print

printlnByteArrayNicely

public static void printlnByteArrayNicely(byte[] a)
Print a hex-dump of a byte-array to System.out followed by a new line.

Parameters:
a - array to print

printlnByteArrayNicely

public static void printlnByteArrayNicely(byte[] a,
                                          int offset,
                                          int length)
Print a hex-dump of some portion of a byte-array to System.out followed by a new line.

Parameters:
a - array to print
offset - starting offset
length - number of bytes of print

Enum2Vector

public static java.util.Vector Enum2Vector(java.util.Enumeration e)
Utility method to stuff an entire enumeration into a vector.

Parameters:
e - input enumeration
Returns:
vector containing all elements of enumeration

byteToIntArray

public static int[] byteToIntArray(byte[] data,
                                   int offset,
                                   int length)
Convert unsigned bytes to ints.

Parameters:
data - array of unsigned bytes
offset - location in array to begin conversion
length - number of bytes to convert
Returns:
unsigned byte array as int array

intToByteArray

public static byte[] intToByteArray(int[] data,
                                    int offset,
                                    int length)
Convert ints into unsigned bytes.

Parameters:
data - array of unsigned ints
offset - locationin array to begin conversion
length - number of bytes to convert
Returns:
array of ints as unsigned byte array

byteToIntArray

public static int[] byteToIntArray(byte[] data)
Convert unsigned bytes to ints.

Parameters:
data - array of unsigned bytes
Returns:
unsigned byte array as int array

intToByteArray

public static byte[] intToByteArray(int[] data)
Convert ints into unsigned bytes.

Parameters:
data - array of unsigned ints
Returns:
array of ints as unsigned byte array

concat

public static byte[] concat(byte[] b1,
                            byte[] b2)
Concatenate two byte arrays.

Parameters:
b1 - first byte array
b2 - second byte array
Returns:
concatenated byte array

integerToArray

public static void integerToArray(int integer,
                                  byte[] b,
                                  int offset)
Store integer as bytes.

Parameters:
integer - int to convert
b - destination byte array
offset - offset within array to store integer at (4 bytes)

arrayToInteger

public static int arrayToInteger(byte[] b,
                                 int offset)
Reconstruct integer from bytes.

Parameters:
b - byte array
offset - offset within array to read integer from (4 bytes)
Returns:
reconstructed integer

shortToArray

public static void shortToArray(short i,
                                byte[] b,
                                int offset)
Store integer as bytes.

Parameters:
i - short to convert
b - destination byte array
offset - offset within array to store short at (2 bytes)

arrayToShort

public static short arrayToShort(byte[] b,
                                 int offset)
Reconstruct short from bytes.

Parameters:
b - byte array
offset - offset within array to read short from (2 bytes)
Returns:
reconstructed short

InetAddressToArray

public static void InetAddressToArray(java.net.InetAddress inet,
                                      byte[] b,
                                      int offset)
Store Internet address as bytes.

Parameters:
inet - Internet address to convert
b - destination byte array
offset - offset within array to store address at (4 bytes)

arrayToInetAddress

public static java.net.InetAddress arrayToInetAddress(byte[] b,
                                                      int offset)
Reconstruct Internet address from bytes.

Parameters:
b - byte array
offset - offset within array to read address from (4 bytes)
Returns:
reconstructed Internet address

stringToArray

public static byte[] stringToArray(java.lang.String s)
Store string as bytes.

Parameters:
s - string to convert
Returns:
string as byte array

arrayToString

public static java.lang.String arrayToString(byte[] b,
                                             int offset)
Reconstruct string from bytes.

Parameters:
b - byte array
offset - offset within array to read string from (4 bytes + string)
Returns:
reconstructed string

objectToArray

public static byte[] objectToArray(java.lang.Object s)
Store object as bytes.

Parameters:
s - object to convert
Returns:
object as byte array

arrayToObject

public static java.lang.Object arrayToObject(byte[] b,
                                             int offset)
Reconstruct object from bytes.

Parameters:
b - byte array
offset - offset within array to read object from (4 bytes + object)
Returns:
reconstructed object

arrayToObject

public static java.lang.Object arrayToObject(byte[] b)
Reconstruct object from bytes.

Parameters:
b - byte array
Returns:
reconstructed object