org.openmali.vecmath2.util
Class SerializationUtils

java.lang.Object
  extended by org.openmali.vecmath2.util.SerializationUtils

public class SerializationUtils
extends java.lang.Object

The SerializationUtils provide static methods, that read/write float and int data to/from a byte array.


Constructor Summary
SerializationUtils()
           
 
Method Summary
static java.lang.Object loadObject(java.io.File file)
          Loads an Object.
static java.lang.Object loadObject(java.io.InputStream in)
          Loads an Object.
static java.lang.Object loadObject(java.lang.String filename)
          Loads an Object.
static boolean readBoolFromBuffer(int pos, byte[] buffer)
          Reads a boolean from one byte at the specified position of the byte array.
static void readBoolsFromBuffer(int pos, byte[] buffer, boolean[] out)
          Reads a boolean-array from one byte each at the specified position of the byte array.
static void readBoolsFromBuffer(int pos, byte[] buffer, boolean[] out, int start, int length)
          Reads a boolean-array from one byte each at the specified position of the byte array.
static double readDoubleFromBuffer(int pos, byte[] buffer)
          Reads a double from eight bytes at the specified position of the byte array.
static void readDoublesFromBuffer(int pos, byte[] buffer, double[] out)
          Reads a double-array from eight bytes each at the specified position of the byte array.
static void readDoublesFromBuffer(int pos, byte[] buffer, double[] out, int start, int length)
          Reads a double-array from eight bytes each at the specified position of the byte array.
static float readFloatFromBuffer(int pos, byte[] buffer)
          Reads a float from four bytes at the specified position of the byte array.
static void readFloatsFromBuffer(int pos, byte[] buffer, float[] out)
          Reads a float-array from four bytes each at the specified position of the byte array.
static void readFloatsFromBuffer(int pos, byte[] buffer, float[] out, int start, int length)
          Reads a float-array from four bytes each at the specified position of the byte array.
static int readIntFromBuffer(int pos, byte[] buffer)
          Reads an int from four bytes at the specified position of the byte array.
static void readIntsFromBuffer(int pos, byte[] buffer, int[] out)
          Reads an int-array from four bytes each at the specified position of the byte array.
static void readIntsFromBuffer(int pos, byte[] buffer, int[] out, int start, int length)
          Reads an int-array from four bytes each at the specified position of the byte array.
static long readLongFromBuffer(int pos, byte[] buffer)
          Reads an long from eight bytes at the specified position of the byte array.
static void readLongsFromBuffer(int pos, byte[] buffer, long[] out)
          Reads an long-array from eight bytes each at the specified position of the byte array.
static void readLongsFromBuffer(int pos, byte[] buffer, long[] out, int start, int length)
          Reads an long-array from eight bytes each at the specified position of the byte array.
static void saveObject(java.lang.Object object, java.io.File file)
          Stores a Serializable Object.
static void saveObject(java.lang.Object object, java.io.OutputStream out)
          Stores a Serializable Object.
static void saveObject(java.lang.Object object, java.lang.String filename)
          Stores a Serializable Object.
static void writeToBuffer(boolean[] bools, int pos, byte[] buffer)
          Writes a boolean-array as one byte each to the specified position of the byte array.
static void writeToBuffer(boolean[] bools, int start, int length, int pos, byte[] buffer)
          Writes a boolean-array as one byte each to the specified position of the byte array.
static void writeToBuffer(boolean b, int pos, byte[] buffer)
          Writes a boolean as one byte to the specified position of the byte array.
static void writeToBuffer(double[] doubles, int start, int length, int pos, byte[] buffer)
          Writes a double-array as four bytes each to the specified position of the byte array.
static void writeToBuffer(double d, int pos, byte[] buffer)
          Writes a double as eight bytes to the specified position of the byte array.
static void writeToBuffer(float[] floats, int pos, byte[] buffer)
          Writes an int-array as four bytes each to the specified position of the byte array.
static void writeToBuffer(float[] floats, int start, int length, int pos, byte[] buffer)
          Writes a float-array as four bytes each to the specified position of the byte array.
static void writeToBuffer(float f, int pos, byte[] buffer)
          Writes a float as four bytes to the specified position of the byte array.
static void writeToBuffer(int[] ints, int pos, byte[] buffer)
          Writes an int-array as four bytes each to the specified position of the byte array.
static void writeToBuffer(int[] ints, int start, int length, int pos, byte[] buffer)
          Writes an int-array as four bytes each to the specified position of the byte array.
static void writeToBuffer(int i, int pos, byte[] buffer)
          Writes an int as four bytes to the specified position of the byte array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SerializationUtils

public SerializationUtils()
Method Detail

writeToBuffer

public static final void writeToBuffer(int i,
                                       int pos,
                                       byte[] buffer)
