GemFire 6.6.3

com.gemstone.gemfire
Class DataSerializer

java.lang.Object
  extended by com.gemstone.gemfire.DataSerializer

public abstract class DataSerializer
extends Object

Provides static helper methods for reading and writing non-primitive data when working with a 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 Instantiators, 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.

Since:
3.5
See Also:
writeObject(Object, DataOutput), readObject(java.io.DataInput)

Field Summary
static boolean DEBUG
          Should verbose debugging information be dumped?
static boolean DUMP_SERIALIZED
          If the "DataSerializer.DUMP_SERIALIZED" system property is set, the class names of the objects that are serialized by writeObject(Object, DataOutput) using standard Java serialization are logged to standard out.
 
Constructor Summary
DataSerializer()
          Creates a new DataSerializer.
 
Method Summary
 boolean equals(Object o)
          Two DataSerializers 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 Classes 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 booleans 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 bytes 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 chars 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 doubles from a DataInput.
static
<E extends Enum<E>>
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 floats 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 longs 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 Objects 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 shorts 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 Strings 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)
          Reads a primitive int as an unsigned byte from a DataInput using DataInput.readUnsignedByte().
static int readUnsignedShort(DataInput in)
          Reads a primitive int as an unsigned short from a DataInput using DataInput.readUnsignedShort().
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 booleans 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 bytes to a DataOutput.
static void writeByteArray(byte[] array, int len, DataOutput out)
          Writes the first len elements of an array of bytes 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 chars 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 doubles 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 floats 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 longs 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 Objects 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 shorts 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 Strings 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.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DUMP_SERIALIZED

public static final boolean DUMP_SERIALIZED
If the "DataSerializer.DUMP_SERIALIZED" system property is set, the class names of the objects that are serialized by writeObject(Object, DataOutput) using standard Java serialization are logged to standard out. This aids in determining which classes should implement DataSerializable (or should be special cased by a custom DataSerializer).


DEBUG

public static final boolean DEBUG
Should verbose debugging information be dumped?

Constructor Detail

DataSerializer

public DataSerializer()
Creates a new DataSerializer. All class that implement DataSerializer must provide a zero-argument constructor.

See Also:
register(Class)
Method Detail

writeClass

public static void writeClass(Class<?> c,
                              DataOutput out)
                       throws IOException
Writes an instance of Class to a DataOutput. This method will handle a null value and not throw a NullPointerException.

Throws:
IOException - A problem occurs while writing to out
See Also:
readClass(java.io.DataInput)

writeNonPrimitiveClassName

public static void writeNonPrimitiveClassName(String className,
                                              DataOutput out)
                                       throws IOException
Writes class name to a DataOutput. This method will handle a null value and not throw a NullPointerException.

Throws:
IOException - A problem occurs while writing to out
See Also:
readNonPrimitiveClassName(DataInput)

readClass

public static Class<?> readClass(DataInput in)
                          throws IOException,
                                 ClassNotFoundException
Reads an instance of Class from a DataInput. The class will be loaded using the current content class loader. The return value may be null.

Throws:
IOException - A problem occurs while reading from in
ClassNotFoundException - The class cannot be loaded

readNonPrimitiveClassName

public static String readNonPrimitiveClassName(DataInput in)
                                        throws IOException
Reads name of an instance of Class from a DataInput. The return value may be null.

Throws:
IOException - A problem occurs while reading from in
See Also:
writeNonPrimitiveClassName(String, DataOutput)

writeRegion

public static void writeRegion(Region<?,?> rgn,
                               DataOutput out)
                        throws IOException
Writes an instance of Region. A Region is serialized as just a reference to a full path only. It will be recreated on the other end by calling CacheFactory.getAnyInstance() and then calling getRegion on it. This method will handle a null value and not throw a NullPointerException.

Throws:
IOException

readRegion

public static <K,V> Region<K,V> readRegion(DataInput in)
                              throws IOException,
                                     ClassNotFoundException
Reads an instance of Region. A Region is serialized as a reference to a full path only. It is recreated on the other end by calling CacheFactory.getAnyInstance() and then calling getRegion on it. The return value may be null.

Parameters:
in - the input stream
Returns:
the Region instance
Throws:
CacheClosedException - 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 Cache
IOException
ClassNotFoundException

writeDate

public static void writeDate(Date date,
                             DataOutput out)
                      throws IOException
