public abstract class DataSerializer extends Object
DataSerializable
.
For instance, classes that implement DataSerializable
can use the DataSerializer
in their
toData
and fromData
methods:
public class Employee implements DataSerializable { private int id; private String name; private Date birthday; private Company employer; public void toData(DataOutput out) throws IOException { out.writeInt(this.id); out.writeUTF(this.name); DataSerializer.writeDate(this.birthday, out); DataSerializer.writeObject(this.employer, out); } public void fromData(DataInput in) throws IOException, ClassNotFoundException { this.id = in.readInt(); this.name = in.readUTF(); this.birthday = DataSerializer.readDate(in); this.employer = (Company) DataSerializer.readObject(in); } }
Instances of DataSerializer
are used to data serialize
objects (such as instances of standard Java classes or third-party
classes for which the source code is not available) that do not
implement the DataSerializable
interface.
The following DataSerializer
data serializes instances
of Company
. In order for the data serialization
framework to consult this custom serializer, it must be registered with the framework.
public class CompanySerializer extends DataSerializer { static { DataSerializer.register(CompanySerializer.class); } /** May be invoked reflectively if instances of Company are distributed to other VMs. / public CompanySerializer() { } public Class[] getSupportedClasses() { return new Class[] { Company.class }; } public int getId() { return 42; } public boolean toData(Object o, DataOutput out) throws IOException { if (o instanceof Company) { Company company = (Company) o; out.writeUTF(company.getName()); // Let's assume that Address is java.io.Serializable Address address = company.getAddress(); writeObject(address, out); return true; } else { return false; } } public Object fromData(DataInput in) throws IOException, ClassNotFoundException { String name = in.readUTF(); Address address = (Address) readObject(in); return new Company(name, address); } }Just like
Instantiator
s, a DataSerializer
may
be sent to other members of the distributed system when it is
registered. The data serialization
framework does not require that a DataSerializer
be
Serializable
, but it does require that it provide a
zero-argument constructor.writeObject(Object, DataOutput)
,
readObject(java.io.DataInput)
Constructor and Description |
---|
DataSerializer()
Creates a new
DataSerializer . |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object o)
Two
DataSerializer s are consider to be equal if they
have the same id and the same class |
abstract Object |
fromData(DataInput in)
Reads an object from a
DataInput . |
Object |
getContext()
For internal use only.
|
Object |
getEventId()
For internal use only.
|
abstract int |
getId()
Returns the id of this
DataSerializer . |
abstract Class<?>[] |
getSupportedClasses()
Returns the
Class es whose instances are data
serialized by this DataSerializer . |
int |
hashCode() |
static <E> ArrayList<E> |
readArrayList(DataInput in)
Reads an
ArrayList from a DataInput . |
static byte[][] |
readArrayOfByteArrays(DataInput in)
Reads an array of
byte[] s from a
DataInput . |
static Boolean |
readBoolean(DataInput in)
Reads an instance of
Boolean from a
DataInput . |
static boolean[] |
readBooleanArray(DataInput in)
Reads an array of
boolean s from a
DataInput . |
static Byte |
readByte(DataInput in)
Reads an instance of
Byte from a
DataInput . |
static byte[] |
readByteArray(DataInput in)
Reads an array of
byte s from a
DataInput . |
static Character |
readCharacter(DataInput in)
Reads an instance of
Character from a
DataInput . |
static char[] |
readCharArray(DataInput in)
Reads an array of
char s from a
DataInput . |
static Class<?> |
readClass(DataInput in)
Reads an instance of
Class from a
DataInput . |
static <K,V> ConcurrentHashMap<K,V> |
readConcurrentHashMap(DataInput in)
Reads a
ConcurrentHashMap from a DataInput . |
static Date |
readDate(DataInput in)
Reads an instance of
Date from a
DataInput . |
static Double |
readDouble(DataInput in)
Reads an instance of
Double from a
DataInput . |
static double[] |
readDoubleArray(DataInput in)
Reads an array of
double s from a
DataInput . |
static <E extends Enum<E>> |
readEnum(Class<E> clazz,
DataInput in)
Reads a
Enum constant from DataInput . |
static File |
readFile(DataInput in)
Reads an instance of
File from a
DataInput . |
static Float |
readFloat(DataInput in)
Reads an instance of
Float from a
DataInput . |
static float[] |
readFloatArray(DataInput in)
Reads an array of
float s from a
DataInput . |
static <K,V> HashMap<K,V> |
readHashMap(DataInput in)
Reads a
HashMap from a DataInput . |
static <E> HashSet<E> |
readHashSet(DataInput in)
Reads a
HashSet from a DataInput . |
static <K,V> Hashtable<K,V> |
readHashtable(DataInput in)
Reads a
Hashtable from a DataInput . |
static <K,V> IdentityHashMap<K,V> |
readIdentityHashMap(DataInput in)
Reads a
IdentityHashMap from a DataInput . |
static InetAddress |
readInetAddress(DataInput in)
Reads an instance of
InetAddress from a
DataInput . |
static int[] |
readIntArray(DataInput in)
Reads an
int array from a DataInput . |
static Integer |
readInteger(DataInput in)
Reads an instance of
Integer from a
DataInput . |
static <E> LinkedHashSet<E> |
readLinkedHashSet(DataInput in)
Reads a
LinkedHashSet from a DataInput . |
static <E> LinkedList<E> |
readLinkedList(DataInput in)
Reads an
LinkedList from a DataInput . |
static Long |
readLong(DataInput in)
Reads an instance of
Long from a
DataInput . |
static long[] |
readLongArray(DataInput in)
Reads an array of
long s from a
DataInput . |
static String |
readNonPrimitiveClassName(DataInput in)
Reads name of an instance of
Class from a
DataInput . |
static <T> T |
readObject(DataInput in)
Reads an arbitrary object from a
DataInput . |
static Object[] |
readObjectArray(DataInput in)
Reads an array of
Object s from a
DataInput . |
static boolean |
readPrimitiveBoolean(DataInput in)
Reads a primitive
boolean from a
DataInput . |
static byte |
readPrimitiveByte(DataInput in)
Reads a primitive
byte from a
DataInput . |
static char |
readPrimitiveChar(DataInput in)
Reads a primitive
char from a
DataInput . |
static double |
readPrimitiveDouble(DataInput in)
Reads a primitive
double from a
DataInput . |
static float |
readPrimitiveFloat(DataInput in)
Reads a primitive
float from a
DataInput . |
static int |
readPrimitiveInt(DataInput in)
Reads a primitive
int from a
DataInput . |
static long |
readPrimitiveLong(DataInput in)
Reads a primitive
long from a
DataInput . |
static short |
readPrimitiveShort(DataInput in)
Reads a primitive
short from a
DataInput . |
static Properties |
readProperties(DataInput in)
Reads a
Properties from a DataInput . |
static <K,V> Region<K,V> |
readRegion(DataInput in)
Reads an instance of Region.
|
static Short |
readShort(DataInput in)
Reads an instance of
Short from a
DataInput . |
static short[] |
readShortArray(DataInput in)
Reads an array of
short s from a
DataInput . |
static <E> Stack<E> |
readStack(DataInput in)
Reads an
Stack from a DataInput . |
static String |
readString(DataInput in)
Reads an instance of
String from a
DataInput . |
static String[] |
readStringArray(DataInput in)
Reads an array of
String s from a
DataInput . |
static <K,V> TreeMap<K,V> |
readTreeMap(DataInput in)
Reads a
TreeMap from a DataInput . |
static <E> TreeSet<E> |
readTreeSet(DataInput in)
Reads a
TreeSet from a DataInput . |
static int |
readUnsignedByte(DataInput in)
|
static int |
readUnsignedShort(DataInput in)
|
static <E> Vector<E> |
readVector(DataInput in)
Reads an
Vector from a DataInput . |
static DataSerializer |
register(Class<?> c)
Registers a
DataSerializer class with the data
serialization framework. |
static DataSerializer |
register(Class<?> c,
byte b)
Deprecated.
as of 5.7 use
register(Class) instead |
void |
setContext(Object context)
For internal use only.
|
void |
setEventId(Object eventId)
For internal use only.
|
abstract boolean |
toData(Object o,
DataOutput out)
Data serializes an object to a
DataOutput . |
static void |
writeArrayList(ArrayList<?> list,
DataOutput out)
Writes an
ArrayList to a DataOutput . |
static void |
writeArrayOfByteArrays(byte[][] array,
DataOutput out)
Writes an array of byte[] to a DataOutput.
|
static void |
writeBoolean(Boolean value,
DataOutput out)
Writes an instance of
Boolean to a
DataOutput . |
static void |
writeBooleanArray(boolean[] array,
DataOutput out)
Writes an array of
boolean s to a
DataOutput . |
static void |
writeByte(Byte value,
DataOutput out)
Writes an instance of
Byte to a
DataOutput . |
static void |
writeByteArray(byte[] array,
DataOutput out)
Writes an array of
byte s to a
DataOutput . |
static void |
writeByteArray(byte[] array,
int len,
DataOutput out)
Writes the first
len elements
of an array of byte s to a
DataOutput . |
static void |
writeCharacter(Character value,
DataOutput out)
Writes an instance of
Character to a
DataOutput . |
static void |
writeCharArray(char[] array,
DataOutput out)
Writes an array of
char s to a
DataOutput . |
static void |
writeClass(Class<?> c,
DataOutput out)
Writes an instance of
Class to a
DataOutput . |
static void |
writeConcurrentHashMap(ConcurrentHashMap<?,?> map,
DataOutput out)
Writes a
ConcurrentHashMap to a DataOutput . |
static void |
writeDate(Date date,
DataOutput out)
Writes an instance of
Date to a
DataOutput . |
static void |
writeDouble(Double value,
DataOutput out)
Writes an instance of
Double to a
DataOutput . |
static void |
writeDoubleArray(double[] array,
DataOutput out)
Writes an array of
double s to a
DataOutput . |
static void |
writeEnum(Enum e,
DataOutput out)
Writes the
Enum constant to DataOutput . |
static void |
writeFile(File file,
DataOutput out)
Writes an instance of
File to a
DataOutput . |
static void |
writeFloat(Float value,
DataOutput out)
Writes an instance of
Float to a
DataOutput . |
static void |
writeFloatArray(float[] array,
DataOutput out)
Writes an array of
float s to a
DataOutput . |
static void |
writeHashMap(HashMap<?,?> map,
DataOutput out)
Writes a
HashMap to a DataOutput . |
static void |
writeHashSet(HashSet<?> set,
DataOutput out)
Writes a
HashSet to a DataOutput . |
static void |
writeHashtable(Hashtable<?,?> map,
DataOutput out)
Writes a
Hashtable to a DataOutput . |
static void |
writeIdentityHashMap(IdentityHashMap<?,?> map,
DataOutput out)
Writes a
IdentityHashMap to a DataOutput . |
static void |
writeInetAddress(InetAddress address,
DataOutput out)
Writes an instance of
InetAddress to a
DataOutput . |
static void |
writeIntArray(int[] array,
DataOutput out)
Writes an
int array to a DataOutput . |
static void |
writeInteger(Integer value,
DataOutput out)
Writes an instance of
Integer to a
DataOutput . |
static void |
writeLinkedHashSet(LinkedHashSet<?> set,
DataOutput out)
Writes a
LinkedHashSet to a DataOutput . |
static void |
writeLinkedList(LinkedList<?> list,
DataOutput out)
Writes an
LinkedList to a DataOutput . |
static void |
writeLong(Long value,
DataOutput out)
Writes an instance of
Long to a
DataOutput . |
static void |
writeLongArray(long[] array,
DataOutput out)
Writes an array of
long s to a
DataOutput . |
static void |
writeNonPrimitiveClassName(String className,
DataOutput out)
Writes class name to a
DataOutput . |
static void |
writeObject(Object o,
DataOutput out)
Writes an arbitrary object to a
DataOutput . |
static void |
writeObject(Object o,
DataOutput out,
boolean allowJavaSerialization)
Writes an arbitrary object to a
DataOutput . |
static void |
writeObjectArray(Object[] array,
DataOutput out)
Writes an array of
Object s to a
DataOutput . |
static void |
writeObjectAsByteArray(Object obj,
DataOutput out)
Serialize the given object
obj into a byte array
using writeObject(Object, DataOutput) and then writes the byte array
to the given data output out in the same format
writeByteArray(byte[], DataOutput) does. |
static void |
writePrimitiveBoolean(boolean value,
DataOutput out)
Writes a primitive
boolean to a
DataOutput . |
static void |
writePrimitiveByte(byte value,
DataOutput out)
Writes a primitive
byte to a
DataOutput . |
static void |
writePrimitiveChar(char value,
DataOutput out)
Writes a primitive
char to a
DataOutput . |
static void |
writePrimitiveDouble(double value,
DataOutput out)
Writes a primtive
double to a
DataOutput . |
static void |
writePrimitiveFloat(float value,
DataOutput out)
Writes a primitive
float to a
DataOutput . |
static void |
writePrimitiveInt(int value,
DataOutput out)
Writes a primitive
int to a
DataOutput . |
static void |
writePrimitiveLong(long value,
DataOutput out)
Writes a primitive
long to a
DataOutput . |
static void |
writePrimitiveShort(short value,
DataOutput out)
Writes a primitive
short to a
DataOutput . |
static void |
writeProperties(Properties props,
DataOutput out)
Writes a
Properties to a DataOutput . |
static void |
writeRegion(Region<?,?> rgn,
DataOutput out)
Writes an instance of Region.
|
static void |
writeShort(Short value,
DataOutput out)
Writes an instance of
Short to a
DataOutput . |
static void |
writeShortArray(short[] array,
DataOutput out)
Writes an array of
short s to a
DataOutput . |
static void |
writeStack(Stack<?> list,
DataOutput out)
Writes an
Stack to a DataOutput . |
static void |
writeString(String value,
DataOutput out)
Writes an instance of
String to a
DataOutput . |
static void |
writeStringArray(String[] array,
DataOutput out)
Writes an array of
String s to a
DataOutput . |
static void |
writeTreeMap(TreeMap<?,?> map,
DataOutput out)
Writes a
TreeMap to a DataOutput . |
static void |
writeTreeSet(TreeSet<?> set,
DataOutput out)
Writes a
TreeSet to a DataOutput . |
static void |
writeUnsignedByte(int value,
DataOutput out)
Writes a primitive
int as an unsigned byte to a
DataOutput . |
static void |
writeUnsignedShort(int value,
DataOutput out)
Writes a primitive
int as an unsigned short to a
DataOutput . |
static void |
writeVector(Vector<?> list,
DataOutput out)
Writes an
Vector to a DataOutput . |
public DataSerializer()
DataSerializer
. All class that
implement DataSerializer
must provide a
zero-argument constructor.register(Class)
public static void writeClass(Class<?> c, DataOutput out) throws IOException
Class
to a
DataOutput
.
This method will handle a
null
value and not throw a
NullPointerException
.IOException
- A problem occurs while writing to out
readClass(java.io.DataInput)
public static void writeNonPrimitiveClassName(String className, DataOutput out) throws IOException
DataOutput
. This method will handle a
null
value and not throw a NullPointerException
.IOException
- A problem occurs while writing to out
readNonPrimitiveClassName(DataInput)
public static Class<?> readClass(DataInput in) throws IOException, ClassNotFoundException
Class
from a
DataInput
. The class will be loaded using the
current content class
loader.
The return value may be null
.IOException
- A problem occurs while reading from in
ClassNotFoundException
- The class cannot be loadedpublic static String readNonPrimitiveClassName(DataInput in) throws IOException
Class
from a
DataInput
.
The return value may be null
.IOException
- A problem occurs while reading from in
writeNonPrimitiveClassName(String, DataOutput)
public static void writeRegion(Region<?,?> rgn, DataOutput out) throws IOException
CacheFactory.getAnyInstance()
and then calling
getRegion
on it.
This method will handle a
null
value and not throw a
NullPointerException
.IOException
public static <K,V> Region<K,V> readRegion(DataInput in) throws IOException, ClassNotFoundException
CacheFactory.getAnyInstance()
and then calling
getRegion
on it.
The return value may be null
.in
- the input streamCacheClosedException
- if a cache has not been created or the only
created one is closed.RegionNotFoundException
- if there is no region by this name
in the CacheIOException
ClassNotFoundException
public static void writeDate(Date date, DataOutput out) throws IOException
Date
to a
DataOutput
. Note that even though date
may be an instance of a subclass of Date
,
readDate
will always return an instance of
Date
, not an instance of the subclass. To
preserve the class type of date
,\
writeObject(Object, DataOutput)
should be used for data serialization.
This method will handle a
null
value and not throw a
NullPointerException
.IOException
- A problem occurs while writing to out
readDate(java.io.DataInput)
public static Date readDate(DataInput in) throws IOException
Date
from a
DataInput
.
The return value may be null
.IOException
- A problem occurs while reading from in
public static void writeFile(File file, DataOutput out) throws IOException
File
to a
DataOutput
. Note that even though file
may be an instance of a subclass of File
,
readFile
will always return an instance of
File
, not an instance of the subclass. To
preserve the class type of file
,
writeObject(Object, DataOutput)
should be used for data serialization.
This method will handle a
null
value and not throw a
NullPointerException
.IOException
- A problem occurs while writing to out
readFile(java.io.DataInput)
,
File.getCanonicalPath()
public static File readFile(DataInput in) throws IOException
File
from a
DataInput
.
The return value may be null
.IOException
- A problem occurs while reading from in
public static void writeInetAddress(InetAddress address, DataOutput out) throws IOException
InetAddress
to a
DataOutput
. The InetAddress
is data
serialized by writing its byte
representation to the DataOutput
. readInetAddress(java.io.DataInput)
converts the byte
representation
to an instance of InetAddress
using InetAddress.getAddress()
. As a result, if address
is an instance of a user-defined subclass of
InetAddress
(that is, not an instance of one of the
subclasses from the java.net
package), its class
will not be preserved. In order to be able to read an instance
of the user-defined class, writeObject(Object, DataOutput)
should be used.
This method will handle a
null
value and not throw a
NullPointerException
.IOException
- A problem occurs while writing to out
readInetAddress(java.io.DataInput)
public static InetAddress readInetAddress(DataInput in) throws IOException
InetAddress
from a
DataInput
.
The return value may be null
.IOException
- A problem occurs while reading from in
or the address read from in
is unknownInetAddress.getAddress()
public static void writeString(String value, DataOutput out) throws IOException
String
to a
DataOutput
.
This method will handle a
null
value and not throw a
NullPointerException
.
As of 5.7 strings longer than 0xFFFF can be serialized.
IOException
- A problem occurs while writing to out
readString(java.io.DataInput)
public static String readString(DataInput in) throws IOException
String
from a
DataInput
. The return value may be
null
.IOException
- A problem occurs while reading from in
writeString(java.lang.String, java.io.DataOutput)
public static void writeBoolean(Boolean value, DataOutput out) throws IOException
Boolean
to a
DataOutput
.IOException
- A problem occurs while writing to out
NullPointerException
- if value is null.readBoolean(java.io.DataInput)
public static Boolean readBoolean(DataInput in) throws IOException
Boolean
from a
DataInput
.IOException
- A problem occurs while reading from in
public static void writeCharacter(Character value, DataOutput out) throws IOException
Character
to a
DataOutput
.IOException
- A problem occurs while writing to out
NullPointerException
- if value is null.readCharacter(java.io.DataInput)
public static Character readCharacter(DataInput in) throws IOException
Character
from a
DataInput
.IOException
- A problem occurs while reading from in
public static void writeByte(Byte value, DataOutput out) throws IOException
Byte
to a
DataOutput
.IOException
- A problem occurs while writing to out
NullPointerException
- if value is null.readByte(java.io.DataInput)
public static Byte readByte(DataInput in) throws IOException
Byte
from a
DataInput
.IOException
- A problem occurs while reading from in
public static void writeShort(Short value, DataOutput out) throws IOException
Short
to a
DataOutput
.IOException
- A problem occurs while writing to out
NullPointerException
- if value is null.readShort(java.io.DataInput)
public static Short readShort(DataInput in) throws IOException
Short
from a
DataInput
.IOException
- A problem occurs while reading from in
public static void writeInteger(Integer value, DataOutput out) throws IOException
Integer
to a
DataOutput
.IOException
- A problem occurs while writing to out
NullPointerException
- if value is null.readInteger(java.io.DataInput)
public static Integer readInteger(DataInput in) throws IOException
Integer
from a
DataInput
.IOException
- A problem occurs while reading from in
public static void writeLong(Long value, DataOutput out) throws IOException
Long
to a
DataOutput
.IOException
- A problem occurs while writing to out
NullPointerException
- if value is null.readLong(java.io.DataInput)
public static Long readLong(DataInput in) throws IOException
Long
from a
DataInput
.IOException
- A problem occurs while reading from in
public static void writeFloat(Float value, DataOutput out) throws IOException
Float
to a
DataOutput
.IOException
- A problem occurs while writing to out
NullPointerException
- if value is null.readFloat(java.io.DataInput)
public static Float readFloat(DataInput in) throws IOException
Float
from a
DataInput
.IOException
- A problem occurs while reading from in
public static void writeDouble(Double value, DataOutput out) throws IOException
Double
to a
DataOutput
.IOException
- A problem occurs while writing to out
NullPointerException
- if value is null.readDouble(java.io.DataInput)
public static Double readDouble(DataInput in) throws IOException
Double
from a
DataInput
.IOException
- A problem occurs while reading from in
public static void writePrimitiveBoolean(boolean value, DataOutput out) throws IOException
boolean
to a
DataOutput
.IOException
- A problem occurs while writing to out
DataOutput.writeBoolean(boolean)
public static boolean readPrimitiveBoolean(DataInput in) throws IOException
boolean
from a
DataInput
.IOException
- A problem occurs while reading from in
DataInput.readBoolean()
public static void writePrimitiveByte(byte value, DataOutput out) throws IOException
byte
to a
DataOutput
.IOException
- A problem occurs while writing to out
DataOutput.writeByte(int)
public static byte readPrimitiveByte(DataInput in) throws IOException
byte
from a
DataInput
.IOException
- A problem occurs while reading from in
DataInput.readByte()
public static void writePrimitiveChar(char value, DataOutput out) throws IOException
char
to a
DataOutput
.IOException
- A problem occurs while writing to out
DataOutput.writeChar(int)
public static char readPrimitiveChar(DataInput in) throws IOException
char
from a
DataInput
.IOException
- A problem occurs while reading from in
DataInput.readChar()
public static void writePrimitiveShort(short value, DataOutput out) throws IOException
short
to a
DataOutput
.IOException
- A problem occurs while writing to out
DataOutput.writeShort(int)
public static short readPrimitiveShort(DataInput in) throws IOException
short
from a
DataInput
.IOException
- A problem occurs while reading from in
DataInput.readShort()
public static void writeUnsignedByte(int value, DataOutput out) throws IOException
int
as an unsigned byte to a
DataOutput
.IOException
- A problem occurs while writing to out
DataOutput.writeByte(int)
,
DataInput.readUnsignedByte()
public static int readUnsignedByte(DataInput in) throws IOException
IOException
- A problem occurs while reading from in
public static void writeUnsignedShort(int value, DataOutput out) throws IOException
int
as an unsigned short to a
DataOutput
.IOException
- A problem occurs while writing to out
DataOutput.writeShort(int)
,
DataInput.readUnsignedShort()
public static int readUnsignedShort(DataInput in) throws IOException
IOException
- A problem occurs while reading from in
public static void writePrimitiveInt(int value, DataOutput out) throws IOException
int
to a
DataOutput
.IOException
- A problem occurs while writing to out
DataOutput.writeInt(int)
public static int readPrimitiveInt(DataInput in) throws IOException
int
from a
DataInput
.IOException
- A problem occurs while reading from in
DataInput.readInt()
public static void writePrimitiveLong(long value, DataOutput out) throws IOException
long
to a
DataOutput
.IOException
- A problem occurs while writing to out
DataOutput.writeLong(long)
public static long readPrimitiveLong(DataInput in) throws IOException
long
from a
DataInput
.IOException
- A problem occurs while reading from in
DataInput.readLong()
public static void writePrimitiveFloat(float value, DataOutput out) throws IOException
float
to a
DataOutput
.IOException
- A problem occurs while writing to out
DataOutput.writeFloat(float)
public static float readPrimitiveFloat(DataInput in) throws IOException
float
from a
DataInput
.IOException
- A problem occurs while reading from in
DataInput.readFloat()
public static void writePrimitiveDouble(double value, DataOutput out) throws IOException
double
to a
DataOutput
.IOException
- A problem occurs while writing to out
DataOutput.writeDouble(double)
public static double readPrimitiveDouble(DataInput in) throws IOException
double
from a
DataInput
.IOException
- A problem occurs while reading from in
DataInput.readDouble()
public static void writeByteArray(byte[] array, DataOutput out) throws IOException
byte
s to a
DataOutput
.
This method will serialize a
null
array and not throw a
NullPointerException
.IOException
- A problem occurs while writing to out
readByteArray(java.io.DataInput)
public static void writeByteArray(byte[] array, int len, DataOutput out) throws IOException
len
elements
of an array of byte
s to a
DataOutput
.
This method will serialize a
null
array and not throw a
NullPointerException
.len
- the actual number of entries to write. If len is greater
than then length of the array then the entire array is written.IOException
- A problem occurs while writing to out
readByteArray(java.io.DataInput)
public static void writeObjectAsByteArray(Object obj, DataOutput out) throws IOException
obj
into a byte array
using writeObject(Object, DataOutput)
and then writes the byte array
to the given data output out
in the same format
writeByteArray(byte[], DataOutput)
does.
This method will serialize a
null
obj and not throw a
NullPointerException
.obj
- the object to serialize and writeout
- the data output to write the byte array toIllegalArgumentException
- if a problem occurs while serialize obj
IOException
- if a problem occurs while writing to out
readByteArray(java.io.DataInput)
public static byte[] readByteArray(DataInput in) throws IOException
byte
s from a
DataInput
.IOException
- A problem occurs while reading from in
writeByteArray(byte[], DataOutput)
public static void writeStringArray(String[] array, DataOutput out) throws IOException
String
s to a
DataOutput
.
This method will serialize a
null
array and not throw a
NullPointerException
.IOException
- A problem occurs while writing to out
readStringArray(java.io.DataInput)
,
writeString(java.lang.String, java.io.DataOutput)
public static String[] readStringArray(DataInput in) throws IOException
String
s from a
DataInput
.IOException
- A problem occurs while reading from in
writeStringArray(java.lang.String[], java.io.DataOutput)
public static void writeShortArray(short[] array, DataOutput out) throws IOException
short
s to a
DataOutput
.
This method will serialize a
null
array and not throw a
NullPointerException
.IOException
- A problem occurs while writing to out
readShortArray(java.io.DataInput)
public static short[] readShortArray(DataInput in) throws IOException
short
s from a
DataInput
.IOException
- A problem occurs while reading from in
writeShortArray(short[], java.io.DataOutput)
public static void writeCharArray(char[] array, DataOutput out) throws IOException
char
s to a
DataOutput
.IOException
- A problem occurs while writing to out
readCharArray(java.io.DataInput)
public static char[] readCharArray(DataInput in) throws IOException
char
s from a
DataInput
.IOException
- A problem occurs while reading from in
writeCharArray(char[], java.io.DataOutput)
public static void writeBooleanArray(boolean[] array, DataOutput out) throws IOException
boolean
s to a
DataOutput
.IOException
- A problem occurs while writing to out
readBooleanArray(java.io.DataInput)
public static boolean[] readBooleanArray(DataInput in) throws IOException
boolean
s from a
DataInput
.IOException
- A problem occurs while reading from in
writeBooleanArray(boolean[], java.io.DataOutput)
public static void writeIntArray(int[] array, DataOutput out) throws IOException
int
array to a DataOutput
.
This method will serialize a
null
array and not throw a
NullPointerException
.IOException
- A problem occurs while writing to out
readIntArray(java.io.DataInput)
public static int[] readIntArray(DataInput in) throws IOException
int
array from a DataInput
.IOException
- A problem occurs while reading from in
writeIntArray(int[], java.io.DataOutput)
public static void writeLongArray(long[] array, DataOutput out) throws IOException
long
s to a
DataOutput
.
This method will serialize a
null
array and not throw a
NullPointerException
.IOException
- A problem occurs while writing to out
readLongArray(java.io.DataInput)
public static long[] readLongArray(DataInput in) throws IOException
long
s from a
DataInput
.IOException
- A problem occurs while reading from in
writeLongArray(long[], java.io.DataOutput)
public static void writeFloatArray(float[] array, DataOutput out) throws IOException
float
s to a
DataOutput
.
This method will serialize a
null
array and not throw a
NullPointerException
.IOException
- A problem occurs while writing to out
readFloatArray(java.io.DataInput)
public static float[] readFloatArray(DataInput in) throws IOException
float
s from a
DataInput
.IOException
- A problem occurs while reading from in
writeFloatArray(float[], java.io.DataOutput)
public static void writeDoubleArray(double[] array, DataOutput out) throws IOException
double
s to a
DataOutput
.
This method will serialize a
null
array and not throw a
NullPointerException
.IOException
- A problem occurs while writing to out
readDoubleArray(java.io.DataInput)
public static double[] readDoubleArray(DataInput in) throws IOException
double
s from a
DataInput
.IOException
- A problem occurs while reading from in
writeDoubleArray(double[], java.io.DataOutput)
public static void writeObjectArray(Object[] array, DataOutput out) throws IOException
Object
s to a
DataOutput
.
This method will serialize a
null
array and not throw a
NullPointerException
.IOException
- A problem occurs while writing to out
readObjectArray(java.io.DataInput)
,
writeObject(Object, DataOutput)
public static Object[] readObjectArray(DataInput in) throws IOException, ClassNotFoundException
Object
s from a
DataInput
.IOException
- A problem occurs while reading from in
ClassNotFoundException
writeObjectArray(java.lang.Object[], java.io.DataOutput)
,
readObject(java.io.DataInput)
public static void writeArrayOfByteArrays(byte[][] array, DataOutput out) throws IOException
IOException
- A problem occurs while writing to out.public static byte[][] readArrayOfByteArrays(DataInput in) throws IOException, ClassNotFoundException
byte[]
s from a
DataInput
.IOException
- A problem occurs while reading from in
ClassNotFoundException
public static void writeArrayList(ArrayList<?> list, DataOutput out) throws IOException
ArrayList
to a DataOutput
.
Note that even though list
may be an instance of a
subclass of ArrayList
, readArrayList
will always return an instance of ArrayList
,
not an instance of the subclass. To preserve the class
type of list
, writeObject(Object, DataOutput)
should be used
for data serialization.
This method will serialize a
null
list and not throw a
NullPointerException
.IOException
- A problem occurs while writing to out
readArrayList(java.io.DataInput)
public static <E> ArrayList<E> readArrayList(DataInput in) throws IOException, ClassNotFoundException
ArrayList
from a DataInput
.IOException
- A problem occurs while reading from in
ClassNotFoundException
- The class of one of the ArrayList
's
elements cannot be found.writeArrayList(java.util.ArrayList<?>, java.io.DataOutput)
public static void writeVector(Vector<?> list, DataOutput out) throws IOException
Vector
to a DataOutput
.
Note that even though list
may be an instance of a
subclass of Vector
, readVector
will always return an instance of Vector
,
not an instance of the subclass. To preserve the class
type of list
, writeObject(Object, DataOutput)
should be used
for data serialization.IOException
- A problem occurs while writing to out
readVector(java.io.DataInput)
public static <E> Vector<E> readVector(DataInput in) throws IOException, ClassNotFoundException
Vector
from a DataInput
.IOException
- A problem occurs while reading from in
ClassNotFoundException
- The class of one of the Vector
's
elements cannot be found.writeVector(java.util.Vector<?>, java.io.DataOutput)
public static void writeStack(Stack<?> list, DataOutput out) throws IOException
Stack
to a DataOutput
.
Note that even though list
may be an instance of a
subclass of Stack
, readStack
will always return an instance of Stack
,
not an instance of the subclass. To preserve the class
type of list
, writeObject(Object, DataOutput)
should be used
for data serialization.IOException
- A problem occurs while writing to out
readStack(java.io.DataInput)
public static <E> Stack<E> readStack(DataInput in) throws IOException, ClassNotFoundException
Stack
from a DataInput
.IOException
- A problem occurs while reading from in
ClassNotFoundException
- The class of one of the Stack
's
elements cannot be found.writeStack(java.util.Stack<?>, java.io.DataOutput)
public static void writeLinkedList(LinkedList<?> list, DataOutput out) throws IOException
LinkedList
to a DataOutput
.
Note that even though list
may be an instance of a
subclass of LinkedList
, readLinkedList
will always return an instance of LinkedList
,
not an instance of the subclass. To preserve the class
type of list
, writeObject(Object, DataOutput)
should be used
for data serialization.
This method will serialize a
null
list and not throw a
NullPointerException
.IOException
- A problem occurs while writing to out
readLinkedList(java.io.DataInput)
public static <E> LinkedList<E> readLinkedList(DataInput in) throws IOException, ClassNotFoundException
LinkedList
from a DataInput
.IOException
- A problem occurs while reading from in
ClassNotFoundException
- The class of one of the LinkedList
's
elements cannot be found.writeLinkedList(java.util.LinkedList<?>, java.io.DataOutput)
public static void writeHashSet(HashSet<?> set, DataOutput out) throws IOException
HashSet
to a DataOutput
. Note
that even though set
may be an instance of a
subclass of HashSet
, readHashSet
will
always return an instance of HashSet
, not an
instance of the subclass. To preserve the class type of
set
, writeObject(Object, DataOutput)
should be used for data
serialization.
This method will serialize a
null
set and not throw a
NullPointerException
.IOException
- A problem occurs while writing to out
readHashSet(java.io.DataInput)
public static <E> HashSet<E> readHashSet(DataInput in) throws IOException, ClassNotFoundException
HashSet
from a DataInput
.IOException
- A problem occurs while reading from in
ClassNotFoundException
- The class of one of the HashSet
's
elements cannot be found.writeHashSet(java.util.HashSet<?>, java.io.DataOutput)
public static void writeLinkedHashSet(LinkedHashSet<?> set, DataOutput out) throws IOException
LinkedHashSet
to a DataOutput
. Note
that even though set
may be an instance of a
subclass of LinkedHashSet
, readLinkedHashSet
will
always return an instance of LinkedHashSet
, not an
instance of the subclass. To preserve the class type of
set
, writeObject(Object, DataOutput)
should be used for data
serialization.IOException
- A problem occurs while writing to out
readLinkedHashSet(java.io.DataInput)
public static <E> LinkedHashSet<E> readLinkedHashSet(DataInput in) throws IOException, ClassNotFoundException
LinkedHashSet
from a DataInput
.IOException
- A problem occurs while reading from in
ClassNotFoundException
- The class of one of the LinkedHashSet
's
elements cannot be found.writeLinkedHashSet(java.util.LinkedHashSet<?>, java.io.DataOutput)
public static void writeHashMap(HashMap<?,?> map, DataOutput out) throws IOException
HashMap
to a DataOutput
. Note
that even though map
may be an instance of a
subclass of HashMap
, readHashMap
will
always return an instance of HashMap
, not an
instance of the subclass. To preserve the class type of
map
, writeObject(Object, DataOutput)
should be used for data
serialization.
This method will serialize a
null
map and not throw a
NullPointerException
.IOException
- A problem occurs while writing to out
readHashMap(java.io.DataInput)
public static <K,V> HashMap<K,V> readHashMap(DataInput in) throws IOException, ClassNotFoundException
HashMap
from a DataInput
.IOException
- A problem occurs while reading from in
ClassNotFoundException
- The class of one of the HashMap
's
elements cannot be found.writeHashMap(java.util.HashMap<?, ?>, java.io.DataOutput)
public static void writeIdentityHashMap(IdentityHashMap<?,?> map, DataOutput out) throws IOException
IdentityHashMap
to a DataOutput
. Note
that even though map
may be an instance of a
subclass of IdentityHashMap
, readIdentityHashMap
will
always return an instance of IdentityHashMap
, not an
instance of the subclass. To preserve the class type of
map
, writeObject(Object, DataOutput)
should be used for data
serialization.IOException
- A problem occurs while writing to out
readIdentityHashMap(java.io.DataInput)
public static <K,V> IdentityHashMap<K,V> readIdentityHashMap(DataInput in) throws IOException, ClassNotFoundException
IdentityHashMap
from a DataInput
.
Note that key identity is not preserved unless the keys belong to a class
whose serialization preserves identity.IOException
- A problem occurs while reading from in
ClassNotFoundException
- The class of one of the IdentityHashMap
's
elements cannot be found.writeIdentityHashMap(java.util.IdentityHashMap<?, ?>, java.io.DataOutput)
public static void writeConcurrentHashMap(ConcurrentHashMap<?,?> map, DataOutput out) throws IOException
ConcurrentHashMap
to a DataOutput
. Note
that even though map
may be an instance of a
subclass of ConcurrentHashMap
, readConcurrentHashMap
will
always return an instance of ConcurrentHashMap
, not an
instance of the subclass. To preserve the class type of
map
, writeObject(Object, DataOutput)
should be used for data
serialization.
At this time if writeObject(Object, DataOutput)
is called with an instance
of ConcurrentHashMap then it will be serialized with normal java.io Serialization. So
if you want the keys and values of a ConcurrentHashMap to take advantage of GemFire serialization
it must be serialized with this method.
IOException
- A problem occurs while writing to out
readConcurrentHashMap(java.io.DataInput)
public static <K,V> ConcurrentHashMap<K,V> readConcurrentHashMap(DataInput in) throws IOException, ClassNotFoundException
ConcurrentHashMap
from a DataInput
.IOException
- A problem occurs while reading from in
ClassNotFoundException
- The class of one of the ConcurrentHashMap
's
elements cannot be found.writeConcurrentHashMap(java.util.concurrent.ConcurrentHashMap<?, ?>, java.io.DataOutput)
public static void writeHashtable(Hashtable<?,?> map, DataOutput out) throws IOException
Hashtable
to a DataOutput
. Note
that even though map
may be an instance of a
subclass of Hashtable
, readHashtable
will
always return an instance of Hashtable
, not an
instance of the subclass. To preserve the class type of
map
, writeObject(Object, DataOutput)
should be used for data
serialization.IOException
- A problem occurs while writing to out
readHashtable(java.io.DataInput)
public static <K,V> Hashtable<K,V> readHashtable(DataInput in) throws IOException, ClassNotFoundException
Hashtable
from a DataInput
.IOException
- A problem occurs while reading from in
ClassNotFoundException
- The class of one of the Hashtable
's
elements cannot be found.writeHashtable(java.util.Hashtable<?, ?>, java.io.DataOutput)
public static void writeTreeMap(TreeMap<?,?> map, DataOutput out) throws IOException
TreeMap
to a DataOutput
. Note
that even though map
may be an instance of a
subclass of TreeMap
, readTreeMap
will
always return an instance of TreeMap
, not an
instance of the subclass. To preserve the class type of
map
, writeObject(Object, DataOutput)
should be used for data
serialization.
If the map has a comparator then it must also be serializable.
IOException
- A problem occurs while writing to out
readTreeMap(java.io.DataInput)
public static <K,V> TreeMap<K,V> readTreeMap(DataInput in) throws IOException, ClassNotFoundException
TreeMap
from a DataInput
.IOException
- A problem occurs while reading from in
ClassNotFoundException
- The class of one of the TreeMap
's
elements cannot be found.writeTreeMap(java.util.TreeMap<?, ?>, java.io.DataOutput)
public static void writeTreeSet(TreeSet<?> set, DataOutput out) throws IOException
TreeSet
to a DataOutput
. Note
that even though set
may be an instance of a
subclass of TreeSet
, readTreeSet
will
always return an instance of TreeSet
, not an
instance of the subclass. To preserve the class type of
set
, writeObject(Object, DataOutput)
should be used for data
serialization.
If the set has a comparator then it must also be serializable.
IOException
- A problem occurs while writing to out
readTreeSet(java.io.DataInput)
public static <E> TreeSet<E> readTreeSet(DataInput in) throws IOException, ClassNotFoundException
TreeSet
from a DataInput
.IOException
- A problem occurs while reading from in
ClassNotFoundException
- The class of one of the TreeSet
's
elements cannot be found.writeTreeSet(java.util.TreeSet<?>, java.io.DataOutput)
public static void writeProperties(Properties props, DataOutput out) throws IOException
Properties
to a DataOutput
.
NOTE: The defaults
of the specified props
are not serialized.
Note that even though props
may be an instance of a
subclass of Properties
, readProperties
will
always return an instance of Properties
, not an
instance of the subclass. To preserve the class type of
props
, writeObject(Object, DataOutput)
should be used for data
serialization.
IOException
- A problem occurs while writing to out
readProperties(java.io.DataInput)
public static Properties readProperties(DataInput in) throws IOException, ClassNotFoundException
Properties
from a DataInput
.
NOTE: the defaults
are always empty in the returned Properties
.
IOException
- A problem occurs while reading from in
ClassNotFoundException
writeProperties(java.util.Properties, java.io.DataOutput)
public static final void writeObject(Object o, DataOutput out, boolean allowJavaSerialization) throws IOException
DataOutput
. If
o
is not an instance of a specially-handled
standard Java class (see the list in getSupportedClasses()
),
the toData
method of each
registered DataSerializer
is invoked until the object
is serialized. If no registered serializer can serialize the
object and o
does not implement
DataSerializable
, then it is serialized to
out
using standard Java serialization.
This method will serialize a
null
o and not throw a
NullPointerException
.allowJavaSerialization
- If false, then a NotSerializableException is thrown
in the case where standard Java serialization would
otherwise be used for object o
or for any nested
subobject of o
. This is used to prevent
Java serialization from being used when sending data
to a non-Java clientIOException
- A problem occurs while writing o
to
out
readObject(DataInput)
,
Instantiator
,
ObjectOutputStream.writeObject(java.lang.Object)
public static final void writeObject(Object o, DataOutput out) throws IOException
DataOutput
. If
o
is not an instance of a specially-handled
standard Java class (such as Date
,
Integer
, or ArrayList
), the toData
method of each
registered DataSerializer
is invoked until the object
is serialized. If no registered serializer can serialize the
object and o
does not implement
DataSerializable
, then it is serialized to
out
using standard Java serialization.
This method will serialize a
null
o and not throw a
NullPointerException
.IOException
- A problem occurs while writing o
to
out
readObject(DataInput)
,
DataSerializer
,
ObjectOutputStream.writeObject(java.lang.Object)
public static final <T> T readObject(DataInput in) throws IOException, ClassNotFoundException
DataInput
.
Instances of classes that are not handled specially (such as
String
, Class
, and
DataSerializable
) are read using standard Java
serialization.
Note that if an object is deserialized using standard Java
serialization, its class will be loaded using the current
thread's context class
loader
before the one normally used by Java serialization is
consulted.
IOException
- A problem occured while reading from in
(may wrap another exception)ClassNotFoundException
- The class of an object read from in
could
not be foundwriteObject(Object, DataOutput)
,
ObjectInputStream.readObject()
public static final DataSerializer register(Class<?> c)
DataSerializer
class with the data
serialization framework. This method uses reflection to create
an instance of the DataSerializer
class by invoking
its zero-argument constructor.
The DataSerializer
instance will be consulted by the
writeObject(Object, DataOutput)
and readObject(java.io.DataInput)
methods.
Note that no two serializers can support the same class.
This method invokes the DataSerializer
instance's
getSupportedClasses()
method and keeps track of which
classes can have their instances serialized by by this data serializer.
c
- the DataSerializer
class to create and
register with the data serialization framework.IllegalArgumentException
- If c
does not subclass
DataSerializer
, if c
does not
have a zero-argument constructor,
if id
is 0,
if getSupportedClasses returns null or an empty array,
if getSupportedClasses returns and array with null elementsIllegalStateException
- if another serializer
instance with id id
has already been registered,
if another serializer instance that supports one of this instances
classes has already been registered,
if an attempt is made to support any of the classes reserved by DataSerializer
(see getSupportedClasses()
for a list).getSupportedClasses()
@Deprecated public static final DataSerializer register(Class<?> c, byte b)
register(Class)
insteadpublic abstract Class<?>[] getSupportedClasses()
Class
es whose instances are data
serialized by this DataSerializer
. This method is
invoked when this serializer is registered. This method is not allowed to return null
nor an empty array.
Only instances whose class name is the same as one of the class names
in the result will be serialized by this DataSerializer
.
Two DataSerializer
s are not allowed to support the same class.
The following classes can not be supported by user defined data serializers
since they are all supported by the predefined data serializer:
public abstract boolean toData(Object o, DataOutput out) throws IOException
DataOutput
. It is
very important that when performing the "switch" on
o
's class, your code test for a subclass before it
tests for a superclass. Otherwise, the incorrect class id could
be written to the serialization stream.o
- The object to data serialize. It will never be
null
.false
if this DataSerializer
does
not know how to data serialize o
.IOException
public abstract Object fromData(DataInput in) throws IOException, ClassNotFoundException
DataInput
.
This implementation must support deserializing everything serialized by
the matching toData(java.lang.Object, java.io.DataOutput)
.IOException
- If this serializer cannot read an object from
in
.ClassNotFoundException
toData(java.lang.Object, java.io.DataOutput)
public abstract int getId()
DataSerializer
.
Returns an int instead of a byte since 5.7.
public boolean equals(Object o)
DataSerializer
s are consider to be equal if they
have the same id and the same classpublic final void setEventId(Object eventId)
eventId
of this
DataSerializer
.public final Object getEventId()
eventId
of this
DataSerializer
.public final void setContext(Object context)
DataSerializer
.public final Object getContext()
DataSerializer
.public static void writeEnum(Enum e, DataOutput out) throws IOException
Enum constant
to DataOutput
. Unlike
standard java serialization which serializes both the enum name String and
the ordinal, GemFire only serializes the ordinal byte, so for backward
compatibility new enum constants should only be added to the end of the
enum type.DataSerializer.writeEnum(DAY_OF_WEEK.SUN, out);
IOException
readEnum(Class, DataInput)
public static <E extends Enum<E>> E readEnum(Class<E> clazz, DataInput in) throws IOException
Enum constant
from DataInput
. Unlike
standard java serialization which serializes both the enum name String and
the ordinal, GemFire only serializes the ordinal byte, so be careful about
using the correct enum class. Also, for backward compatibility new enum
constants should only be added to the end of the enum type.DAY_OF_WEEK d = DataSerializer.readEnum(DAY_OF_WEEK.class, in);
IOException
- A problem occurs while writing to out
ArrayIndexOutOfBoundsException
- if the wrong enum class/enum class with a different version and
less enum constants is usedwriteEnum(Enum, DataOutput)
Copyright © 1997-2017 Pivotal Software, Inc. All rights reserved.