Writes an int as four bytes to the specified position of the byte array.

Parameters:
i - the int to write
pos - the position to write to (and the succeeding three bytes)
buffer - the byte array to write to

writeToBuffer

public static final void writeToBuffer(int[] ints,
                                       int start,
                                       int length,
                                       int pos,
                                       byte[] buffer)
Writes an int-array as four bytes each to the specified position of the byte array.

Parameters:
ints - the int-array to write
start - the index of the first int to write
length - the number of ints to write
pos - the position to write to
buffer - the byte array to write to

writeToBuffer

public static final void writeToBuffer(int[] ints,
                                       int pos,
                                       byte[] buffer)
Writes an int-array as four bytes each to the specified position of the byte array.

Parameters:
ints - the int-array to write
pos - the position to write to
buffer - the byte array to write to

writeToBuffer

public static final void writeToBuffer(float f,
                                       int pos,
                                       byte[] buffer)
Writes a float as four bytes to the specified position of the byte array.

Parameters:
f - the float to write
pos - the position to write to (and the succeeding three bytes)
buffer - the byte array to write to

writeToBuffer

public static final void writeToBuffer(float[] floats,
                                       int start,
                                       int length,
                                       int pos,
                                       byte[] buffer)
Writes a float-array as four bytes each to the specified position of the byte array.

Parameters:
floats - the float-array to write
start - the index of the first float to write
length - the number of floats to write
pos - the position to write to
buffer - the byte array to write to

writeToBuffer

public static final void writeToBuffer(double d,
                                       int pos,
                                       byte[] buffer)
Writes a double as eight bytes to the specified position of the byte array.

Parameters:
d - the double to write
pos - the position to write to (and the succeeding three bytes)
buffer - the byte array to write to

writeToBuffer

public static final void writeToBuffer(double[] doubles,
                                       int start,
                                       int length,
                                       int pos,
                                       byte[] buffer)
Writes a double-array as four bytes each to the specified position of the byte array.

Parameters:
doubles - the double-array to write
start - the index of the first double to write
length - the number of doubles to write
pos - the position to write to
buffer - the byte array to write to

writeToBuffer

public static final void writeToBuffer(float[] floats,
                                       int pos,
                                       byte[] buffer)
Writes an int-array as four bytes each to the specified position of the byte array.

Parameters:
floats - the float-array to write
pos - the position to write to
buffer - the byte array to write to

writeToBuffer

public static final void writeToBuffer(boolean b,
                                       int pos,
                                       byte[] buffer)
Writes a boolean as one byte to the specified position of the byte array.

Parameters:
b - the boolean to write
pos - the position to write to
buffer - the byte array to write to

writeToBuffer

public static final void writeToBuffer(boolean[] bools,
                                       int start,
                                       int length,
                                       int pos,
                                       byte[] buffer)
Writes a boolean-array as one byte each to the specified position of the byte array.

Parameters:
bools - the boolean-array to write
start - the index of the first boolean to write
length - the number of booleans to write
pos - the position to write to
buffer - the byte array to write to

writeToBuffer

public static final void writeToBuffer(boolean[] bools,
                                       int pos,
                                       byte[] buffer)
Writes a boolean-array as one byte each to the specified position of the byte array.

Parameters:
bools - the boolean-array to write
pos - the position to write to
buffer - the byte array to write to

readIntFromBuffer

public static final int readIntFromBuffer(int pos,
                                          byte[] buffer)
Reads an int from four bytes at the specified position of the byte array.

Parameters:
pos - the position to start reading at
buffer - the byte array to read from
Returns:
the read int

readIntsFromBuffer

public static final void readIntsFromBuffer(int pos,
                                            byte[] buffer,
                                            int[] out,
                                            int start,
                                            int length)
Reads an int-array from four bytes each at the specified position of the byte array.

Parameters:
pos - the position to start reading at
buffer - the byte array to read from
out - the int-array to write values to
start - the index of the first int to read
length - the number of ints to read

readIntsFromBuffer

public static final void readIntsFromBuffer(int pos,
                                            byte[] buffer,
                                            int[] out)
Reads an int-array from four bytes each at the specified position of the byte array.

Parameters:
pos - the position to start reading at
buffer - the byte array to read from
out - the int-array to write values to

readLongFromBuffer

public static final long readLongFromBuffer(int pos,
                                            byte[] buffer)
Reads an long from eight bytes at the specified position of the byte array.

Parameters:
pos - the position to start reading at
buffer - the byte array to read from
Returns:
the read long

readLongsFromBuffer

public static final void readLongsFromBuffer(int pos,
                                             byte[] buffer,
                                             long[] out,
                                             int start,
                                             int length)
Reads an long-array from eight bytes each at the specified position of the byte array.