Writes an instance of 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.

Throws:
IOException - A problem occurs while writing to out
See Also:
readDate(java.io.DataInput)

readDate

public static Date readDate(DataInput in)
                     throws IOException
Reads an instance of Date from a DataInput. The return value may be null.

Throws:
IOException - A problem occurs while reading from in

writeFile

public static void writeFile(File file,
                             DataOutput out)
                      throws IOException
Writes an instance of 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.

Throws:
IOException - A problem occurs while writing to out
See Also:
readFile(java.io.DataInput), File.getCanonicalPath()

readFile

public static File readFile(DataInput in)
                     throws IOException
Reads an instance of File from a DataInput. The return value may be null.

Throws:
IOException - A problem occurs while reading from in

writeInetAddress

public static void writeInetAddress(InetAddress address,
                                    DataOutput out)
                             throws IOException
Writes an instance of 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.

Throws:
IOException - A problem occurs while writing to out
See Also:
readInetAddress(java.io.DataInput)

readInetAddress

public static InetAddress readInetAddress(DataInput in)
                                   throws IOException
Reads an instance of InetAddress from a DataInput. The return value may be null.

Throws:
IOException - A problem occurs while reading from in or the address read from in is unknown
See Also:
InetAddress.getAddress()

writeString

public static void writeString(String value,
                               DataOutput out)
                        throws IOException
Writes an instance of 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.

Throws:
IOException - A problem occurs while writing to out
See Also:
readString(java.io.DataInput)

readString

public static String readString(DataInput in)
                         throws IOException
Reads an instance of String from a DataInput. The return value may be null.

Throws:
IOException - A problem occurs while reading from in
See Also:
writeString(java.lang.String, java.io.DataOutput)

writeBoolean

public static void writeBoolean(Boolean value,
                                DataOutput out)
                         throws IOException
Writes an instance of Boolean to a DataOutput.

Throws:
IOException - A problem occurs while writing to out
NullPointerException - if value is null.
See Also:
readBoolean(java.io.DataInput)

readBoolean

public static Boolean readBoolean(DataInput in)
                           throws IOException
Reads an instance of Boolean from a DataInput.

Throws:
IOException - A problem occurs while reading from in

writeCharacter

public static void writeCharacter(Character value,
                                  DataOutput out)
                           throws IOException
Writes an instance of Character to a DataOutput.

Throws:
IOException - A problem occurs while writing to out
NullPointerException - if value is null.
See Also:
readCharacter(java.io.DataInput)

readCharacter

public static Character readCharacter(DataInput in)
                               throws IOException
Reads an instance of Character from a DataInput.

Throws:
IOException - A problem occurs while reading from in

writeByte

public static void writeByte(Byte value,
                             DataOutput out)
                      throws IOException
Writes an instance of Byte to a DataOutput.

Throws:
IOException - A problem occurs while writing to out
NullPointerException - if value is null.
See Also:
readByte(java.io.DataInput)

readByte

public static Byte readByte(DataInput in)
                     throws IOException
Reads an instance of Byte from a DataInput.

Throws:
IOException - A problem occurs while reading from in

writeShort

public static void writeShort(Short value,
                              DataOutput out)
                       throws IOException
Writes an instance of Short to a DataOutput.

Throws:
IOException - A problem occurs while writing to out
NullPointerException - if value is null.
See Also:
readShort(java.io.DataInput)

readShort

public static Short readShort(DataInput in)
                       throws IOException
Reads an instance of Short from a DataInput.

Throws:
IOException - A problem occurs while reading from in

writeInteger

public static void writeInteger(Integer value,
                                DataOutput out)
                         throws IOException
Writes an instance of Integer to a DataOutput.

Throws:
IOException - A problem occurs while writing to out
NullPointerException - if value is null.
See Also:
readInteger(java.io.DataInput)

readInteger

public static Integer readInteger(DataInput in)
                           throws IOException
Reads an instance of Integer from a DataInput.

Throws:
IOException - A problem occurs while reading from in

writeLong

public static void writeLong(Long value,
                             DataOutput out)
                      throws IOException
Writes an instance of Long to a DataOutput.

Throws:
IOException - A problem occurs while writing to out
NullPointerException - if value is null.
See Also:
readLong(java.io.DataInput)

readLong

public static Long readLong(DataInput in)
                     throws IOException
Reads an instance of Long from a DataInput.

