Package org.jppf.serialization
Class SerializationUtils
java.lang.Object
org.jppf.serialization.SerializationUtils
Utility methods for serializing and deserializing data
- Author:
- Laurent Cohen
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanisASCII(char[] chars) Determine whether a character sequence is only made of ACII characters.static booleanreadBoolean(byte[] data, int offset) Deserialize an int value from an array of bytes.static charreadChar(byte[] data, int offset) Deserialize an int value from an array of bytes.static intreadInt(byte[] data, int offset) Deserialize an int value from an array of bytes.static intreadInt(InputStream is) Deserialize an int value from a stream.static intreadInt(ReadableByteChannel channel) Read an integer value from a channel.static longreadLong(byte[] data, int offset) Deserialize an int value from an array of bytes.static longreadLong(InputStream is) Deserialize an int value from a stream.static shortreadShort(byte[] data, int offset) Deserialize an int value from an array of bytes.static org.jppf.serialization.SerializationUtils.StringLengthDescreadStringLength(InputStream is, byte[] buf) Deserialize an int value from a stream.static voidreadToBuf(InputStream in, byte[] buf, int offset, int len) Read the specified number of bytes into the temp buffer.static intreadVarInt(InputStream is, byte[] buf) Deserialize an int value from a stream.static longreadVarLong(InputStream is, byte[] buf) Deserialize a long value from a stream.static voidwriteBoolean(boolean value, byte[] data, int offset) Serialize an int value into an array of bytes.static voidwriteChar(char value, byte[] data, int offset) Serialize an int value into an array of bytes.static voidwriteChar(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 voidwriteInt(int value, byte[] data, int offset) Serialize an int value into an array of bytes.static voidwriteInt(int value, OutputStream os) Serialize an int value to a stream.static voidwriteInt(WritableByteChannel channel, int value) Write an integer value to a channel.static voidwriteLong(long value, byte[] data, int offset) Serialize a long value into an array of bytes.static voidwriteShort(short value, byte[] data, int offset) Serialize an int value into an array of bytes.static voidwriteStringLength(OutputStream os, boolean isAscii, int value, byte[] data) Serialize an int value into an array of bytes.static intwriteVarInt(OutputStream os, int value, byte[] data) Serialize an int value into an array of bytes.static intwriteVarLong(OutputStream os, long value, byte[] data) Serialize a long value into an array of bytes.
-
Field Details
-
TEMP_BUFFER_SIZE
public static final int TEMP_BUFFER_SIZE- See Also:
-
-
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
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
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
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
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
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
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
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
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
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
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
Determine whether a character sequence is only made of ACII characters.- Parameters:
chars- the char sequence to check.- Returns:
trueif the sequence only contains ACII characters,falseotherwise.- 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
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.
-