org.jppf.utils
Class SerializationUtils

java.lang.Object
  extended by org.jppf.utils.SerializationUtils

public final class SerializationUtils
extends Object

Utility methods for serializing and deserializing data

Author:
Laurent Cohen

Method Summary
static boolean readBoolean(byte[] data, int offset)
          Deserialize an int value from an array of bytes.
static char readChar(byte[] data, int offset)
          Deserialize an int value from an array of bytes.
static int readInt(byte[] data, int offset)
          Deserialize an int value from an array of bytes.
static int readInt(InputStream is)
          Deserialize an int value from a stream.
static int readInt(ReadableByteChannel channel)
          Read an integer value from a channel.
static long readLong(byte[] data, int offset)
          Deserialize an int value from an array of bytes.
static long readLong(InputStream is)
          Deserialize an int value from a stream.
static short readShort(byte[] data, int offset)
          Deserialize an int value from an array of bytes.
static byte[] writeBoolean(boolean value, byte[] data, int offset)
          Serialize an int value into an array of bytes.
static byte[] writeChar(char value, byte[] data, int offset)
          Serialize an int value into an array of bytes.
static byte[] writeInt(int value)
          Serialize an int value into an array of bytes.
static byte[] writeInt(int value, byte[] data, int offset)
          Serialize an int value into an array of bytes.
static void writeInt(int value, OutputStream os)
          Serialize an int value to a stream.
static void writeInt(WritableByteChannel channel, int value)
          Wrtie an integer value to a channel.
static byte[] writeLong(long value, byte[] data, int offset)
          Serialize a long value into an array of bytes.
static byte[] writeShort(short value, byte[] data, int offset)
          Serialize an int value into an array of bytes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

writeInt

public static byte[] writeInt(int value)
Serialize an int value into an array of bytes.

Parameters:
value - the int value to serialize.
Returns:
an array of bytes filled with the value's representation.

writeBoolean

public static byte[] writeBoolean(boolean value,
                                  byte[] data,
                                  int offset)
Serialize an int value into an array of bytes.

Parameters:
value - the int value to serialize.
data - the array of bytes into which to serialize the value.
offset - the position in the array of byte at which the serializatrion should start.
Returns:
an array of bytes filled with the value's representation, starting at the specified offset.

writeChar

public static byte[] writeChar(char value,
                               byte[] data,
                               int offset)
Serialize an int value into an array of bytes.

Parameters:
value - the int value to serialize.
data - the array of bytes into which to serialize the value.
offset - the position in the array of byte at which the serializatrion should start.
Returns:
an array of bytes filled with the value's representation, starting at the specified offset.

writeShort

public static byte[] writeShort(short value,
                                byte[] data,
                                int offset)
Serialize an int value into an array of bytes.

Parameters:
value - the int value to serialize.
data - the array of bytes into which to serialize the value.
offset - the position in the array of byte at which the serializatrion should start.
Returns:
an array of bytes filled with the value's representation, starting at the specified offset.

writeInt

public static byte[] writeInt(int value,
                              byte[] data,
                              int offset)
Serialize an int value into an array of bytes.

Parameters:
value - the int value to serialize.
data - the array of bytes into which to serialize the value.
offset - the position in the array of byte at which the serializatrion should start.
Returns:
an array of bytes filled with the value's representation, starting at the specified offset.

writeLong

public static byte[] writeLong(long value,
                               byte[] data,
                               int offset)
Serialize a long value into an array of bytes.

Parameters:
value - the int value to serialize.
data - the array of bytes into which to serialize the value.
offset - the position in the array of byte at which the serializatrion should start.
Returns:
an array of bytes filled with the value's representation, starting at the specified offset.

writeInt

public static void writeInt(int value,
                            OutputStream os)
                     throws IOException
Serialize an int value to a stream.

Parameters:
value - the int value to serialize.
os - the stream to write to.
Throws:
IOException - if an error occurs while writing the data.

writeInt

public static void writeInt(WritableByteChannel channel,
                            int value)
                     throws IOException
Wrtie an integer value to a channel.

Parameters:
channel - the channel to write to.
value - the value to write.
Throws:
IOException - if an error occurs while writing the data.

readInt

public static int readInt(ReadableByteChannel channel)
                   throws IOException
Read an integer value from a channel.

Parameters:
channel - the channel to read from.
Returns:
the value read from the channel.
Throws:
IOException - if an error occurs while reading the data.

readBoolean

public static boolean readBoolean(byte[] data,
                                  int offset)
Deserialize an int value from an array of bytes.

Parameters:
data - the array of bytes into which to serialize the value.
offset - the position in the array of byte at which the serializatrion should start.
Returns:
the int value read from the array of bytes

readChar

public static char readChar(byte[] data,
                            int offset)
Deserialize an int value from an array of bytes.

Parameters:
data - the array of bytes into which to serialize the value.
offset - the position in the array of byte at which the serializatrion should start.
Returns:
the int value read from the array of bytes

readShort

public static short readShort(byte[] data,
                              int offset)
Deserialize an int value from an array of bytes.

Parameters:
data - the array of bytes into which to serialize the value.
offset - the position in the array of byte at which the serializatrion should start.
Returns:
the int value read from the array of bytes

readInt

public static int readInt(byte[] data,
                          int offset)
Deserialize an int value from an array of bytes.

Parameters:
data - the array of bytes into which to serialize the value.
offset - the position in the array of byte at which the serializatrion should start.
Returns:
the int value read from the array of bytes

readLong

public static long readLong(byte[] data,
                            int offset)
Deserialize an int value from an array of bytes.

Parameters:
data - the array of bytes into which to serialize the value.
offset - the position in the array of byte at which the serializatrion should start.
Returns:
the int value read from the array of bytes

readInt

public static int readInt(InputStream is)
                   throws IOException
Deserialize an int value from a stream.

Parameters:
is - the stream to read from.
Returns:
the int value read from the stream.
Throws:
IOException - if an error occurs while reading the data.

readLong

public static long readLong(InputStream is)
                     throws IOException
Deserialize an int value from a stream.

Parameters:
is - the stream to read from.
Returns:
the int value read from the stream.
Throws:
IOException - if an error occurs while reading the data.


Copyright © 2005-2010 JPPF Team.