Throws:
IOException - A problem occurs while reading from in

writeFloat

public static void writeFloat(Float value,
                              DataOutput out)
                       throws IOException
Writes an instance of Float to a DataOutput.

Throws:
IOException - A problem occurs while writing to out
NullPointerException - if value is null.
See Also:
readFloat(java.io.DataInput)

readFloat

public static Float readFloat(DataInput in)
                       throws IOException
Reads an instance of Float from a DataInput.

Throws:
IOException - A problem occurs while reading from in

writeDouble

public static void writeDouble(Double value,
                               DataOutput out)
                        throws IOException
Writes an instance of Double to a DataOutput.

Throws:
IOException - A problem occurs while writing to out
NullPointerException - if value is null.
See Also:
readDouble(java.io.DataInput)

readDouble

public static Double readDouble(DataInput in)
                         throws IOException
Reads an instance of Double from a DataInput.

Throws:
IOException - A problem occurs while reading from in

writePrimitiveBoolean

public static void writePrimitiveBoolean(boolean value,
                                         DataOutput out)
                                  throws IOException
Writes a primitive boolean to a DataOutput.

Throws:
IOException - A problem occurs while writing to out
Since:
5.1
See Also:
DataOutput.writeBoolean(boolean)

readPrimitiveBoolean

public static boolean readPrimitiveBoolean(DataInput in)
                                    throws IOException
Reads a primitive boolean from a DataInput.

Throws:
IOException - A problem occurs while reading from in
Since:
5.1
See Also:
DataInput.readBoolean()

writePrimitiveByte

public static void writePrimitiveByte(byte value,
                                      DataOutput out)
                               throws IOException
Writes a primitive byte to a DataOutput.

Throws:
IOException - A problem occurs while writing to out
Since:
5.1
See Also:
DataOutput.writeByte(int)

readPrimitiveByte

public static byte readPrimitiveByte(DataInput in)
                              throws IOException
Reads a primitive byte from a DataInput.

Throws:
IOException - A problem occurs while reading from in
Since:
5.1
See Also:
DataInput.readByte()

writePrimitiveChar

public static void writePrimitiveChar(char value,
                                      DataOutput out)
                               throws IOException
Writes a primitive char to a DataOutput.

Throws:
IOException - A problem occurs while writing to out
Since:
5.1
See Also:
DataOutput.writeChar(int)

readPrimitiveChar

public static char readPrimitiveChar(DataInput in)
                              throws IOException
Reads a primitive char from a DataInput.

Throws:
IOException - A problem occurs while reading from in
Since:
5.1
See Also:
DataInput.readChar()

writePrimitiveShort

public static void writePrimitiveShort(short value,
                                       DataOutput out)
                                throws IOException
Writes a primitive short to a DataOutput.

Throws:
IOException - A problem occurs while writing to out
Since:
5.1
See Also:
DataOutput.writeShort(int)

readPrimitiveShort

public static short readPrimitiveShort(DataInput in)
                                throws IOException
Reads a primitive short from a DataInput.

Throws:
IOException - A problem occurs while reading from in
Since:
5.1
See Also:
DataInput.readShort()

writeUnsignedByte

public static void writeUnsignedByte(int value,
                                     DataOutput out)
                              throws IOException
Writes a primitive int as an unsigned byte to a DataOutput.

Throws:
IOException - A problem occurs while writing to out
Since:
5.1
See Also:
DataOutput.writeByte(int), DataInput.readUnsignedByte()

readUnsignedByte

public static int readUnsignedByte(DataInput in)
                            throws IOException
Reads a primitive int as an unsigned byte from a DataInput using DataInput.readUnsignedByte().

Throws:
IOException - A problem occurs while reading from in
Since:
5.1

writeUnsignedShort

public static void writeUnsignedShort(int value,
                                      DataOutput out)
                               throws IOException
Writes a primitive int as an unsigned short to a DataOutput.

Throws:
IOException - A problem occurs while writing to out
Since:
5.1
See Also:
DataOutput.writeShort(int), DataInput.readUnsignedShort()

readUnsignedShort

public static int readUnsignedShort(DataInput in)
                             throws IOException
Reads a primitive int as an unsigned short from a DataInput using DataInput.readUnsignedShort().

Throws:
IOException - A problem occurs while reading from in
Since:
5.1

writePrimitiveInt

public static void writePrimitiveInt(int value,
                                     DataOutput out)
                              throws IOException
