Class SerializationUtils

java.lang.Object
org.jppf.serialization.SerializationUtils

public final class SerializationUtils extends Object
Utility methods for serializing and deserializing data
Author:
Laurent Cohen
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    isASCII(char[] chars)
    Determine whether a character sequence is only made of ACII characters.
    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
    Deserialize an int value from a stream.
    static int
    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
    Deserialize an int value from a stream.
    static short
    readShort(byte[] data, int offset)
    Deserialize an int value from an array of bytes.
    static org.jppf.serialization.SerializationUtils.StringLengthDesc
    readStringLength(InputStream is, byte[] buf)
    Deserialize an int value from a stream.
    static void
    readToBuf(InputStream in, byte[] buf, int offset, int len)
    Read the specified number of bytes into the temp buffer.
    static int
    readVarInt(InputStream is, byte[] buf)
    Deserialize an int value from a stream.
    static long
    readVarLong(InputStream is, byte[] buf)
    Deserialize a long value from a stream.
    static void
    writeBoolean(boolean value, byte[] data, int offset)
    Serialize an int value into an array of bytes.
    static void
    writeChar(char value, byte[] data, int offset)
    Serialize an int value into an array of bytes.
    static void
    writeChar(char value, OutputStream os)
    Serialize an int value to a stream.
    static byte[]
    writeInt(int value)
    Serialize an int value into an array of bytes.
    static void
    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)
    Write an integer value to a channel.
    static void
    writeLong(long value, byte[] data, int offset)
    Serialize a long value into an array of bytes.
    static void
    writeShort(short value, byte[] data, int offset)
    Serialize an int value into an array of bytes.
    static void
    writeStringLength(OutputStream os, boolean isAscii, int value, byte[] data)
    Serialize an int value into an array of bytes.
    static int
    writeVarInt(OutputStream os, int value, byte[] data)
    Serialize an int value into an array of bytes.
    static int
    writeVarLong(OutputStream os, long value, byte[] data)
    Serialize a long value into an array of bytes.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Method Details

    • 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 void 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 serialization should start.
    • writeChar

      public static void 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 serialization should start.
    • writeShort

      public static void 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 serialization should start.
    • writeInt

      public static void 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 serialization should start.
    • writeLong

      public static void 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 serialization should start.
    • writeChar

      public static void writeChar(char 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(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
      Write 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 serialization 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 serialization 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 serialization 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 serialization 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 serialization 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.
    • writeVarInt

      public static int writeVarInt(OutputStream os, int value, byte[] data) throws IOException
      Serialize an int value into an array of bytes.
      Parameters:
      os - the stream to write to.
      value - the int value to serialize.
      data - the array of bytes into which to serialize the value.
      Returns:
      the number of bytes written to the buffer.
      Throws:
      IOException - if an error occurs while writing the data.
    • writeVarLong

      public static int writeVarLong(OutputStream os, long value, byte[] data) throws IOException
      Serialize a long value into an array of bytes.
      Parameters:
      os - the stream to write to.
      value - the long value to serialize.
      data - the array of bytes into which to serialize the value.
      Returns:
      the number of bytes written to the buffer.
      Throws:
      IOException - if an error occurs while writing the data.
    • readVarInt

      public static int readVarInt(InputStream is, byte[] buf) throws IOException
      Deserialize an int value from a stream.
      Parameters:
      is - the stream to read from.
      buf - a temporary buffer.
      Returns:
      the int value read from the stream.
      Throws:
      IOException - if an error occurs while reading the data.
    • readVarLong

      public static long readVarLong(InputStream is, byte[] buf) throws IOException
      Deserialize a long value from a stream.
      Parameters:
      is - the stream to read from.
      buf - a temporary buffer.
      Returns:
      the long value read from the stream.
      Throws:
      IOException - if an error occurs while reading the data.
    • isASCII

      public static boolean isASCII(char[] chars) throws Exception
      Determine whether a character sequence is only made of ACII characters.
      Parameters:
      chars - the char sequence to check.
      Returns:
      true if the sequence only contains ACII characters, false otherwise.
      Throws:
      Exception - if any error occurs.
    • writeStringLength

      public static void writeStringLength(OutputStream os, boolean isAscii, int value, byte[] data) throws IOException
      Serialize an int value into an array of bytes.
      Parameters:
      os - the stream to write to.
      isAscii - whether the string is pure ASCII.
      value - the string length to serialize.
      data - the array of bytes into which to serialize the value.
      Throws:
      IOException - if an error occurs while writing the data.
    • readStringLength

      public static org.jppf.serialization.SerializationUtils.StringLengthDesc readStringLength(InputStream is, byte[] buf) throws IOException
      Deserialize an int value from a stream.
      Parameters:
      is - the stream to read from.
      buf - a temporary buffer.
      Returns:
      the int value read from the stream.
      Throws:
      IOException - if an error occurs while reading the data.
    • readToBuf

      public static void readToBuf(InputStream in, byte[] buf, int offset, int len) throws IOException
      Read the specified number of bytes into the temp buffer.
      Parameters:
      in - the stream to read from.
      buf - a temporary buffer.
      offset - the offset at which to start in the buffer.
      len - the number of bytes to read.
      Throws:
      IOException - if any error occurs.