Parameters:
pos - the position to start reading at
buffer - the byte array to read from
out - the long-array to write values to
start - the index of the first long to read
length - the number of longs to read

readLongsFromBuffer

public static final void readLongsFromBuffer(int pos,
                                             byte[] buffer,
                                             long[] out)
Reads an long-array from eight bytes each at the specified position of the byte array.

Parameters:
pos - the position to start reading at
buffer - the byte array to read from
out - the long-array to write values to

readFloatFromBuffer

public static final float readFloatFromBuffer(int pos,
                                              byte[] buffer)
Reads a float from four bytes at the specified position of the byte array.

Parameters:
pos - the position to start reading at
buffer - the byte array to read from
Returns:
the read float

readFloatsFromBuffer

public static final void readFloatsFromBuffer(int pos,
                                              byte[] buffer,
                                              float[] out,
                                              int start,
                                              int length)
Reads a float-array from four bytes each at the specified position of the byte array.

Parameters:
pos - the position to start reading at
buffer - the byte array to read from
out - the float-array to write values to
start - the index of the first float to read
length - the number of floats to read

readFloatsFromBuffer

public static final void readFloatsFromBuffer(int pos,
                                              byte[] buffer,
                                              float[] out)
Reads a float-array from four bytes each at the specified position of the byte array.

Parameters:
pos - the position to start reading at
buffer - the byte array to read from
out - the float-array to write values to

readDoubleFromBuffer

public static final double readDoubleFromBuffer(int pos,
                                                byte[] buffer)
Reads a double from eight bytes at the specified position of the byte array.

Parameters:
pos - the position to start reading at
buffer - the byte array to read from
Returns:
the read double

readDoublesFromBuffer

public static final void readDoublesFromBuffer(int pos,
                                               byte[] buffer,
                                               double[] out,
                                               int start,
                                               int length)
Reads a double-array from eight bytes each at the specified position of the byte array.

Parameters:
pos - the position to start reading at
buffer - the byte array to read from
out - the double-array to write values to
start - the index of the first double to read
length - the number of doubles to read

readDoublesFromBuffer

public static final void readDoublesFromBuffer(int pos,
                                               byte[] buffer,
                                               double[] out)
Reads a double-array from eight bytes each at the specified position of the byte array.

Parameters:
pos - the position to start reading at
buffer - the byte array to read from
out - the double-array to write values to

readBoolFromBuffer

public static final boolean readBoolFromBuffer(int pos,
                                               byte[] buffer)
Reads a boolean from one byte at the specified position of the byte array.

Parameters:
pos - the position to start reading at
buffer - the byte array to read from
Returns:
the read boolean

readBoolsFromBuffer

public static final void readBoolsFromBuffer(int pos,
                                             byte[] buffer,
                                             boolean[] out,
                                             int start,
                                             int length)
Reads a boolean-array from one byte each at the specified position of the byte array.

Parameters:
pos - the position to start reading at
buffer - the byte array to read from
out - the boolean-array to write values to
start - the index of the first boolean to read
length - the number of booleans to read

readBoolsFromBuffer

public static final void readBoolsFromBuffer(int pos,
                                             byte[] buffer,
                                             boolean[] out)
Reads a boolean-array from one byte each at the specified position of the byte array.

Parameters:
pos - the position to start reading at
buffer - the byte array to read from
out - the boolean-array to write values to

saveObject

public static void saveObject(java.lang.Object object,
                              java.io.OutputStream out)
                       throws java.io.IOException
Stores a Serializable Object.

Parameters:
object -
out -
Throws:
java.io.IOException

saveObject

public static void saveObject(java.lang.Object object,
                              java.lang.String filename)
                       throws java.io.IOException
Stores a Serializable Object.

Parameters:
object -
filename -
Throws:
java.io.IOException

saveObject

public static void saveObject(java.lang.Object object,
                              java.io.File file)
                       throws java.io.IOException
Stores a Serializable Object.

Parameters:
object -
file -
Throws:
java.io.IOException

loadObject

public static java.lang.Object loadObject(java.io.InputStream in)
                                   throws java.io.IOException,
                                          java.lang.ClassNotFoundException
Loads an Object.

Parameters:
in -
Returns:
the object
Throws:
java.io.IOException
java.lang.ClassNotFoundException

loadObject

public static java.lang.Object loadObject(java.lang.String filename)
                                   throws java.io.IOException,
                                          java.lang.ClassNotFoundException
Loads an Object.

Parameters:
filename -
Returns:
the object
Throws:
java.io.IOException
java.lang.ClassNotFoundException

loadObject

public static java.lang.Object loadObject(java.io.File file)
                                   throws java.io.IOException,
                                          java.lang.ClassNotFoundException
Loads an Object.

Parameters:
file -
Returns:
the object
Throws:
java.io.IOException
java.lang.ClassNotFoundException