Writes a primitive int to a DataOutput.

Throws:
IOException - A problem occurs while writing to out
See Also:
DataOutput.writeInt(int)

readPrimitiveInt

public static int readPrimitiveInt(DataInput in)
                            throws IOException
Reads a primitive int from a DataInput.

Throws:
IOException - A problem occurs while reading from in
Since:
5.1
See Also:
DataInput.readInt()

writePrimitiveLong

public static void writePrimitiveLong(long value,
                                      DataOutput out)
                               throws IOException
Writes a primitive long to a DataOutput.

Throws:
IOException - A problem occurs while writing to out
Since:
5.1
See Also:
DataOutput.writeLong(long)

readPrimitiveLong

public static long readPrimitiveLong(DataInput in)
                              throws IOException
Reads a primitive long from a DataInput.

Throws:
IOException - A problem occurs while reading from in
Since:
5.1
See Also:
DataInput.readLong()

writePrimitiveFloat

public static void writePrimitiveFloat(float value,
                                       DataOutput out)
                                throws IOException
Writes a primitive float to a DataOutput.

Throws:
IOException - A problem occurs while writing to out
Since:
5.1
See Also:
DataOutput.writeFloat(float)

readPrimitiveFloat

public static float readPrimitiveFloat(DataInput in)
                                throws IOException
Reads a primitive float from a DataInput.

Throws:
IOException - A problem occurs while reading from in
Since:
5.1
See Also:
DataInput.readFloat()

writePrimitiveDouble

public static void writePrimitiveDouble(double value,
                                        DataOutput out)
                                 throws IOException
Writes a primtive double to a DataOutput.

Throws:
IOException - A problem occurs while writing to out
Since:
5.1
See Also:
DataOutput.writeDouble(double)

readPrimitiveDouble

public static double readPrimitiveDouble(DataInput in)
                                  throws IOException
Reads a primitive double from a DataInput.

Throws:
IOException - A problem occurs while reading from in
Since:
5.1
See Also:
DataInput.readDouble()

writeByteArray

public static void writeByteArray(byte[] array,
                                  DataOutput out)
                           throws IOException
Writes an array of bytes to a DataOutput. This method will serialize a null array and not throw a NullPointerException.

Throws:
IOException - A problem occurs while writing to out
See Also:
readByteArray(java.io.DataInput)

writeByteArray

public static void writeByteArray(byte[] array,
                                  int len,
                                  DataOutput out)
                           throws IOException
Writes the first len elements of an array of bytes to a DataOutput. This method will serialize a null array and not throw a NullPointerException.

Parameters:
len - the actual number of entries to write. If len is greater than then length of the array then the entire array is written.
Throws:
IOException - A problem occurs while writing to out
See Also:
readByteArray(java.io.DataInput)

writeObjectAsByteArray

public static void writeObjectAsByteArray(Object obj,
                                          DataOutput out)
                                   throws IOException
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. This method will serialize a null obj and not throw a NullPointerException.

Parameters:
obj - the object to serialize and write
out - the data output to write the byte array to
Throws:
IllegalArgumentException - if a problem occurs while serialize obj
IOException - if a problem occurs while writing to out
Since:
5.0.2
See Also:
readByteArray(java.io.DataInput)

readByteArray

public static byte[] readByteArray(DataInput in)
                            throws IOException
Reads an array of bytes from a DataInput.

Throws:
IOException - A problem occurs while reading from in
See Also:
writeByteArray(byte[], DataOutput)

writeStringArray

public static void writeStringArray(String[] array,
                                    DataOutput out)
                             throws IOException
Writes an array of Strings to a DataOutput. This method will serialize a null array and not throw a NullPointerException.

Throws:
IOException - A problem occurs while writing to out
See Also:
readStringArray(java.io.DataInput), writeString(java.lang.String, java.io.DataOutput)

readStringArray

public static String[] readStringArray(DataInput in)
                                throws IOException
Reads an array of Strings from a DataInput.

Throws:
IOException - A problem occurs while reading from in
See Also:
writeStringArray(java.lang.String[], java.io.DataOutput)

writeShortArray

public static void writeShortArray(short[] array,
                                   DataOutput out)
                            throws IOException
Writes an array of shorts to a DataOutput. This method will serialize a null array and not throw a NullPointerException.

Throws:
IOException - A problem occurs while writing to out
See Also:
readShortArray(java.io.DataInput)

