com.inxar.syntacs.util
Class Pickler

java.lang.Object
  |
  +--com.inxar.syntacs.util.Pickler

public class Pickler
extends Object

The Pickler class contains static methods to transform int arrays into String objects and vice versa. Pickling is useful to decrease classfile size when one requires large static final int arrays. One the shortcomings of Java's design is that there is little bytecode support for array initialization. The classfile constant pool was not designed to store arbitrarily typed arrays. Therefore, each element in an array must be initialized expliclitly in bytecode upon compilation. The constant pool /is/ designed to store char arrays (Strings) however, so by converting an int array into a String, the compiler will put this in the constant pool, saving the need for all those extra bytecode instructions. Thus, when the class is initialized you can unpickle the String back into the array. All said and done, the classfile is not only /much/ smaller, the time needed to initialize the class decreases.


Method Summary
static char[] bin(int x, int bits)
           
static String pickle(int[] src)
          "Pickles" a 1-dimensional array of int to a String.
static String pickle(int[][] src)
          "Pickles" a 2-dimensional array of int to a String.
static String pickle(int[][][] src)
          "Pickles" a 3-dimensional array of int to a String.
static int[] unpickle1D(String src)
          "Unpickles" a String into a 1-dimensional array of int that was previously pickled.
static int[] unpickle1D(String[] src)
          "Unpickles" a String[] array into a 1-dimensional array of int that was previously pickled.
static int[][] unpickle2D(String src)
          "Unpickles" a String into a 2-dimensional array of int that was previously pickled.
static int[][] unpickle2D(String[] src)
          "Unpickles" a String[] array into a 2-dimensional array of int that was previously pickled.
static int[][][] unpickle3D(String src)
          "Unpickles" a String into a 3-dimensional array of int that was previously pickled.
static int[][][] unpickle3D(String[] src)
          "Unpickles" a String[] array into a 3-dimensional array of int that was previously pickled.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

pickle

public static String pickle(int[] src)
"Pickles" a 1-dimensional array of int to a String.
Parameters:
src - - The source array to be pickled.
Returns:
The source array pickled as a String. The original in array can be restored using the unpickle1D() method.

pickle

public static String pickle(int[][] src)
"Pickles" a 2-dimensional array of int to a String.
Parameters:
src - - The source array to be pickled.
Returns:
The source array pickled as a String. The original in array can be restored using the unpickle2D() method.

pickle

public static String pickle(int[][][] src)
"Pickles" a 3-dimensional array of int to a String.
Parameters:
src - - The source array to be pickled.
Returns:
The source array pickled as a String. The original in array can be restored using the unpickle3D() method.

unpickle1D

public static int[] unpickle1D(String src)
"Unpickles" a String into a 1-dimensional array of int that was previously pickled.
Parameters:
src - - The Pickle.
Returns:
The unpickled array.

unpickle1D

public static int[] unpickle1D(String[] src)
"Unpickles" a String[] array into a 1-dimensional array of int that was previously pickled. The elements in the array are concatenated to a single string. This method signature is provided to bypass the constant pool requirement that a string have a maximum length of 65535 chars.
Parameters:
src - - The Pickle, split into several contiguous parts in the array.
Returns:
The unpickled array.

unpickle2D

public static int[][] unpickle2D(String src)
"Unpickles" a String into a 2-dimensional array of int that was previously pickled.
Parameters:
src - - The Pickle.
Returns:
The unpickled array.

unpickle2D

public static int[][] unpickle2D(String[] src)
"Unpickles" a String[] array into a 2-dimensional array of int that was previously pickled. The elements in the array are concatenated to a single string. This method signature is provided to bypass the constant pool requirement that a string have a maximum length of 65535 chars.
Parameters:
src - - The Pickle, split into several contiguous parts in the array.
Returns:
The unpickled array.

unpickle3D

public static int[][][] unpickle3D(String src)
"Unpickles" a String into a 3-dimensional array of int that was previously pickled.
Parameters:
src - - The Pickle.
Returns:
The unpickled array.

unpickle3D

public static int[][][] unpickle3D(String[] src)
"Unpickles" a String[] array into a 3-dimensional array of int that was previously pickled. The elements in the array are concatenated to a single string. This method signature is provided to bypass the constant pool requirement that a string have a maximum length of 65535 chars.
Parameters:
src - - The Pickle, split into several contiguous parts in the array.
Returns:
The unpickled array.

bin

public static char[] bin(int x,
                         int bits)