VMware GemFire Java API Reference
Class DataSerializer
- java.lang.Object
-
- org.apache.geode.DataSerializer
-
public abstract class DataSerializer extends java.lang.ObjectProvides static helper methods for reading and writing non-primitive data when working with aDataSerializable. For instance, classes that implementDataSerializablecan use theDataSerializerin theirtoDataandfromDatamethods: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
DataSerializerare 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 theDataSerializableinterface.The following
DataSerializerdata serializes instances ofCompany. 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 likeInstantiators, aDataSerializermay be sent to other members of the distributed system when it is registered. The data serialization framework does not require that aDataSerializerbeSerializable, but it does require that it provide a zero-argument constructor.- Since:
- GemFire 3.5
- See Also:
writeObject(Object, DataOutput),readObject(java.io.DataInput)
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.ThreadLocal<java.lang.Boolean>DISALLOW_JAVA_SERIALIZATIONprotected static byteDOUBLEprotected static byteINTprotected static byteLONGprotected static bytePRESENTprotected static booleanTRACE_SERIALIZABLEDeprecated.Use Boolean.getBoolean("DataSerializer.TRACE_SERIALIZABLE") instead.
-
Constructor Summary
Constructors Constructor Description DataSerializer()Creates a newDataSerializer.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleanequals(java.lang.Object o)TwoDataSerializers are consider to be equal if they have the same id and the same classabstract java.lang.ObjectfromData(java.io.DataInput in)Reads an object from aDataInput.java.lang.ObjectgetContext()For internal use only.java.lang.ObjectgetEventId()For internal use only.abstract intgetId()Returns the id of thisDataSerializer.abstract java.lang.Class<?>[]getSupportedClasses()Returns theClasses whose instances are data serialized by thisDataSerializer.inthashCode()static <E> java.util.ArrayList<E>readArrayList(java.io.DataInput in)Reads anArrayListfrom aDataInput.static byte[][]readArrayOfByteArrays(java.io.DataInput in)Reads an array ofbyte[]s from aDataInput.static java.lang.BooleanreadBoolean(java.io.DataInput in)Reads an instance ofBooleanfrom aDataInput.static boolean[]readBooleanArray(java.io.DataInput in)Reads an array ofbooleans from aDataInput.static java.lang.BytereadByte(java.io.DataInput in)Reads an instance ofBytefrom aDataInput.static byte[]readByteArray(java.io.DataInput in)Reads an array ofbytes from aDataInput.static java.lang.CharacterreadCharacter(java.io.DataInput in)Reads an instance ofCharacterfrom aDataInput.static char[]readCharArray(java.io.DataInput in)Reads an array ofchars from aDataInput.static java.lang.Class<?>readClass(java.io.DataInput in)Reads an instance ofClassfrom aDataInput.static <K,V>
java.util.concurrent.ConcurrentHashMap<K,V>readConcurrentHashMap(java.io.DataInput in)Reads aConcurrentHashMapfrom aDataInput.static java.util.DatereadDate(java.io.DataInput in)Reads an instance ofDatefrom aDataInput.static java.lang.DoublereadDouble(java.io.DataInput in)Reads an instance ofDoublefrom aDataInput.static double[]readDoubleArray(java.io.DataInput in)Reads an array ofdoubles from aDataInput.static <E extends java.lang.Enum<E>>
EreadEnum(java.lang.Class<E> clazz, java.io.DataInput in)Reads anEnum constantfromDataInput.static java.io.FilereadFile(java.io.DataInput in)Reads an instance ofFilefrom aDataInput.static java.lang.FloatreadFloat(java.io.DataInput in)Reads an instance ofFloatfrom aDataInput.static float[]readFloatArray(java.io.DataInput in)Reads an array offloats from aDataInput.static <K,V>
java.util.HashMap<K,V>readHashMap(java.io.DataInput in)Reads aHashMapfrom aDataInput.static <E> java.util.HashSet<E>readHashSet(java.io.DataInput in)Reads aHashSetfrom aDataInput.static <K,V>
java.util.Hashtable<K,V>readHashtable(java.io.DataInput in)Reads aHashtablefrom aDataInput.static <K,V>
java.util.IdentityHashMap<K,V>readIdentityHashMap(java.io.DataInput in)Reads anIdentityHashMapfrom aDataInput.static java.net.InetAddressreadInetAddress(java.io.DataInput in)Reads an instance ofInetAddressfrom aDataInput.static int[]readIntArray(java.io.DataInput in)Reads anintarray from aDataInput.static java.lang.IntegerreadInteger(java.io.DataInput in)Reads an instance ofIntegerfrom aDataInput.static <K,V>
java.util.LinkedHashMap<K,V>readLinkedHashMap(java.io.DataInput in)Reads aLinkedHashMapfrom aDataInput.static <E> java.util.LinkedHashSet<E>readLinkedHashSet(java.io.DataInput in)Reads aLinkedHashSetfrom aDataInput.static <E> java.util.LinkedList<E>readLinkedList(java.io.DataInput in)Reads aLinkedListfrom aDataInput.static java.lang.LongreadLong(java.io.DataInput in)Reads an instance ofLongfrom aDataInput.static long[]readLongArray(java.io.DataInput in)Reads an array oflongs from aDataInput.static java.lang.StringreadNonPrimitiveClassName(java.io.DataInput in)Reads name of an instance ofClassfrom aDataInput.static <T> TreadObject(java.io.DataInput in)Reads an arbitrary object from aDataInput.static java.lang.Object[]readObjectArray(java.io.DataInput in)Reads an array ofObjects from aDataInput.static <T> java.util.Optional<T>readOptional(java.io.DataInput in)Reads anOptionalfrom aDataInput.static java.util.OptionalDoublereadOptionalDouble(java.io.DataInput in)Reads anOptionalDoublefrom aDataInput.static java.util.OptionalIntreadOptionalInt(java.io.DataInput in)Reads anOptionalIntfrom aDataInput.static java.util.OptionalLongreadOptionalLong(java.io.DataInput in)Reads anOptionalLongfrom aDataInput.protected static <T> TreadOptionalPrimitive(java.io.DataInput in)static booleanreadPrimitiveBoolean(java.io.DataInput in)Reads a primitivebooleanfrom aDataInput.static bytereadPrimitiveByte(java.io.DataInput in)Reads a primitivebytefrom aDataInput.static charreadPrimitiveChar(java.io.DataInput in)Reads a primitivecharfrom aDataInput.static doublereadPrimitiveDouble(java.io.DataInput in)Reads a primitivedoublefrom aDataInput.static floatreadPrimitiveFloat(java.io.DataInput in)Reads a primitivefloatfrom aDataInput.static intreadPrimitiveInt(java.io.DataInput in)Reads a primitiveintfrom aDataInput.static longreadPrimitiveLong(java.io.DataInput in)Reads a primitivelongfrom aDataInput.static shortreadPrimitiveShort(java.io.DataInput in)Reads a primitiveshortfrom aDataInput.static java.util.PropertiesreadProperties(java.io.DataInput in)Reads aPropertiesfrom aDataInput.static <K,V>
Region<K,V>readRegion(java.io.DataInput in)Reads an instance of Region.static java.lang.ShortreadShort(java.io.DataInput in)Reads an instance ofShortfrom aDataInput.static short[]readShortArray(java.io.DataInput in)Reads an array ofshorts from aDataInput.static <E> java.util.Stack<E>readStack(java.io.DataInput in)Reads aStackfrom aDataInput.static java.lang.StringreadString(java.io.DataInput in)Reads an instance ofStringfrom aDataInput.static java.lang.String[]readStringArray(java.io.DataInput in)Reads an array ofStrings from aDataInput.static <K,V>
java.util.TreeMap<K,V>readTreeMap(java.io.DataInput in)Reads aTreeMapfrom aDataInput.static <E> java.util.TreeSet<E>readTreeSet(java.io.DataInput in)Reads aTreeSetfrom aDataInput.static intreadUnsignedByte(java.io.DataInput in)Reads a primitiveintas an unsigned byte from aDataInputusingDataInput.readUnsignedByte().static intreadUnsignedShort(java.io.DataInput in)Reads a primitiveintas an unsigned short from aDataInputusingDataInput.readUnsignedShort().static <E> java.util.Vector<E>readVector(java.io.DataInput in)Reads aVectorfrom aDataInput.static DataSerializerregister(java.lang.Class<?> c)Registers aDataSerializerclass with the data serialization framework.voidsetContext(java.lang.Object context)For internal use only.voidsetEventId(java.lang.Object eventId)For internal use only.abstract booleantoData(java.lang.Object o, java.io.DataOutput out)Data serializes an object to aDataOutput.static voidwriteArrayList(java.util.ArrayList<?> list, java.io.DataOutput out)Writes anArrayListto aDataOutput.static voidwriteArrayOfByteArrays(byte[][] array, java.io.DataOutput out)Writes an array ofbyte[]to aDataOutput.static voidwriteBoolean(java.lang.Boolean value, java.io.DataOutput out)Writes an instance ofBooleanto aDataOutput.static voidwriteBooleanArray(boolean[] array, java.io.DataOutput out)Writes an array ofbooleans to aDataOutput.static voidwriteByte(java.lang.Byte value, java.io.DataOutput out)Writes an instance ofByteto aDataOutput.static voidwriteByteArray(byte[] array, int len, java.io.DataOutput out)Writes the firstlenelements of an array ofbytes to aDataOutput.static voidwriteByteArray(byte[] array, java.io.DataOutput out)Writes an array ofbytes to aDataOutput.static voidwriteCharacter(java.lang.Character value, java.io.DataOutput out)Writes an instance ofCharacterto aDataOutput.static voidwriteCharArray(char[] array, java.io.DataOutput out)Writes an array ofchars to aDataOutput.static voidwriteClass(java.lang.Class<?> c, java.io.DataOutput out)Writes an instance ofClassto aDataOutput.static voidwriteConcurrentHashMap(java.util.concurrent.ConcurrentHashMap<?,?> map, java.io.DataOutput out)Writes aConcurrentHashMapto aDataOutput.static voidwriteDate(java.util.Date date, java.io.DataOutput out)Writes an instance ofDateto aDataOutput.static voidwriteDouble(java.lang.Double value, java.io.DataOutput out)Writes an instance ofDoubleto aDataOutput.static voidwriteDoubleArray(double[] array, java.io.DataOutput out)Writes an array ofdoubles to aDataOutput.static voidwriteEnum(java.lang.Enum<?> e, java.io.DataOutput out)Writes theEnum constanttoDataOutput.static voidwriteFile(java.io.File file, java.io.DataOutput out)Writes an instance ofFileto aDataOutput.static voidwriteFloat(java.lang.Float value, java.io.DataOutput out)Writes an instance ofFloatto aDataOutput.static voidwriteFloatArray(float[] array, java.io.DataOutput out)Writes an array offloats to aDataOutput.static voidwriteHashMap(java.util.Map<?,?> map, java.io.DataOutput out)Writes aHashMapto aDataOutput.static voidwriteHashSet(java.util.HashSet<?> set, java.io.DataOutput out)Writes aHashSetto aDataOutput.static voidwriteHashtable(java.util.Hashtable<?,?> map, java.io.DataOutput out)Writes aHashtableto aDataOutput.static voidwriteIdentityHashMap(java.util.IdentityHashMap<?,?> map, java.io.DataOutput out)Writes anIdentityHashMapto aDataOutput.static voidwriteInetAddress(java.net.InetAddress address, java.io.DataOutput out)Writes an instance ofInetAddressto aDataOutput.static voidwriteIntArray(int[] array, java.io.DataOutput out)Writes anintarray to aDataOutput.static voidwriteInteger(java.lang.Integer value, java.io.DataOutput out)Writes an instance ofIntegerto aDataOutput.static voidwriteLinkedHashMap(java.util.Map<?,?> map, java.io.DataOutput out)Writes aLinkedHashMapto aDataOutput.static voidwriteLinkedHashSet(java.util.LinkedHashSet<?> set, java.io.DataOutput out)Writes aLinkedHashSetto aDataOutput.static voidwriteLinkedList(java.util.LinkedList<?> list, java.io.DataOutput out)Writes aLinkedListto aDataOutput.static voidwriteLong(java.lang.Long value, java.io.DataOutput out)Writes an instance ofLongto aDataOutput.static voidwriteLongArray(long[] array, java.io.DataOutput out)Writes an array oflongs to aDataOutput.static voidwriteNonPrimitiveClassName(java.lang.String className, java.io.DataOutput out)Writes class name to aDataOutput.static voidwriteObject(java.lang.Object o, java.io.DataOutput out)Writes an arbitrary object to aDataOutputby callingwriteObject(Object, DataOutput, boolean)withtrue.static voidwriteObject(java.lang.Object o, java.io.DataOutput out, boolean allowJavaSerialization)Writes an arbitrary object to aDataOutputby serializing it into bytes.static voidwriteObjectArray(java.lang.Object[] array, java.io.DataOutput out)Writes an array ofObjects to aDataOutput.static voidwriteObjectAsByteArray(java.lang.Object obj, java.io.DataOutput out)Serialize the given objectobjinto a byte array usingwriteObject(Object, DataOutput)and then writes the byte array to the given data outputoutin the same formatwriteByteArray(byte[], DataOutput)does.static <T> voidwriteOptional(java.util.Optional<T> o, java.io.DataOutput out)Writes anOptionalto aDataOutput.static voidwriteOptionalDouble(java.util.OptionalDouble o, java.io.DataOutput out)Writes anOptionalDoubleto aDataOutput.static voidwriteOptionalInt(java.util.OptionalInt o, java.io.DataOutput out)Writes anOptionalIntto aDataOutput.static voidwriteOptionalLong(java.util.OptionalLong o, java.io.DataOutput out)Writes anOptionalLongto aDataOutput.static voidwritePrimitiveBoolean(boolean value, java.io.DataOutput out)Writes a primitivebooleanto aDataOutput.static voidwritePrimitiveByte(byte value, java.io.DataOutput out)Writes a primitivebyteto aDataOutput.static voidwritePrimitiveChar(char value, java.io.DataOutput out)Writes a primitivecharto aDataOutput.static voidwritePrimitiveDouble(double value, java.io.DataOutput out)Writes a primitivedoubleto aDataOutput.static voidwritePrimitiveFloat(float value, java.io.DataOutput out)Writes a primitivefloatto aDataOutput.static voidwritePrimitiveInt(int value, java.io.DataOutput out)Writes a primitiveintto aDataOutput.static voidwritePrimitiveLong(long value, java.io.DataOutput out)Writes a primitivelongto aDataOutput.static voidwritePrimitiveShort(short value, java.io.DataOutput out)Writes a primitiveshortto aDataOutput.static voidwriteProperties(java.util.Properties props, java.io.DataOutput out)Writes aPropertiesto aDataOutput.static voidwriteRegion(Region<?,?> rgn, java.io.DataOutput out)Writes an instance of Region.static voidwriteShort(java.lang.Short value, java.io.DataOutput out)Writes an instance ofShortto aDataOutput.static voidwriteShortArray(short[] array, java.io.DataOutput out)Writes an array ofshorts to aDataOutput.static voidwriteStack(java.util.Stack<?> list, java.io.DataOutput out)Writes aStackto aDataOutput.static voidwriteString(java.lang.String value, java.io.DataOutput out)Writes an instance ofStringto aDataOutput.static voidwriteStringArray(java.lang.String[] array, java.io.DataOutput out)Writes an array ofStrings to aDataOutput.static voidwriteTreeMap(java.util.TreeMap<?,?> map, java.io.DataOutput out)Writes aTreeMapto aDataOutput.static voidwriteTreeSet(java.util.TreeSet<?> set, java.io.DataOutput out)Writes aTreeSetto aDataOutput.static voidwriteUnsignedByte(int value, java.io.DataOutput out)Writes a primitiveintas an unsigned byte to aDataOutput.static voidwriteUnsignedShort(int value, java.io.DataOutput out)Writes a primitiveintas an unsigned short to aDataOutput.static voidwriteVector(java.util.Vector<?> list, java.io.DataOutput out)Writes aVectorto aDataOutput.
-
-
-
Field Detail
-
PRESENT
protected static final byte PRESENT
- See Also:
- Constant Field Values
-
INT
protected static final byte INT
- See Also:
- Constant Field Values
-
LONG
protected static final byte LONG
- See Also:
- Constant Field Values
-
DOUBLE
protected static final byte DOUBLE
- See Also:
- Constant Field Values
-
TRACE_SERIALIZABLE
@Deprecated protected static final boolean TRACE_SERIALIZABLE
Deprecated.Use Boolean.getBoolean("DataSerializer.TRACE_SERIALIZABLE") instead.
-
DISALLOW_JAVA_SERIALIZATION
protected static final java.lang.ThreadLocal<java.lang.Boolean> DISALLOW_JAVA_SERIALIZATION
-
-
Constructor Detail
-
DataSerializer
public DataSerializer()
Creates a newDataSerializer. All class that implementDataSerializermust provide a zero-argument constructor.- See Also:
register(Class)
-
-
Method Detail
-
writeClass
public static void writeClass(java.lang.Class<?> c, java.io.DataOutput out) throws java.io.IOExceptionWrites an instance ofClassto aDataOutput. This method will handle anullvalue and not throw aNullPointerException.- Parameters:
c- theClassto writeout- theDataInputto write to- Throws:
java.io.IOException- A problem occurs while writing toout- See Also:
readClass(java.io.DataInput)
-
writeNonPrimitiveClassName
public static void writeNonPrimitiveClassName(java.lang.String className, java.io.DataOutput out) throws java.io.IOExceptionWrites class name to aDataOutput. This method will handle anullvalue and not throw aNullPointerException.- Parameters:
className- the class name to writeout- theDataInputto write to- Throws:
java.io.IOException- A problem occurs while writing toout- See Also:
readNonPrimitiveClassName(DataInput)
-
readClass
public static java.lang.Class<?> readClass(java.io.DataInput in) throws java.io.IOException, java.lang.ClassNotFoundExceptionReads an instance ofClassfrom aDataInput. The class will be loaded using the current content class loader. The return value may benull.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized
Class - Throws:
java.io.IOException- A problem occurs while reading frominjava.lang.ClassNotFoundException- The class cannot be loaded
-
readNonPrimitiveClassName
public static java.lang.String readNonPrimitiveClassName(java.io.DataInput in) throws java.io.IOExceptionReads name of an instance ofClassfrom aDataInput. The return value may benull.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized Class name
- Throws:
java.io.IOException- A problem occurs while reading fromin- See Also:
writeNonPrimitiveClassName(String, DataOutput)
-
writeRegion
public static void writeRegion(Region<?,?> rgn, java.io.DataOutput out) throws java.io.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 callingCacheFactory.getAnyInstance()and then callinggetRegionon it. This method will handle anullvalue and not throw aNullPointerException.- Parameters:
rgn- the Region to writeout- theDataInputto write to- Throws:
java.io.IOException- if a problem occurs while reading fromin
-
readRegion
public static <K,V> Region<K,V> readRegion(java.io.DataInput in) throws java.io.IOException, java.lang.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 callingCacheFactory.getAnyInstance()and then callinggetRegionon it. The return value may benull.- Type Parameters:
K- the type of keys in the regionV- the type of values in the region- 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. Since this exception is deprecated, please seeRegionNotFoundExceptionfor alternatives.java.io.IOException- if a problem occurs while reading frominjava.lang.ClassNotFoundException- if the class of one of the Region's elements cannot be found.
-
writeDate
public static void writeDate(java.util.Date date, java.io.DataOutput out) throws java.io.IOExceptionWrites an instance ofDateto aDataOutput. Note that even thoughdatemay be an instance of a subclass ofDate,readDatewill always return an instance ofDate, not an instance of the subclass. To preserve the class type ofdate,\writeObject(Object, DataOutput)should be used for data serialization. This method will handle anullvalue and not throw aNullPointerException.- Parameters:
date- theDateto writeout- theDataInputto write to- Throws:
java.io.IOException- A problem occurs while writing toout- See Also:
readDate(java.io.DataInput)
-
readDate
public static java.util.Date readDate(java.io.DataInput in) throws java.io.IOExceptionReads an instance ofDatefrom aDataInput. The return value may benull.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized
Date - Throws:
java.io.IOException- A problem occurs while reading fromin
-
writeFile
public static void writeFile(java.io.File file, java.io.DataOutput out) throws java.io.IOExceptionWrites an instance ofFileto aDataOutput. Note that even thoughfilemay be an instance of a subclass ofFile,readFilewill always return an instance ofFile, not an instance of the subclass. To preserve the class type offile,writeObject(Object, DataOutput)should be used for data serialization. This method will handle anullvalue and not throw aNullPointerException.- Parameters:
file- theFileto writeout- theDataInputto write to- Throws:
java.io.IOException- A problem occurs while writing toout- See Also:
readFile(java.io.DataInput),File.getCanonicalPath()
-
readFile
public static java.io.File readFile(java.io.DataInput in) throws java.io.IOExceptionReads an instance ofFilefrom aDataInput. The return value may benull.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized
File - Throws:
java.io.IOException- A problem occurs while reading fromin
-
writeInetAddress
public static void writeInetAddress(java.net.InetAddress address, java.io.DataOutput out) throws java.io.IOExceptionWrites an instance ofInetAddressto aDataOutput. TheInetAddressis data serialized by writing itsbyterepresentation to theDataOutput.readInetAddress(java.io.DataInput)converts thebyterepresentation to an instance ofInetAddressusingInetAddress.getAddress(). As a result, ifaddressis an instance of a user-defined subclass ofInetAddress(that is, not an instance of one of the subclasses from thejava.netpackage), 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 anullvalue and not throw aNullPointerException.- Parameters:
address- theInetAddressto writeout- theDataInputto write to- Throws:
java.io.IOException- A problem occurs while writing toout- See Also:
readInetAddress(java.io.DataInput)
-
readInetAddress
public static java.net.InetAddress readInetAddress(java.io.DataInput in) throws java.io.IOExceptionReads an instance ofInetAddressfrom aDataInput. The return value may benull.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized
InetAddress - Throws:
java.io.IOException- A problem occurs while reading frominor the address read frominis unknown- See Also:
InetAddress.getAddress()
-
writeString
public static void writeString(java.lang.String value, java.io.DataOutput out) throws java.io.IOExceptionWrites an instance ofStringto aDataOutput. This method will handle anullvalue and not throw aNullPointerException.As of 5.7 strings longer than 0xFFFF can be serialized.
- Parameters:
value- theStringto writeout- theDataInputto write to- Throws:
java.io.IOException- A problem occurs while writing toout- See Also:
readString(java.io.DataInput)
-
readString
public static java.lang.String readString(java.io.DataInput in) throws java.io.IOExceptionReads an instance ofStringfrom aDataInput. The return value may benull.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized
String - Throws:
java.io.IOException- A problem occurs while reading fromin- See Also:
writeString(java.lang.String, java.io.DataOutput)
-
writeBoolean
public static void writeBoolean(java.lang.Boolean value, java.io.DataOutput out) throws java.io.IOExceptionWrites an instance ofBooleanto aDataOutput.- Parameters:
value- theBooleanto writeout- theDataInputto write to- Throws:
java.io.IOException- A problem occurs while writing tooutjava.lang.NullPointerException- if value is null.- See Also:
readBoolean(java.io.DataInput)
-
readBoolean
public static java.lang.Boolean readBoolean(java.io.DataInput in) throws java.io.IOExceptionReads an instance ofBooleanfrom aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized
Boolean - Throws:
java.io.IOException- A problem occurs while reading fromin
-
writeCharacter
public static void writeCharacter(java.lang.Character value, java.io.DataOutput out) throws java.io.IOExceptionWrites an instance ofCharacterto aDataOutput.- Parameters:
value- theCharacterto writeout- theDataInputto write to- Throws:
java.io.IOException- A problem occurs while writing tooutjava.lang.NullPointerException- if value is null.- See Also:
readCharacter(java.io.DataInput)
-
readCharacter
public static java.lang.Character readCharacter(java.io.DataInput in) throws java.io.IOExceptionReads an instance ofCharacterfrom aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized
Character - Throws:
java.io.IOException- A problem occurs while reading fromin
-
writeByte
public static void writeByte(java.lang.Byte value, java.io.DataOutput out) throws java.io.IOExceptionWrites an instance ofByteto aDataOutput.- Parameters:
value- theByteto writeout- theDataInputto write to- Throws:
java.io.IOException- A problem occurs while writing tooutjava.lang.NullPointerException- if value is null.- See Also:
readByte(java.io.DataInput)
-
readByte
public static java.lang.Byte readByte(java.io.DataInput in) throws java.io.IOExceptionReads an instance ofBytefrom aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized
Byte - Throws:
java.io.IOException- A problem occurs while reading fromin
-
writeShort
public static void writeShort(java.lang.Short value, java.io.DataOutput out) throws java.io.IOExceptionWrites an instance ofShortto aDataOutput.- Parameters:
value- theShortto writeout- theDataInputto write to- Throws:
java.io.IOException- A problem occurs while writing tooutjava.lang.NullPointerException- if value is null.- See Also:
readShort(java.io.DataInput)
-
readShort
public static java.lang.Short readShort(java.io.DataInput in) throws java.io.IOExceptionReads an instance ofShortfrom aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized
Short - Throws:
java.io.IOException- A problem occurs while reading fromin
-
writeInteger
public static void writeInteger(java.lang.Integer value, java.io.DataOutput out) throws java.io.IOExceptionWrites an instance ofIntegerto aDataOutput.- Parameters:
value- theIntegerto writeout- theDataInputto write to- Throws:
java.io.IOException- A problem occurs while writing tooutjava.lang.NullPointerException- if value is null.- See Also:
readInteger(java.io.DataInput)
-
readInteger
public static java.lang.Integer readInteger(java.io.DataInput in) throws java.io.IOExceptionReads an instance ofIntegerfrom aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized
Integer - Throws:
java.io.IOException- A problem occurs while reading fromin
-
writeLong
public static void writeLong(java.lang.Long value, java.io.DataOutput out) throws java.io.IOExceptionWrites an instance ofLongto aDataOutput.- Parameters:
value- theLongto writeout- theDataInputto write to- Throws:
java.io.IOException- A problem occurs while writing tooutjava.lang.NullPointerException- if value is null.- See Also:
readLong(java.io.DataInput)
-
readLong
public static java.lang.Long readLong(java.io.DataInput in) throws java.io.IOExceptionReads an instance ofLongfrom aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized
Long - Throws:
java.io.IOException- A problem occurs while reading fromin
-
writeFloat
public static void writeFloat(java.lang.Float value, java.io.DataOutput out) throws java.io.IOExceptionWrites an instance ofFloatto aDataOutput.- Parameters:
value- theFloatto writeout- theDataInputto write to- Throws:
java.io.IOException- A problem occurs while writing tooutjava.lang.NullPointerException- if value is null.- See Also:
readFloat(java.io.DataInput)
-
readFloat
public static java.lang.Float readFloat(java.io.DataInput in) throws java.io.IOExceptionReads an instance ofFloatfrom aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized
Float - Throws:
java.io.IOException- A problem occurs while reading fromin
-
writeDouble
public static void writeDouble(java.lang.Double value, java.io.DataOutput out) throws java.io.IOExceptionWrites an instance ofDoubleto aDataOutput.- Parameters:
value- theDoubleto writeout- theDataInputto write to- Throws:
java.io.IOException- A problem occurs while writing tooutjava.lang.NullPointerException- if value is null.- See Also:
readDouble(java.io.DataInput)
-
readDouble
public static java.lang.Double readDouble(java.io.DataInput in) throws java.io.IOExceptionReads an instance ofDoublefrom aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized
Double - Throws:
java.io.IOException- A problem occurs while reading fromin
-
writePrimitiveBoolean
public static void writePrimitiveBoolean(boolean value, java.io.DataOutput out) throws java.io.IOExceptionWrites a primitivebooleanto aDataOutput.- Parameters:
value- the primitivebooleanto writeout- theDataInputto write to- Throws:
java.io.IOException- A problem occurs while writing toout- Since:
- GemFire 5.1
- See Also:
DataOutput.writeBoolean(boolean)
-
readPrimitiveBoolean
public static boolean readPrimitiveBoolean(java.io.DataInput in) throws java.io.IOExceptionReads a primitivebooleanfrom aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized primitive
boolean - Throws:
java.io.IOException- A problem occurs while reading fromin- Since:
- GemFire 5.1
- See Also:
DataInput.readBoolean()
-
writePrimitiveByte
public static void writePrimitiveByte(byte value, java.io.DataOutput out) throws java.io.IOExceptionWrites a primitivebyteto aDataOutput.- Parameters:
value- the primitivebyteto writeout- theDataInputto write to- Throws:
java.io.IOException- A problem occurs while writing toout- Since:
- GemFire 5.1
- See Also:
DataOutput.writeByte(int)
-
readPrimitiveByte
public static byte readPrimitiveByte(java.io.DataInput in) throws java.io.IOExceptionReads a primitivebytefrom aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized primitive
byte - Throws:
java.io.IOException- A problem occurs while reading fromin- Since:
- GemFire 5.1
- See Also:
DataInput.readByte()
-
writePrimitiveChar
public static void writePrimitiveChar(char value, java.io.DataOutput out) throws java.io.IOExceptionWrites a primitivecharto aDataOutput.- Parameters:
value- the primitivecharto writeout- theDataInputto write to- Throws:
java.io.IOException- A problem occurs while writing toout- Since:
- GemFire 5.1
- See Also:
DataOutput.writeChar(int)
-
readPrimitiveChar
public static char readPrimitiveChar(java.io.DataInput in) throws java.io.IOExceptionReads a primitivecharfrom aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized primitive
char - Throws:
java.io.IOException- A problem occurs while reading fromin- Since:
- GemFire 5.1
- See Also:
DataInput.readChar()
-
writePrimitiveShort
public static void writePrimitiveShort(short value, java.io.DataOutput out) throws java.io.IOExceptionWrites a primitiveshortto aDataOutput.- Parameters:
value- the primitiveshortto writeout- theDataInputto write to- Throws:
java.io.IOException- A problem occurs while writing toout- Since:
- GemFire 5.1
- See Also:
DataOutput.writeShort(int)
-
readPrimitiveShort
public static short readPrimitiveShort(java.io.DataInput in) throws java.io.IOExceptionReads a primitiveshortfrom aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized primitive
short - Throws:
java.io.IOException- A problem occurs while reading fromin- Since:
- GemFire 5.1
- See Also:
DataInput.readShort()
-
writeUnsignedByte
public static void writeUnsignedByte(int value, java.io.DataOutput out) throws java.io.IOExceptionWrites a primitiveintas an unsigned byte to aDataOutput.- Parameters:
value- the primitiveintas an unsigned byte to writeout- theDataInputto write to- Throws:
java.io.IOException- A problem occurs while writing toout- Since:
- GemFire 5.1
- See Also:
DataOutput.writeByte(int),DataInput.readUnsignedByte()
-
readUnsignedByte
public static int readUnsignedByte(java.io.DataInput in) throws java.io.IOExceptionReads a primitiveintas an unsigned byte from aDataInputusingDataInput.readUnsignedByte().- Parameters:
in- theDataInputto read from- Returns:
- the deserialized primitive
intas an unsigned byte - Throws:
java.io.IOException- A problem occurs while reading fromin- Since:
- GemFire 5.1
-
writeUnsignedShort
public static void writeUnsignedShort(int value, java.io.DataOutput out) throws java.io.IOExceptionWrites a primitiveintas an unsigned short to aDataOutput.- Parameters:
value- the primitiveintas an unsigned short to writeout- theDataInputto write to- Throws:
java.io.IOException- A problem occurs while writing toout- Since:
- GemFire 5.1
- See Also:
DataOutput.writeShort(int),DataInput.readUnsignedShort()
-
readUnsignedShort
public static int readUnsignedShort(java.io.DataInput in) throws java.io.IOExceptionReads a primitiveintas an unsigned short from aDataInputusingDataInput.readUnsignedShort().- Parameters:
in- theDataInputto read from- Returns:
- the deserialized primitive
intas an unsigned short - Throws:
java.io.IOException- A problem occurs while reading fromin- Since:
- GemFire 5.1
-
writePrimitiveInt
public static void writePrimitiveInt(int value, java.io.DataOutput out) throws java.io.IOExceptionWrites a primitiveintto aDataOutput.- Parameters:
value- the primitiveintto writeout- theDataOutputto write to- Throws:
java.io.IOException- A problem occurs while writing toout- See Also:
DataOutput.writeInt(int)
-
readPrimitiveInt
public static int readPrimitiveInt(java.io.DataInput in) throws java.io.IOExceptionReads a primitiveintfrom aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- a primitive
int - Throws:
java.io.IOException- A problem occurs while reading fromin- Since:
- GemFire 5.1
- See Also:
DataInput.readInt()
-
writePrimitiveLong
public static void writePrimitiveLong(long value, java.io.DataOutput out) throws java.io.IOExceptionWrites a primitivelongto aDataOutput.- Parameters:
value- the primitivelongto writeout- theDataOutputto write to- Throws:
java.io.IOException- A problem occurs while writing toout- Since:
- GemFire 5.1
- See Also:
DataOutput.writeLong(long)
-
readPrimitiveLong
public static long readPrimitiveLong(java.io.DataInput in) throws java.io.IOExceptionReads a primitivelongfrom aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- a primitive
long - Throws:
java.io.IOException- A problem occurs while reading fromin- Since:
- GemFire 5.1
- See Also:
DataInput.readLong()
-
writePrimitiveFloat
public static void writePrimitiveFloat(float value, java.io.DataOutput out) throws java.io.IOExceptionWrites a primitivefloatto aDataOutput.- Parameters:
value- the primitivefloatto writeout- theDataOutputto write to- Throws:
java.io.IOException- A problem occurs while writing toout- Since:
- GemFire 5.1
- See Also:
DataOutput.writeFloat(float)
-
readPrimitiveFloat
public static float readPrimitiveFloat(java.io.DataInput in) throws java.io.IOExceptionReads a primitivefloatfrom aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- a primitive
float - Throws:
java.io.IOException- A problem occurs while reading fromin- Since:
- GemFire 5.1
- See Also:
DataInput.readFloat()
-
writePrimitiveDouble
public static void writePrimitiveDouble(double value, java.io.DataOutput out) throws java.io.IOExceptionWrites a primitivedoubleto aDataOutput.- Parameters:
value- the primitivedoubleto writeout- theDataOutputto write to- Throws:
java.io.IOException- A problem occurs while writing toout- Since:
- GemFire 5.1
- See Also:
DataOutput.writeDouble(double)
-
readPrimitiveDouble
public static double readPrimitiveDouble(java.io.DataInput in) throws java.io.IOExceptionReads a primitivedoublefrom aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- a primitive
double - Throws:
java.io.IOException- A problem occurs while reading fromin- Since:
- GemFire 5.1
- See Also:
DataInput.readDouble()
-
writeByteArray
public static void writeByteArray(byte[] array, java.io.DataOutput out) throws java.io.IOExceptionWrites an array ofbytes to aDataOutput. This method will serialize anullarray and not throw aNullPointerException.- Parameters:
array- the array ofbytes to writeout- theDataOutputto write to- Throws:
java.io.IOException- A problem occurs while writing toout- See Also:
readByteArray(java.io.DataInput)
-
writeByteArray
public static void writeByteArray(byte[] array, int len, java.io.DataOutput out) throws java.io.IOExceptionWrites the firstlenelements of an array ofbytes to aDataOutput. This method will serialize anullarray and not throw aNullPointerException.- Parameters:
array- the array ofbytes to writelen- the actual number of entries to write. If len is greater than then length of theout- theDataOutputto write to array then the entire array is written.- Throws:
java.io.IOException- A problem occurs while writing toout- See Also:
readByteArray(java.io.DataInput)
-
writeObjectAsByteArray
public static void writeObjectAsByteArray(java.lang.Object obj, java.io.DataOutput out) throws java.io.IOExceptionSerialize the given objectobjinto a byte array usingwriteObject(Object, DataOutput)and then writes the byte array to the given data outputoutin the same formatwriteByteArray(byte[], DataOutput)does. This method will serialize anullobj and not throw aNullPointerException.- Parameters:
obj- the object to serialize and writeout- the data output to write the byte array to- Throws:
java.lang.IllegalArgumentException- if a problem occurs while serializeobjjava.io.IOException- if a problem occurs while writing toout- Since:
- GemFire 5.0.2
- See Also:
readByteArray(java.io.DataInput)
-
readByteArray
public static byte[] readByteArray(java.io.DataInput in) throws java.io.IOExceptionReads an array ofbytes from aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized array of
bytes - Throws:
java.io.IOException- A problem occurs while reading fromin- See Also:
writeByteArray(byte[], DataOutput)
-
writeStringArray
public static void writeStringArray(java.lang.String[] array, java.io.DataOutput out) throws java.io.IOExceptionWrites an array ofStrings to aDataOutput. This method will serialize anullarray and not throw aNullPointerException.- Parameters:
array- the array ofStrings to writeout- theDataInputto write to- Throws:
java.io.IOException- A problem occurs while writing toout- See Also:
readStringArray(java.io.DataInput),writeString(java.lang.String, java.io.DataOutput)
-
readStringArray
public static java.lang.String[] readStringArray(java.io.DataInput in) throws java.io.IOExceptionReads an array ofStrings from aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized array of
Strings - Throws:
java.io.IOException- A problem occurs while reading fromin- See Also:
writeStringArray(java.lang.String[], java.io.DataOutput)
-
writeShortArray
public static void writeShortArray(short[] array, java.io.DataOutput out) throws java.io.IOExceptionWrites an array ofshorts to aDataOutput. This method will serialize anullarray and not throw aNullPointerException.- Parameters:
array- the array ofshorts to writeout- theDataInputto write to- Throws:
java.io.IOException- A problem occurs while writing toout- See Also:
readShortArray(java.io.DataInput)
-
readShortArray
public static short[] readShortArray(java.io.DataInput in) throws java.io.IOExceptionReads an array ofshorts from aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized array of
shorts - Throws:
java.io.IOException- A problem occurs while reading fromin- See Also:
writeShortArray(short[], java.io.DataOutput)
-
writeCharArray
public static void writeCharArray(char[] array, java.io.DataOutput out) throws java.io.IOExceptionWrites an array ofchars to aDataOutput.- Parameters:
array- the array ofchars to writeout- theDataInputto write to- Throws:
java.io.IOException- A problem occurs while writing toout- Since:
- GemFire 5.7
- See Also:
readCharArray(java.io.DataInput)
-
readCharArray
public static char[] readCharArray(java.io.DataInput in) throws java.io.IOExceptionReads an array ofchars from aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized array of
chars - Throws:
java.io.IOException- A problem occurs while reading fromin- Since:
- GemFire 5.7
- See Also:
writeCharArray(char[], java.io.DataOutput)
-
writeBooleanArray
public static void writeBooleanArray(boolean[] array, java.io.DataOutput out) throws java.io.IOExceptionWrites an array ofbooleans to aDataOutput.- Parameters:
array- the array ofbooleans to writeout- theDataInputto write to- Throws:
java.io.IOException- A problem occurs while writing toout- Since:
- GemFire 5.7
- See Also:
readBooleanArray(java.io.DataInput)
-
readBooleanArray
public static boolean[] readBooleanArray(java.io.DataInput in) throws java.io.IOExceptionReads an array ofbooleans from aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized array of
booleans - Throws:
java.io.IOException- A problem occurs while reading fromin- Since:
- GemFire 5.7
- See Also:
writeBooleanArray(boolean[], java.io.DataOutput)
-
writeIntArray
public static void writeIntArray(int[] array, java.io.DataOutput out) throws java.io.IOExceptionWrites anintarray to aDataOutput. This method will serialize anullarray and not throw aNullPointerException.- Parameters:
array- the array ofints to writeout- theDataInputto write to- Throws:
java.io.IOException- A problem occurs while writing toout- See Also:
readIntArray(java.io.DataInput)
-
readIntArray
public static int[] readIntArray(java.io.DataInput in) throws java.io.IOExceptionReads anintarray from aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized array of
ints - Throws:
java.io.IOException- A problem occurs while reading fromin- See Also:
writeIntArray(int[], java.io.DataOutput)
-
writeLongArray
public static void writeLongArray(long[] array, java.io.DataOutput out) throws java.io.IOExceptionWrites an array oflongs to aDataOutput. This method will serialize anullarray and not throw aNullPointerException.- Parameters:
array- the array oflongs to writeout- theDataInputto write to- Throws:
java.io.IOException- A problem occurs while writing toout- See Also:
readLongArray(java.io.DataInput)
-
readLongArray
public static long[] readLongArray(java.io.DataInput in) throws java.io.IOExceptionReads an array oflongs from aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized array of
longs - Throws:
java.io.IOException- A problem occurs while reading fromin- See Also:
writeLongArray(long[], java.io.DataOutput)
-
writeFloatArray
public static void writeFloatArray(float[] array, java.io.DataOutput out) throws java.io.IOExceptionWrites an array offloats to aDataOutput. This method will serialize anullarray and not throw aNullPointerException.- Parameters:
array- the array offloats to writeout- theDataInputto write to- Throws:
java.io.IOException- A problem occurs while writing toout- See Also:
readFloatArray(java.io.DataInput)
-
readFloatArray
public static float[] readFloatArray(java.io.DataInput in) throws java.io.IOExceptionReads an array offloats from aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized array of
floats - Throws:
java.io.IOException- A problem occurs while reading fromin- See Also:
writeFloatArray(float[], java.io.DataOutput)
-
writeDoubleArray
public static void writeDoubleArray(double[] array, java.io.DataOutput out) throws java.io.IOExceptionWrites an array ofdoubles to aDataOutput. This method will serialize anullarray and not throw aNullPointerException.- Parameters:
array- the array ofdoubles to writeout- theDataInputto write to- Throws:
java.io.IOException- A problem occurs while writing toout- See Also:
readDoubleArray(java.io.DataInput)
-
readDoubleArray
public static double[] readDoubleArray(java.io.DataInput in) throws java.io.IOExceptionReads an array ofdoubles from aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized array of
doubles - Throws:
java.io.IOException- A problem occurs while reading fromin- See Also:
writeDoubleArray(double[], java.io.DataOutput)
-
writeObjectArray
public static void writeObjectArray(java.lang.Object[] array, java.io.DataOutput out) throws java.io.IOExceptionWrites an array ofObjects to aDataOutput. This method will serialize anullarray and not throw aNullPointerException.- Parameters:
array- the array ofObjects to writeout- theDataInputto write to- Throws:
java.io.IOException- A problem occurs while writing toout- See Also:
readObjectArray(java.io.DataInput),writeObject(Object, DataOutput)
-
readObjectArray
public static java.lang.Object[] readObjectArray(java.io.DataInput in) throws java.io.IOException, java.lang.ClassNotFoundExceptionReads an array ofObjects from aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized array of
Objects - Throws:
java.io.IOException- A problem occurs while reading frominjava.lang.ClassNotFoundException- if the class of one of the array's elements cannot be found.- See Also:
writeObjectArray(java.lang.Object[], java.io.DataOutput),readObject(java.io.DataInput)
-
writeArrayOfByteArrays
public static void writeArrayOfByteArrays(byte[][] array, java.io.DataOutput out) throws java.io.IOExceptionWrites an array ofbyte[]to aDataOutput.- Parameters:
array- the array ofbyte[]s to writeout- theDataInputto write to- Throws:
java.io.IOException- A problem occurs while writing toout.
-
readArrayOfByteArrays
public static byte[][] readArrayOfByteArrays(java.io.DataInput in) throws java.io.IOExceptionReads an array ofbyte[]s from aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized array of
byte[]s - Throws:
java.io.IOException- A problem occurs while reading fromin
-
writeArrayList
public static void writeArrayList(java.util.ArrayList<?> list, java.io.DataOutput out) throws java.io.IOExceptionWrites anArrayListto aDataOutput. Note that even thoughlistmay be an instance of a subclass ofArrayList,readArrayListwill always return an instance ofArrayList, not an instance of the subclass. To preserve the class type oflist,writeObject(Object, DataOutput)should be used for data serialization. This method will serialize anulllist and not throw aNullPointerException.- Parameters:
list- theArrayListto writeout- theDataInputto write to- Throws:
java.io.IOException- A problem occurs while writing toout- See Also:
readArrayList(java.io.DataInput)
-
readArrayList
public static <E> java.util.ArrayList<E> readArrayList(java.io.DataInput in) throws java.io.IOException, java.lang.ClassNotFoundExceptionReads anArrayListfrom aDataInput.- Type Parameters:
E- – the type of elements in the list- Parameters:
in- theDataInputto read from- Returns:
- the deserialized
ArrayList - Throws:
java.io.IOException- A problem occurs while reading frominjava.lang.ClassNotFoundException- The class of one of theArrayList's elements cannot be found.- See Also:
writeArrayList(java.util.ArrayList<?>, java.io.DataOutput)
-
writeVector
public static void writeVector(java.util.Vector<?> list, java.io.DataOutput out) throws java.io.IOExceptionWrites aVectorto aDataOutput. Note that even thoughlistmay be an instance of a subclass ofVector,readVectorwill always return an instance ofVector, not an instance of the subclass. To preserve the class type oflist,writeObject(Object, DataOutput)should be used for data serialization.- Parameters:
list- theVectorto writeout- theDataOutputto write to- Throws:
java.io.IOException- A problem occurs while writing toout- Since:
- GemFire 5.7
- See Also:
readVector(java.io.DataInput)
-
readVector
public static <E> java.util.Vector<E> readVector(java.io.DataInput in) throws java.io.IOException, java.lang.ClassNotFoundExceptionReads aVectorfrom aDataInput.- Type Parameters:
E- – the type of elements in the vector- Parameters:
in- theDataInputto read from- Returns:
- the deserialized
Vector - Throws:
java.io.IOException- A problem occurs while reading frominjava.lang.ClassNotFoundException- The class of one of theVector's elements cannot be found.- Since:
- GemFire 5.7
- See Also:
writeVector(java.util.Vector<?>, java.io.DataOutput)
-
writeStack
public static void writeStack(java.util.Stack<?> list, java.io.DataOutput out) throws java.io.IOExceptionWrites aStackto aDataOutput. Note that even thoughlistmay be an instance of a subclass ofStack,readStackwill always return an instance ofStack, not an instance of the subclass. To preserve the class type oflist,writeObject(Object, DataOutput)should be used for data serialization.- Parameters:
list- theStackto writeout- theDataInputto write to- Throws:
java.io.IOException- A problem occurs while writing toout- Since:
- GemFire 5.7
- See Also:
readStack(java.io.DataInput)
-
readStack
public static <E> java.util.Stack<E> readStack(java.io.DataInput in) throws java.io.IOException, java.lang.ClassNotFoundExceptionReads aStackfrom aDataInput.- Type Parameters:
E- – the type of elements in the stack- Parameters:
in- theDataInputto read from- Returns:
- the deserialized
Stack - Throws:
java.io.IOException- A problem occurs while reading frominjava.lang.ClassNotFoundException- The class of one of theStack's elements cannot be found.- Since:
- GemFire 5.7
- See Also:
writeStack(java.util.Stack<?>, java.io.DataOutput)
-
writeLinkedList
public static void writeLinkedList(java.util.LinkedList<?> list, java.io.DataOutput out) throws java.io.IOExceptionWrites aLinkedListto aDataOutput. Note that even thoughlistmay be an instance of a subclass ofLinkedList,readLinkedListwill always return an instance ofLinkedList, not an instance of the subclass. To preserve the class type oflist,writeObject(Object, DataOutput)should be used for data serialization. This method will serialize anulllist and not throw aNullPointerException.- Parameters:
list- theLinkedListto writeout- theDataInputto write to- Throws:
java.io.IOException- A problem occurs while writing toout- See Also:
readLinkedList(java.io.DataInput)
-
readLinkedList
public static <E> java.util.LinkedList<E> readLinkedList(java.io.DataInput in) throws java.io.IOException, java.lang.ClassNotFoundExceptionReads aLinkedListfrom aDataInput.- Type Parameters:
E- – the type of elements in the list- Parameters:
in- theDataInputto read from- Returns:
- the deserialized
LinkedList - Throws:
java.io.IOException- A problem occurs while reading frominjava.lang.ClassNotFoundException- The class of one of theLinkedList's elements cannot be found.- See Also:
writeLinkedList(java.util.LinkedList<?>, java.io.DataOutput)
-
writeHashSet
public static void writeHashSet(java.util.HashSet<?> set, java.io.DataOutput out) throws java.io.IOExceptionWrites aHashSetto aDataOutput. Note that even thoughsetmay be an instance of a subclass ofHashSet,readHashSetwill always return an instance ofHashSet, not an instance of the subclass. To preserve the class type ofset,writeObject(Object, DataOutput)should be used for data serialization. This method will serialize anullset and not throw aNullPointerException.- Parameters:
set- theHashSetto writeout- theDataInputto write to- Throws:
java.io.IOException- A problem occurs while writing toout- See Also:
readHashSet(java.io.DataInput)
-
readHashSet
public static <E> java.util.HashSet<E> readHashSet(java.io.DataInput in) throws java.io.IOException, java.lang.ClassNotFoundExceptionReads aHashSetfrom aDataInput.- Type Parameters:
E- – the type of elements in the set- Parameters:
in- theDataInputto read from- Returns:
- the deserialized
HashSet - Throws:
java.io.IOException- A problem occurs while reading frominjava.lang.ClassNotFoundException- The class of one of theHashSet's elements cannot be found.- See Also:
writeHashSet(java.util.HashSet<?>, java.io.DataOutput)
-
writeLinkedHashSet
public static void writeLinkedHashSet(java.util.LinkedHashSet<?> set, java.io.DataOutput out) throws java.io.IOExceptionWrites aLinkedHashSetto aDataOutput. Note that even thoughsetmay be an instance of a subclass ofLinkedHashSet,readLinkedHashSetwill always return an instance ofLinkedHashSet, not an instance of the subclass. To preserve the class type ofset,writeObject(Object, DataOutput)should be used for data serialization.- Parameters:
set- theLinkedHashSetto writeout- theDataInputto write to- Throws:
java.io.IOException- A problem occurs while writing toout- Since:
- GemFire 5.7
- See Also:
readLinkedHashSet(java.io.DataInput)
-
readLinkedHashSet
public static <E> java.util.LinkedHashSet<E> readLinkedHashSet(java.io.DataInput in) throws java.io.IOException, java.lang.ClassNotFoundExceptionReads aLinkedHashSetfrom aDataInput.- Type Parameters:
E- – the type of elements in the set- Parameters:
in- theDataInputto read from- Returns:
- the deserialized
LinkedHashSet - Throws:
java.io.IOException- A problem occurs while reading frominjava.lang.ClassNotFoundException- The class of one of theLinkedHashSet's elements cannot be found.- Since:
- GemFire 5.7
- See Also:
writeLinkedHashSet(java.util.LinkedHashSet<?>, java.io.DataOutput)
-
writeHashMap
public static void writeHashMap(java.util.Map<?,?> map, java.io.DataOutput out) throws java.io.IOExceptionWrites aHashMapto aDataOutput. Note that even thoughmapmay be an instance of a subclass ofHashMap,readHashMapwill always return an instance ofHashMap, not an instance of the subclass. To preserve the class type ofmap,writeObject(Object, DataOutput)should be used for data serialization. This method will serialize anullmap and not throw aNullPointerException.- Parameters:
map- theHashMapto writeout- theDataInputto write to- Throws:
java.io.IOException- A problem occurs while writing toout- See Also:
readHashMap(java.io.DataInput)
-
readHashMap
public static <K,V> java.util.HashMap<K,V> readHashMap(java.io.DataInput in) throws java.io.IOException, java.lang.ClassNotFoundExceptionReads aHashMapfrom aDataInput.- Type Parameters:
K- – the type of keys in the mapV- – the type of mapped values- Parameters:
in- theDataInputto read from- Returns:
- the deserialized
HashMap - Throws:
java.io.IOException- A problem occurs while reading frominjava.lang.ClassNotFoundException- The class of one of theHashMap's elements cannot be found.- See Also:
writeHashMap(java.util.Map<?, ?>, java.io.DataOutput)
-
writeIdentityHashMap
public static void writeIdentityHashMap(java.util.IdentityHashMap<?,?> map, java.io.DataOutput out) throws java.io.IOExceptionWrites anIdentityHashMapto aDataOutput. Note that even thoughmapmay be an instance of a subclass ofIdentityHashMap,readIdentityHashMapwill always return an instance ofIdentityHashMap, not an instance of the subclass. To preserve the class type ofmap,writeObject(Object, DataOutput)should be used for data serialization.- Parameters:
map- theIdentityHashMapto writeout- theDataInputto write to- Throws:
java.io.IOException- A problem occurs while writing toout- See Also:
readIdentityHashMap(java.io.DataInput)
-
readIdentityHashMap
public static <K,V> java.util.IdentityHashMap<K,V> readIdentityHashMap(java.io.DataInput in) throws java.io.IOException, java.lang.ClassNotFoundExceptionReads anIdentityHashMapfrom aDataInput. Note that key identity is not preserved unless the keys belong to a class whose serialization preserves identity.- Type Parameters:
K- – the type of keys in the mapV- – the type of mapped values- Parameters:
in- theDataInputto read from- Returns:
- the deserialized
IdentityHashMap - Throws:
java.io.IOException- A problem occurs while reading frominjava.lang.ClassNotFoundException- The class of one of theIdentityHashMap's elements cannot be found.- See Also:
writeIdentityHashMap(java.util.IdentityHashMap<?, ?>, java.io.DataOutput)
-
writeConcurrentHashMap
public static void writeConcurrentHashMap(java.util.concurrent.ConcurrentHashMap<?,?> map, java.io.DataOutput out) throws java.io.IOExceptionWrites aConcurrentHashMapto aDataOutput. Note that even thoughmapmay be an instance of a subclass ofConcurrentHashMap,readConcurrentHashMapwill always return an instance ofConcurrentHashMap, not an instance of the subclass. To preserve the class type ofmap,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.- Parameters:
map- theConcurrentHashMapto writeout- theDataInputto write to- Throws:
java.io.IOException- A problem occurs while writing toout- Since:
- GemFire 6.6
- See Also:
readConcurrentHashMap(java.io.DataInput)
-
readConcurrentHashMap
public static <K,V> java.util.concurrent.ConcurrentHashMap<K,V> readConcurrentHashMap(java.io.DataInput in) throws java.io.IOException, java.lang.ClassNotFoundExceptionReads aConcurrentHashMapfrom aDataInput.- Type Parameters:
K- – the type of keys in the mapV- – the type of mapped values- Parameters:
in- theDataInputto read from- Returns:
- the deserialized
ConcurrentHashMap - Throws:
java.io.IOException- A problem occurs while reading frominjava.lang.ClassNotFoundException- The class of one of theConcurrentHashMap's elements cannot be found.- Since:
- GemFire 6.6
- See Also:
writeConcurrentHashMap(java.util.concurrent.ConcurrentHashMap<?, ?>, java.io.DataOutput)
-
writeHashtable
public static void writeHashtable(java.util.Hashtable<?,?> map, java.io.DataOutput out) throws java.io.IOExceptionWrites aHashtableto aDataOutput. Note that even thoughmapmay be an instance of a subclass ofHashtable,readHashtablewill always return an instance ofHashtable, not an instance of the subclass. To preserve the class type ofmap,writeObject(Object, DataOutput)should be used for data serialization.- Parameters:
map- theHashtableto writeout- theDataInputto write to- Throws:
java.io.IOException- A problem occurs while writing toout- Since:
- GemFire 5.7
- See Also:
readHashtable(java.io.DataInput)
-
readHashtable
public static <K,V> java.util.Hashtable<K,V> readHashtable(java.io.DataInput in) throws java.io.IOException, java.lang.ClassNotFoundExceptionReads aHashtablefrom aDataInput.- Type Parameters:
K- – the type of keys in the hashtableV- – the type of values in the hashtable- Parameters:
in- theDataInputto read from- Returns:
- the deserialized
Hashtable - Throws:
java.io.IOException- A problem occurs while reading frominjava.lang.ClassNotFoundException- The class of one of theHashtable's elements cannot be found.- Since:
- GemFire 5.7
- See Also:
writeHashtable(java.util.Hashtable<?, ?>, java.io.DataOutput)
-
writeTreeMap
public static void writeTreeMap(java.util.TreeMap<?,?> map, java.io.DataOutput out) throws java.io.IOExceptionWrites aTreeMapto aDataOutput. Note that even thoughmapmay be an instance of a subclass ofTreeMap,readTreeMapwill always return an instance ofTreeMap, not an instance of the subclass. To preserve the class type ofmap,writeObject(Object, DataOutput)should be used for data serialization.If the map has a comparator then it must also be serializable.
- Parameters:
map- theTreeMapto writeout- theDataInputto write to- Throws:
java.io.IOException- A problem occurs while writing toout- Since:
- GemFire 5.7
- See Also:
readTreeMap(java.io.DataInput)
-
readTreeMap
public static <K,V> java.util.TreeMap<K,V> readTreeMap(java.io.DataInput in) throws java.io.IOException, java.lang.ClassNotFoundExceptionReads aTreeMapfrom aDataInput.- Type Parameters:
K- – the type of keys in the mapV- – the type of mapped values- Parameters:
in- theDataInputto read from- Returns:
- the deserialized
TreeMap - Throws:
java.io.IOException- A problem occurs while reading frominjava.lang.ClassNotFoundException- The class of one of theTreeMap's elements cannot be found.- Since:
- GemFire 5.7
- See Also:
writeTreeMap(java.util.TreeMap<?, ?>, java.io.DataOutput)
-
writeLinkedHashMap
public static void writeLinkedHashMap(java.util.Map<?,?> map, java.io.DataOutput out) throws java.io.IOExceptionWrites aLinkedHashMapto aDataOutput. Note that even thoughmapmay be an instance of a subclass ofLinkedHashMap,readLinkedHashMapwill always return an instance ofLinkedHashMap, not an instance of the subclass. To preserve the class type ofmap,writeObject(Object, DataOutput)should be used for data serialization. This method will serialize anullmap and not throw aNullPointerException.- Parameters:
map- theLinkedHashMapto writeout- theDataInputto write to- Throws:
java.io.IOException- A problem occurs while writing toout- See Also:
readLinkedHashMap(java.io.DataInput)
-
readLinkedHashMap
public static <K,V> java.util.LinkedHashMap<K,V> readLinkedHashMap(java.io.DataInput in) throws java.io.IOException, java.lang.ClassNotFoundExceptionReads aLinkedHashMapfrom aDataInput.- Type Parameters:
K- – the type of keys in the mapV- – the type of mapped values- Parameters:
in- theDataInputto read from- Returns:
- the deserialized
LinkedHashMap - Throws:
java.io.IOException- A problem occurs while reading frominjava.lang.ClassNotFoundException- The class of one of theHashMap's elements cannot be found.- See Also:
writeLinkedHashMap(java.util.Map<?, ?>, java.io.DataOutput)
-
writeTreeSet
public static void writeTreeSet(java.util.TreeSet<?> set, java.io.DataOutput out) throws java.io.IOExceptionWrites aTreeSetto aDataOutput. Note that even thoughsetmay be an instance of a subclass ofTreeSet,readTreeSetwill always return an instance ofTreeSet, not an instance of the subclass. To preserve the class type ofset,writeObject(Object, DataOutput)should be used for data serialization.If the set has a comparator then it must also be serializable.
- Parameters:
set- theTreeSetto writeout- theDataInputto write to- Throws:
java.io.IOException- A problem occurs while writing toout- See Also:
readTreeSet(java.io.DataInput)
-
readTreeSet
public static <E> java.util.TreeSet<E> readTreeSet(java.io.DataInput in) throws java.io.IOException, java.lang.ClassNotFoundExceptionReads aTreeSetfrom aDataInput.- Type Parameters:
E- the type contained in theTreeSet- Parameters:
in- theDataInputto read from- Returns:
- the deserialized
TreeSet - Throws:
java.io.IOException- A problem occurs while reading frominjava.lang.ClassNotFoundException- The class of one of theTreeSet's elements cannot be found.- See Also:
writeTreeSet(java.util.TreeSet<?>, java.io.DataOutput)
-
writeProperties
public static void writeProperties(java.util.Properties props, java.io.DataOutput out) throws java.io.IOExceptionWrites aPropertiesto aDataOutput.NOTE: The
defaultsof the specifiedpropsare not serialized.Note that even though
propsmay be an instance of a subclass ofProperties,readPropertieswill always return an instance ofProperties, not an instance of the subclass. To preserve the class type ofprops,writeObject(Object, DataOutput)should be used for data serialization.- Parameters:
props- the Properties to writeout- theDataInputto write to- Throws:
java.io.IOException- A problem occurs while writing toout- See Also:
readProperties(java.io.DataInput)
-
readProperties
public static java.util.Properties readProperties(java.io.DataInput in) throws java.io.IOException, java.lang.ClassNotFoundExceptionReads aPropertiesfrom aDataInput.NOTE: the
defaultsare always empty in the returnedProperties.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized Properties
- Throws:
java.io.IOException- If this serializer cannot read an object fromin.java.lang.ClassNotFoundException- If the class cannot be loaded- See Also:
writeProperties(java.util.Properties, java.io.DataOutput)
-
writeObject
public static void writeObject(java.lang.Object o, java.io.DataOutput out, boolean allowJavaSerialization) throws java.io.IOExceptionWrites an arbitrary object to aDataOutputby serializing it into bytes. Serialization is done with the following steps:- If
oisnullthen GemFire serialize it. Note thatNullPointerExceptionis not thrown. - If
ois an instance ofDataSerializable.Replaceablethen callwriteObjectwith whatreplacereturns. - If
ois an instance ofPdxSerializablethen GemFire serialize it as PDX. - If
ois an instance ofDataSerializablethen GemFire serialize it as DataSerializable. - If
ois a GemFire instance ofPdxInstancethen GemFire serialize it as PDX. - If
ois a GemFire instance ofJsonDocumentthen GemFire serialize it. - If
ois an instance of the classes listed ongetSupportedClasses()then GemFire serialize it. - If
ois an instance of a class that has aDataSerializerregistered for it then GemFire serialize it. - If a
PdxSerializerhas been registered, and it acceptsothen GemFire serialize it. Note that this step includesReflectionBasedAutoSerializer. - Otherwise if
allowJavaSerializationis true, attempt standard Java serialization. Note that once standard Java serialization is used, then it will also be used for all the objects referenced byoeven if those objects would normally use GemFire serialization.
- Parameters:
o- the object to writeout- theDataOutputto write toallowJavaSerialization- If false, then a NotSerializableException is thrown in the case where standard Java serialization would otherwise be used for objectoor for any nested sub-object ofo. This is used to prevent Java serialization from being used when sending data to a non-Java client- Throws:
java.io.IOException- A problem occurs while writingotoout- See Also:
readObject(DataInput),Instantiator,ObjectOutputStream.writeObject(java.lang.Object)
- If
-
writeObject
public static void writeObject(java.lang.Object o, java.io.DataOutput out) throws java.io.IOExceptionWrites an arbitrary object to aDataOutputby callingwriteObject(Object, DataOutput, boolean)withtrue.- Parameters:
o- the object to writeout- theDataOutputto write to- Throws:
java.io.IOException- A problem occurs while writingotoout- See Also:
writeObject(Object, DataOutput, boolean)
-
readObject
public static <T> T readObject(java.io.DataInput in) throws java.io.IOException, java.lang.ClassNotFoundExceptionReads an arbitrary object from aDataInput. Instances of classes that are not handled specially (such asString,Class, andDataSerializable) 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 loaderbefore the one normally used by Java serialization is consulted.- Type Parameters:
T- the type of the Object to read- Parameters:
in- theDataInputto read from- Returns:
- an arbitrary deserialized object
- Throws:
java.io.IOException- A problem occurred while reading fromin(may wrap another exception)java.lang.ClassNotFoundException- The class of an object read fromincould not be found- See Also:
writeObject(Object, DataOutput),ObjectInputStream.readObject()
-
register
public static DataSerializer register(java.lang.Class<?> c)
Registers aDataSerializerclass with the data serialization framework. This method uses reflection to create an instance of theDataSerializerclass by invoking its zero-argument constructor.The
DataSerializerinstance will be consulted by thewriteObject(Object, DataOutput)andreadObject(java.io.DataInput)methods. Note that no two serializers can support the same class.This method invokes the
DataSerializerinstance'sgetSupportedClasses()method and keeps track of which classes can have their instances serialized by by this data serializer.- Parameters:
c- theDataSerializerclass to create and register with the data serialization framework.- Returns:
- the registered serializer instance
- Throws:
java.lang.IllegalArgumentException- Ifcdoes not subclassDataSerializer, ifcdoes not have a zero-argument constructor, ifidis 0, if getSupportedClasses returns null or an empty array, if getSupportedClasses returns and array with null elementsjava.lang.IllegalStateException- if another serializer instance with ididhas 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 (seegetSupportedClasses()for a list).- See Also:
getSupportedClasses()
-
getSupportedClasses
public abstract java.lang.Class<?>[] getSupportedClasses()
Returns theClasses whose instances are data serialized by thisDataSerializer. This method is invoked when this serializer is registered. This method is not allowed to returnnullnor an empty array. Only instances whose class name is the same as one of the class names in the result will be serialized by thisDataSerializer. TwoDataSerializers 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 serializers:ClassStringBooleanByteCharacterShortIntegerLongFloatDoubleFileBigIntegerBigDecimalInetAddressInet4AddressInet6AddressTimestampArrayListDateHashMapIdentityHashMapHashSetHashtableLinkedHashSetLinkedListOptionalOptionalIntOptionalLongOptionalDoublePropertiesStackTreeMapTreeSetUUIDVectorany array classNote: an Object[], with the exception of String[], can be handled by a user defined DataSerializerany enum classNote: Enum classes other than java.util.concurrent.TimeUnit can be handled by a user defined DataSerializer
- Returns:
- the
Classes whose instances are data serialized by thisDataSerializer
-
toData
public abstract boolean toData(java.lang.Object o, java.io.DataOutput out) throws java.io.IOExceptionData serializes an object to aDataOutput. It is very important that when performing the "switch" ono'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 benull.out- theDataInputto write to- Returns:
falseif thisDataSerializerdoes not know how to data serializeo.- Throws:
java.io.IOException- If this serializer cannot write an object toout.
-
fromData
public abstract java.lang.Object fromData(java.io.DataInput in) throws java.io.IOException, java.lang.ClassNotFoundExceptionReads an object from aDataInput. This implementation must support deserializing everything serialized by the matchingtoData(java.lang.Object, java.io.DataOutput).- Parameters:
in- theDataInputto write to- Returns:
- the deserialized Object
- Throws:
java.io.IOException- If this serializer cannot read an object fromin.java.lang.ClassNotFoundException- If the class cannot be loaded- See Also:
toData(java.lang.Object, java.io.DataOutput)
-
getId
public abstract int getId()
Returns the id of thisDataSerializer.Returns an int instead of a byte
- Returns:
- the id of this
DataSerializer - Since:
- 5.7.
-
equals
public boolean equals(java.lang.Object o)
TwoDataSerializers are consider to be equal if they have the same id and the same class- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
setEventId
public void setEventId(java.lang.Object eventId)
For internal use only. Sets the uniqueeventIdof thisDataSerializer.- Parameters:
eventId- the uniqueeventIdof thisDataSerializer- Since:
- GemFire 6.5
-
getEventId
public java.lang.Object getEventId()
For internal use only. Returns the uniqueeventIdof thisDataSerializer.- Returns:
- the unique
eventIdof thisDataSerializer - Since:
- GemFire 6.5
-
setContext
public void setContext(java.lang.Object context)
For internal use only. Sets the context of thisDataSerializer.- Parameters:
context- the context of thisDataSerializer- Since:
- GemFire 6.5
-
getContext
public java.lang.Object getContext()
For internal use only. Returns the context of thisDataSerializer.- Returns:
- the context of this
DataSerializer - Since:
- GemFire 6.5
-
writeEnum
public static void writeEnum(java.lang.Enum<?> e, java.io.DataOutput out) throws java.io.IOExceptionWrites theEnum constanttoDataOutput. 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);- Parameters:
e- the Enum to serializeout- theDataInputto write to- Throws:
java.io.IOException- if a problem occurs while writing toout- Since:
- GemFire 6.5
- See Also:
readEnum(Class, DataInput)
-
readEnum
public static <E extends java.lang.Enum<E>> E readEnum(java.lang.Class<E> clazz, java.io.DataInput in) throws java.io.IOExceptionReads anEnum constantfromDataInput. 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);- Type Parameters:
E- the type of Enum- Parameters:
clazz- the Enum class to deserialize toin- theDataInputto read from- Returns:
- the deserialized Enum
- Throws:
java.io.IOException- if a problem occurs while reading frominjava.lang.ArrayIndexOutOfBoundsException- if the wrong enum class/enum class with a different version and less enum constants is used- Since:
- GemFire 6.5
- See Also:
writeEnum(Enum, DataOutput)
-
writeOptional
public static <T> void writeOptional(java.util.Optional<T> o, java.io.DataOutput out) throws java.io.IOExceptionWrites anOptionalto aDataOutput.- Type Parameters:
T- the type of value in theOptional- Parameters:
o- theOptionalto writeout- theDataOutputto write to- Throws:
java.io.IOException- A problem occurs while writing tooutjava.lang.NullPointerException- if o is null- Since:
- GemFire 10.1
- See Also:
readOptional(java.io.DataInput)
-
readOptional
public static <T> java.util.Optional<T> readOptional(java.io.DataInput in) throws java.io.IOException, java.lang.ClassNotFoundExceptionReads anOptionalfrom aDataInput.- Type Parameters:
T- – the type of value in theOptional- Parameters:
in- theDataInputto read from- Returns:
- the deserialized
Optional - Throws:
java.io.IOException- A problem occurs while reading frominjava.lang.ClassNotFoundException- The class of theOptional's elements cannot be found.- Since:
- GemFire 10.1
- See Also:
writeOptional(java.util.Optional<T>, java.io.DataOutput)
-
writeOptionalInt
public static void writeOptionalInt(java.util.OptionalInt o, java.io.DataOutput out) throws java.io.IOExceptionWrites anOptionalIntto aDataOutput.- Parameters:
o- theOptionalIntto writeout- theDataOutputto write to- Throws:
java.io.IOException- A problem occurs while writing tooutjava.lang.NullPointerException- if o is null- Since:
- GemFire 10.1
- See Also:
readOptionalInt(java.io.DataInput)
-
readOptionalInt
public static java.util.OptionalInt readOptionalInt(java.io.DataInput in) throws java.io.IOExceptionReads anOptionalIntfrom aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized
OptionalInt - Throws:
java.io.IOException- A problem occurs while reading fromin- Since:
- GemFire 10.1
- See Also:
writeOptionalInt(java.util.OptionalInt, java.io.DataOutput)
-
writeOptionalLong
public static void writeOptionalLong(java.util.OptionalLong o, java.io.DataOutput out) throws java.io.IOExceptionWrites anOptionalLongto aDataOutput.- Parameters:
o- theOptionalLongto writeout- theDataOutputto write to- Throws:
java.io.IOException- A problem occurs while writing tooutjava.lang.NullPointerException- if o is null- Since:
- GemFire 10.1
- See Also:
readOptionalLong(java.io.DataInput)
-
readOptionalLong
public static java.util.OptionalLong readOptionalLong(java.io.DataInput in) throws java.io.IOExceptionReads anOptionalLongfrom aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized
OptionalLong - Throws:
java.io.IOException- A problem occurs while reading fromin- Since:
- GemFire 10.1
- See Also:
writeOptionalLong(java.util.OptionalLong, java.io.DataOutput)
-
writeOptionalDouble
public static void writeOptionalDouble(java.util.OptionalDouble o, java.io.DataOutput out) throws java.io.IOExceptionWrites anOptionalDoubleto aDataOutput.- Parameters:
o- theOptionalDoubleto writeout- theDataOutputto write to- Throws:
java.io.IOException- A problem occurs while writing tooutjava.lang.NullPointerException- if o is null- Since:
- GemFire 10.1
- See Also:
readOptionalDouble(java.io.DataInput)
-
readOptionalDouble
public static java.util.OptionalDouble readOptionalDouble(java.io.DataInput in) throws java.io.IOExceptionReads anOptionalDoublefrom aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized
OptionalDouble - Throws:
java.io.IOException- A problem occurs while reading fromin- Since:
- GemFire 10.1
- See Also:
writeOptionalDouble(java.util.OptionalDouble, java.io.DataOutput)
-
readOptionalPrimitive
protected static <T> T readOptionalPrimitive(java.io.DataInput in) throws java.io.IOException- Throws:
java.io.IOException
-
-