readShortArray

public static short[] readShortArray(DataInput in)
                              throws IOException
Reads an array of shorts from a DataInput.

Throws:
IOException - A problem occurs while reading from in
See Also:
writeShortArray(short[], java.io.DataOutput)

writeCharArray

public static void writeCharArray(char[] array,
                                  DataOutput out)
                           throws IOException
Writes an array of chars to a DataOutput.

Throws:
IOException - A problem occurs while writing to out
Since:
5.7
See Also:
readCharArray(java.io.DataInput)

readCharArray

public static char[] readCharArray(DataInput in)
                            throws IOException
Reads an array of chars from a DataInput.

Throws:
IOException - A problem occurs while reading from in
Since:
5.7
See Also:
writeCharArray(char[], java.io.DataOutput)

writeBooleanArray

public static void writeBooleanArray(boolean[] array,
                                     DataOutput out)
                              throws IOException
Writes an array of booleans to a DataOutput.

Throws:
IOException - A problem occurs while writing to out
Since:
5.7
See Also:
readBooleanArray(java.io.DataInput)

readBooleanArray

public static boolean[] readBooleanArray(DataInput in)
                                  throws IOException
Reads an array of booleans from a DataInput.

Throws:
IOException - A problem occurs while reading from in
Since:
5.7
See Also:
writeBooleanArray(boolean[], java.io.DataOutput)

writeIntArray

public static void writeIntArray(int[] array,
                                 DataOutput out)
                          throws IOException
Writes an int array to a DataOutput. This method will serialize a null array and not throw a NullPointerException.

Throws:
IOException - A problem occurs while writing to out
See Also:
readIntArray(java.io.DataInput)

readIntArray

public static int[] readIntArray(DataInput in)
                          throws IOException
Reads an int array from a DataInput.

Throws:
IOException - A problem occurs while reading from in
See Also:
writeIntArray(int[], java.io.DataOutput)

writeLongArray

public static void writeLongArray(long[] array,
                                  DataOutput out)
                           throws IOException
Writes an array of longs to a DataOutput. This method will serialize a null array and not throw a NullPointerException.

Throws:
IOException - A problem occurs while writing to out
See Also:
readLongArray(java.io.DataInput)

readLongArray

public static long[] readLongArray(DataInput in)
                            throws IOException
Reads an array of longs from a DataInput.

Throws:
IOException - A problem occurs while reading from in
See Also:
writeLongArray(long[], java.io.DataOutput)

writeFloatArray

public static void writeFloatArray(float[] array,
                                   DataOutput out)
                            throws IOException
Writes an array of floats to a DataOutput. This method will serialize a null array and not throw a NullPointerException.

Throws:
IOException - A problem occurs while writing to out
See Also:
readFloatArray(java.io.DataInput)

readFloatArray

public static float[] readFloatArray(DataInput in)
                              throws IOException
Reads an array of floats from a DataInput.

Throws:
IOException - A problem occurs while reading from in
See Also:
writeFloatArray(float[], java.io.DataOutput)

writeDoubleArray

public static void writeDoubleArray(double[] array,
                                    DataOutput out)
                             throws IOException
Writes an array of doubles to a DataOutput. This method will serialize a null array and not throw a NullPointerException.

Throws:
IOException - A problem occurs while writing to out
See Also:
readDoubleArray(java.io.DataInput)

readDoubleArray

public static double[] readDoubleArray(DataInput in)
                                throws IOException
Reads an array of doubles from a DataInput.

Throws:
IOException - A problem occurs while reading from in
See Also:
writeDoubleArray(double[], java.io.DataOutput)

writeObjectArray

public static void writeObjectArray(Object[] array,
                                    DataOutput out)
                             throws IOException
Writes an array of Objects to a DataOutput. This method will serialize a null array and not throw a NullPointerException.

Throws:
IOException - A problem occurs while writing to out
See Also:
readObjectArray(java.io.DataInput), writeObject(Object, DataOutput)

readObjectArray

public static Object[] readObjectArray(DataInput in)
                                throws IOException,
                                       ClassNotFoundException
Reads an array of Objects from a DataInput.

Throws:
IOException - A problem occurs while reading from in
ClassNotFoundException
See Also:
writeObjectArray(java.lang.Object[], java.io.DataOutput), readObject(java.io.DataInput)

writeArrayOfByteArrays

public static void writeArrayOfByteArrays(byte[][] array,
                                          DataOutput out)
                                   throws IOException
Writes an array of byte[] to a DataOutput.

Throws:
IOException - A problem occurs while writing to out.

readArrayOfByteArrays

public static byte[][] readArrayOfByteArrays(DataInput in)
                                      throws IOException,
                                             ClassNotFoundException
Reads an array of byte[]s from a DataInput.

Throws:
IOException - A problem occurs while reading from in
ClassNotFoundException

writeArrayList

public static void writeArrayList(ArrayList<?> list,
                                  DataOutput out)
                           throws IOException
Writes an 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.

Throws:
IOException - A problem occurs while writing to out
See Also:
readArrayList(java.io.DataInput)

readArrayList

public static <E> ArrayList<E> readArrayList(DataInput in)
                                  throws IOException,
                                         ClassNotFoundException
Reads an ArrayList from a DataInput.

Throws:
IOException - A problem occurs while reading from in
ClassNotFoundException - The class of one of the ArrayList's elements cannot be found.
See Also:
writeArrayList(java.util.ArrayList, java.io.DataOutput)

writeVector

public static void writeVector(Vector<?> list,
                               DataOutput out)
                        throws IOException
Writes an 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.

Throws:
IOException - A problem occurs while writing to out
Since:
5.7
See Also:
readVector(java.io.DataInput)

readVector

public static <E> Vector<E> readVector(DataInput in)
                            throws IOException,
                                   ClassNotFoundException
Reads an Vector from a DataInput.

Throws:
IOException - A problem occurs while reading from in
ClassNotFoundException - The class of one of the Vector's elements cannot be found.
Since:
5.7
See Also:
writeVector(java.util.Vector, java.io.DataOutput)

writeStack

public static void writeStack(Stack<?> list,
                              DataOutput out)
                       throws IOException
Writes an 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.

Throws:
IOException - A problem occurs while writing to out
Since:
5.7
See Also:
readStack(java.io.DataInput)

readStack

public static <E> Stack<E> readStack(DataInput in)
                          throws IOException,
                                 ClassNotFoundException
Reads an Stack from a DataInput.

Throws:
IOException - A problem occurs while reading from in
ClassNotFoundException - The class of one of the Stack's elements cannot be found.
Since:
5.7
See Also:
writeStack(java.util.Stack, java.io.DataOutput)

writeLinkedList

public static void writeLinkedList(LinkedList<?> list,
                                   DataOutput out)
                            throws IOException
Writes an 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.

Throws:
IOException - A problem occurs while writing to out
See Also:
readLinkedList(java.io.DataInput)

readLinkedList

public static <E> LinkedList<E> readLinkedList(DataInput in)
                                    throws IOException,
                                           ClassNotFoundException
Reads an LinkedList from a DataInput.

Throws:
IOException - A problem occurs while reading from in
ClassNotFoundException - The class of one of the LinkedList's elements cannot be found.
See Also:
writeLinkedList(java.util.LinkedList, java.io.DataOutput)

writeHashSet

public static void writeHashSet(HashSet<?> set,
                                DataOutput out)
                         throws IOException
Writes a 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.

Throws:
IOException - A problem occurs while writing to out
See Also:
readHashSet(java.io.DataInput)

readHashSet

public static <E> HashSet<E> readHashSet(DataInput in)
                              throws IOException,
                                     ClassNotFoundException
Reads a HashSet from a DataInput.

Throws:
IOException - A problem occurs while reading from in
ClassNotFoundException - The class of one of the HashSet's elements cannot be found.
See Also:
writeHashSet(java.util.HashSet, java.io.DataOutput)

writeLinkedHashSet

public static void writeLinkedHashSet(LinkedHashSet<?> set,
                                      DataOutput out)
                               throws IOException
Writes a 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.

Throws:
IOException - A problem occurs while writing to out
Since:
5.7
See Also:
readLinkedHashSet(java.io.DataInput)

readLinkedHashSet

public static <E> LinkedHashSet<E> readLinkedHashSet(DataInput in)
                                          throws IOException,
                                                 ClassNotFoundException
Reads a LinkedHashSet from a DataInput.

Throws:
IOException - A problem occurs while reading from in
ClassNotFoundException - The class of one of the LinkedHashSet's elements cannot be found.
Since:
5.7
See Also:
writeLinkedHashSet(java.util.LinkedHashSet, java.io.DataOutput)

writeHashMap

public static void writeHashMap(HashMap<?,?> map,
                                DataOutput out)
                         throws IOException
Writes a 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.

Throws:
IOException - A problem occurs while writing to out
See Also:
readHashMap(java.io.DataInput)

readHashMap

public static <K,V> HashMap<K,V> readHashMap(DataInput in)
                                throws IOException,
                                       ClassNotFoundException
Reads a HashMap from a DataInput.

Throws:
IOException - A problem occurs while reading from in
ClassNotFoundException - The class of one of the HashMap's elements cannot be found.
See Also:
writeHashMap(java.util.HashMap, java.io.DataOutput)

writeIdentityHashMap

public static void writeIdentityHashMap(IdentityHashMap<?,?> map,
                                        DataOutput out)
                                 throws IOException
Writes a 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.

Throws:
IOException - A problem occurs while writing to out
See Also:
readIdentityHashMap(java.io.DataInput)

readIdentityHashMap

public static <K,V> IdentityHashMap<K,V> readIdentityHashMap(DataInput in)
                                                throws IOException,
                                                       ClassNotFoundException
Reads a IdentityHashMap from a DataInput. Note that key identity is not preserved unless the keys belong to a class whose serialization preserves identity.

Throws:
IOException - A problem occurs while reading from in
ClassNotFoundException - The class of one of the IdentityHashMap's elements cannot be found.
See Also:
writeIdentityHashMap(java.util.IdentityHashMap, java.io.DataOutput)

writeConcurrentHashMap

public static void writeConcurrentHashMap(ConcurrentHashMap<?,?> map,
                                          DataOutput out)
                                   throws IOException
Writes a 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.

Throws:
IOException - A problem occurs while writing to out
Since:
6.6
See Also:
readConcurrentHashMap(java.io.DataInput)

readConcurrentHashMap

public static <K,V> ConcurrentHashMap<K,V> readConcurrentHashMap(DataInput in)
                                                    throws IOException,
                                                           ClassNotFoundException
Reads a ConcurrentHashMap from a DataInput.

Throws:
IOException - A problem occurs while reading from in
ClassNotFoundException - The class of one of the ConcurrentHashMap's elements cannot be found.
Since:
6.6
See Also:
writeConcurrentHashMap(java.util.concurrent.ConcurrentHashMap, java.io.DataOutput)

writeHashtable

public static void writeHashtable(Hashtable<?,?> map,
                                  DataOutput out)
                           throws IOException
Writes a 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.

Throws:
IOException - A problem occurs while writing to out
Since:
5.7
See Also:
readHashtable(java.io.DataInput)

readHashtable

public static <K,V> Hashtable<K,V> readHashtable(DataInput in)
                                    throws IOException,
                                           ClassNotFoundException
Reads a Hashtable from a DataInput.

Throws:
IOException - A problem occurs while reading from in
ClassNotFoundException - The class of one of the Hashtable's elements cannot be found.
Since:
5.7
See Also:
writeHashtable(java.util.Hashtable, java.io.DataOutput)

writeTreeMap

public static void writeTreeMap(TreeMap<?,?> map,
                                DataOutput out)
                         throws IOException
Writes a 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.

Throws:
IOException - A problem occurs while writing to out
Since:
5.7
See Also:
readTreeMap(java.io.DataInput)

readTreeMap

public static <K,V> TreeMap<K,V> readTreeMap(DataInput in)
                                throws IOException,
                                       ClassNotFoundException
Reads a TreeMap from a DataInput.

Throws:
IOException - A problem occurs while reading from in
ClassNotFoundException - The class of one of the TreeMap's elements cannot be found.
Since:
5.7
See Also:
writeTreeMap(java.util.TreeMap, java.io.DataOutput)

writeTreeSet

public static void writeTreeSet(TreeSet<?> set,
                                DataOutput out)
                         throws IOException
Writes a 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.

Throws:
IOException - A problem occurs while writing to out
See Also:
readTreeSet(java.io.DataInput)

readTreeSet

public static <E> TreeSet<E> readTreeSet(DataInput in)
                              throws IOException,
                                     ClassNotFoundException
Reads a TreeSet from a DataInput.

Throws:
IOException - A problem occurs while reading from in
ClassNotFoundException - The class of one of the TreeSet's elements cannot be found.
See Also:
writeTreeSet(java.util.TreeSet, java.io.DataOutput)

writeProperties

public static void writeProperties(Properties props,
                                   DataOutput out)
                            throws IOException
Writes a 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.

Throws:
IOException - A problem occurs while writing to out
See Also:
readProperties(java.io.DataInput)

readProperties

public static Properties readProperties(DataInput in)
                                 throws IOException,
                                        ClassNotFoundException
Reads a Properties from a DataInput.

NOTE: the defaults are always empty in the returned Properties.

Throws:
IOException - A problem occurs while reading from in
ClassNotFoundException
See Also:
writeProperties(java.util.Properties, java.io.DataOutput)

writeObject

public static final void writeObject(Object o,
                                     DataOutput out,
                                     boolean allowJavaSerialization)
                              throws IOException
Writes an arbitrary object to a 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.

Parameters:
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 client
Throws:
IOException - A problem occurs while writing o to out
See Also:
readObject(DataInput), Instantiator, ObjectOutputStream.writeObject(java.lang.Object)

writeObject

public static final void writeObject(Object o,
                                     DataOutput out)
                              throws IOException
Writes an arbitrary object to a 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.

Throws:
IOException - A problem occurs while writing o to out
See Also:
readObject(DataInput), DataSerializer, ObjectOutputStream.writeObject(java.lang.Object)

readObject

public static final <T> T readObject(DataInput in)
                          throws IOException,
                                 ClassNotFoundException
Reads an arbitrary object from a 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.

Throws:
IOException - A problem occured while reading from in (may wrap another exception)
ClassNotFoundException - The class of an object read from in could not be found
See Also:
writeObject(Object, DataOutput), ObjectInputStream.readObject()

register

public static final DataSerializer register(Class<?> c)
Registers a 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.

Parameters:
c - the DataSerializer class to create and register with the data serialization framework.
Returns:
the registered serializer instance
Throws:
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 elements
IllegalStateException - 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).
See Also:
getSupportedClasses()

register

@Deprecated
public static final DataSerializer register(Class<?> c,
                                                       byte b)
Deprecated. as of 5.7 use register(Class) instead


getSupportedClasses

public abstract Class<?>[] getSupportedClasses()
Returns the Classes 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 DataSerializers 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:


toData

public abstract boolean toData(Object o,
                               DataOutput out)
                        throws IOException
Data serializes an object to a 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.

Parameters:
o - The object to data serialize. It will never be null.
Returns:
false if this DataSerializer does not know how to data serialize o.
Throws:
IOException

fromData

public abstract Object fromData(DataInput in)
                         throws IOException,
                                ClassNotFoundException
Reads an object from a DataInput. This implementation must support deserializing everything serialized by the matching toData(java.lang.Object, java.io.DataOutput).

Throws:
IOException - If this serializer cannot read an object from in.
ClassNotFoundException
See Also:
toData(java.lang.Object, java.io.DataOutput)

getId

public abstract int getId()
Returns the id of this DataSerializer.

Returns an int instead of a byte since 5.7.


equals

public boolean equals(Object o)
Two DataSerializers are consider to be equal if they have the same id and the same class

Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

setEventId

public final void setEventId(Object eventId)
For internal use only. Sets the unique eventId of this DataSerializer.

Since:
6.5

getEventId

public final Object getEventId()
For internal use only. Returns the unique eventId of this DataSerializer.

Since:
6.5

setContext

public final void setContext(Object context)
For internal use only. Sets the context of this DataSerializer.

Since:
6.5

getContext

public final Object getContext()
For internal use only. Returns the context of this DataSerializer.

Since:
6.5

writeEnum

public static void writeEnum(Enum e,
                             DataOutput out)
                      throws IOException
Writes the 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.
Example: DataSerializer.writeEnum(DAY_OF_WEEK.SUN, out);

Throws:
IOException
Since:
6.5
See Also:
readEnum(Class, DataInput)

readEnum

public static <E extends Enum<E>> E readEnum(Class<E> clazz,
                                             DataInput in)
                                  throws IOException
Reads a 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.
Example: DAY_OF_WEEK d = DataSerializer.readEnum(DAY_OF_WEEK.class, in);

Throws:
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 used
Since:
6.5
See Also:
writeEnum(Enum, DataOutput)

GemFire 6.6.3

Copyright © 1997-2012 VMware, Inc. All rights reserved.