VMware GemFire Java API Reference
Class DataSerializer
- java.lang.Object
-
- org.apache.geode.DataSerializer
-
public abstract class DataSerializer extends Object
Provides 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 ThreadLocal<Boolean>DISALLOW_JAVA_SERIALIZATIONprotected 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(Object o)TwoDataSerializers are consider to be equal if they have the same id and the same classabstract ObjectfromData(DataInput in)Reads an object from aDataInput.ObjectgetContext()For internal use only.ObjectgetEventId()For internal use only.abstract intgetId()Returns the id of thisDataSerializer.abstract Class<?>[]getSupportedClasses()Returns theClasses whose instances are data serialized by thisDataSerializer.inthashCode()static <E> ArrayList<E>readArrayList(DataInput in)Reads anArrayListfrom aDataInput.static byte[][]readArrayOfByteArrays(DataInput in)Reads an array ofbyte[]s from aDataInput.static BooleanreadBoolean(DataInput in)Reads an instance ofBooleanfrom aDataInput.static boolean[]readBooleanArray(DataInput in)Reads an array ofbooleans from aDataInput.static BytereadByte(DataInput in)Reads an instance ofBytefrom aDataInput.static byte[]readByteArray(DataInput in)Reads an array ofbytes from aDataInput.static CharacterreadCharacter(DataInput in)Reads an instance ofCharacterfrom aDataInput.static char[]readCharArray(DataInput in)Reads an array ofchars from aDataInput.static Class<?>readClass(DataInput in)Reads an instance ofClassfrom aDataInput.static <K,V>
ConcurrentHashMap<K,V>readConcurrentHashMap(DataInput in)Reads aConcurrentHashMapfrom aDataInput.static DatereadDate(DataInput in)Reads an instance ofDatefrom aDataInput.static DoublereadDouble(DataInput in)Reads an instance ofDoublefrom aDataInput.static double[]readDoubleArray(DataInput in)Reads an array ofdoubles from aDataInput.static <E extends Enum<E>>
EreadEnum(Class<E> clazz, DataInput in)Reads aEnum constantfromDataInput.static FilereadFile(DataInput in)Reads an instance ofFilefrom aDataInput.static FloatreadFloat(DataInput in)Reads an instance ofFloatfrom aDataInput.static float[]readFloatArray(DataInput in)Reads an array offloats from aDataInput.static <K,V>
HashMap<K,V>readHashMap(DataInput in)Reads aHashMapfrom aDataInput.static <E> HashSet<E>readHashSet(DataInput in)Reads aHashSetfrom aDataInput.static <K,V>
Hashtable<K,V>readHashtable(DataInput in)Reads aHashtablefrom aDataInput.static <K,V>
IdentityHashMap<K,V>readIdentityHashMap(DataInput in)Reads aIdentityHashMapfrom aDataInput.static InetAddressreadInetAddress(DataInput in)Reads an instance ofInetAddressfrom aDataInput.static int[]readIntArray(DataInput in)Reads anintarray from aDataInput.static IntegerreadInteger(DataInput in)Reads an instance ofIntegerfrom aDataInput.static <K,V>
LinkedHashMap<K,V>readLinkedHashMap(DataInput in)Reads aLinkedHashMapfrom aDataInput.static <E> LinkedHashSet<E>readLinkedHashSet(DataInput in)Reads aLinkedHashSetfrom aDataInput.static <E> LinkedList<E>readLinkedList(DataInput in)Reads anLinkedListfrom aDataInput.static LongreadLong(DataInput in)Reads an instance ofLongfrom aDataInput.static long[]readLongArray(DataInput in)Reads an array oflongs from aDataInput.static StringreadNonPrimitiveClassName(DataInput in)Reads name of an instance ofClassfrom aDataInput.static <T> TreadObject(DataInput in)Reads an arbitrary object from aDataInput.static Object[]readObjectArray(DataInput in)Reads an array ofObjects from aDataInput.static booleanreadPrimitiveBoolean(DataInput in)Reads a primitivebooleanfrom aDataInput.static bytereadPrimitiveByte(DataInput in)Reads a primitivebytefrom aDataInput.static charreadPrimitiveChar(DataInput in)Reads a primitivecharfrom aDataInput.static doublereadPrimitiveDouble(DataInput in)Reads a primitivedoublefrom aDataInput.static floatreadPrimitiveFloat(DataInput in)Reads a primitivefloatfrom aDataInput.static intreadPrimitiveInt(DataInput in)Reads a primitiveintfrom aDataInput.static longreadPrimitiveLong(DataInput in)Reads a primitivelongfrom aDataInput.static shortreadPrimitiveShort(DataInput in)Reads a primitiveshortfrom aDataInput.static PropertiesreadProperties(DataInput in)Reads aPropertiesfrom aDataInput.static <K,V>
Region<K,V>readRegion(DataInput in)Reads an instance of Region.static ShortreadShort(DataInput in)Reads an instance ofShortfrom aDataInput.static short[]readShortArray(DataInput in)Reads an array ofshorts from aDataInput.static <E> Stack<E>readStack(DataInput in)Reads anStackfrom aDataInput.static StringreadString(DataInput in)Reads an instance ofStringfrom aDataInput.static String[]readStringArray(DataInput in)Reads an array ofStrings from aDataInput.static <K,V>
TreeMap<K,V>readTreeMap(DataInput in)Reads aTreeMapfrom aDataInput.static <E> TreeSet<E>readTreeSet(DataInput in)Reads aTreeSetfrom aDataInput.static intreadUnsignedByte(DataInput in)static intreadUnsignedShort(DataInput in)static <E> Vector<E>readVector(DataInput in)Reads anVectorfrom aDataInput.static DataSerializerregister(Class<?> c)Registers aDataSerializerclass with the data serialization framework.voidsetContext(Object context)For internal use only.voidsetEventId(Object eventId)For internal use only.abstract booleantoData(Object o, DataOutput out)Data serializes an object to aDataOutput.static voidwriteArrayList(ArrayList<?> list, DataOutput out)Writes anArrayListto aDataOutput.static voidwriteArrayOfByteArrays(byte[][] array, DataOutput out)Writes an array ofbyte[]to aDataOutput.static voidwriteBoolean(Boolean value, DataOutput out)Writes an instance ofBooleanto aDataOutput.static voidwriteBooleanArray(boolean[] array, DataOutput out)Writes an array ofbooleans to aDataOutput.static voidwriteByte(Byte value, DataOutput out)Writes an instance ofByteto aDataOutput.static voidwriteByteArray(byte[] array, int len, DataOutput out)Writes the firstlenelements of an array ofbytes to aDataOutput.static voidwriteByteArray(byte[] array, DataOutput out)Writes an array ofbytes to aDataOutput.static voidwriteCharacter(Character value, DataOutput out)Writes an instance ofCharacterto aDataOutput.static voidwriteCharArray(char[] array, DataOutput out)Writes an array ofchars to aDataOutput.static voidwriteClass(Class<?> c, DataOutput out)Writes an instance ofClassto aDataOutput.static voidwriteConcurrentHashMap(ConcurrentHashMap<?,?> map, DataOutput out)Writes aConcurrentHashMapto aDataOutput.static voidwriteDate(Date date, DataOutput out)Writes an instance ofDateto aDataOutput.static voidwriteDouble(Double value, DataOutput out)Writes an instance ofDoubleto aDataOutput.static voidwriteDoubleArray(double[] array, DataOutput out)Writes an array ofdoubles to aDataOutput.static voidwriteEnum(Enum<?> e, DataOutput out)Writes theEnum constanttoDataOutput.static voidwriteFile(File file, DataOutput out)Writes an instance ofFileto aDataOutput.static voidwriteFloat(Float value, DataOutput out)Writes an instance ofFloatto aDataOutput.static voidwriteFloatArray(float[] array, DataOutput out)Writes an array offloats to aDataOutput.static voidwriteHashMap(Map<?,?> map, DataOutput out)Writes aHashMapto aDataOutput.static voidwriteHashSet(HashSet<?> set, DataOutput out)Writes aHashSetto aDataOutput.static voidwriteHashtable(Hashtable<?,?> map, DataOutput out)Writes aHashtableto aDataOutput.static voidwriteIdentityHashMap(IdentityHashMap<?,?> map, DataOutput out)Writes aIdentityHashMapto aDataOutput.static voidwriteInetAddress(InetAddress address, DataOutput out)Writes an instance ofInetAddressto aDataOutput.static voidwriteIntArray(int[] array, DataOutput out)Writes anintarray to aDataOutput.static voidwriteInteger(Integer value, DataOutput out)Writes an instance ofIntegerto aDataOutput.static voidwriteLinkedHashMap(Map<?,?> map, DataOutput out)Writes aLinkedHashMapto aDataOutput.static voidwriteLinkedHashSet(LinkedHashSet<?> set, DataOutput out)Writes aLinkedHashSetto aDataOutput.static voidwriteLinkedList(LinkedList<?> list, DataOutput out)Writes anLinkedListto aDataOutput.static voidwriteLong(Long value, DataOutput out)Writes an instance ofLongto aDataOutput.static voidwriteLongArray(long[] array, DataOutput out)Writes an array oflongs to aDataOutput.static voidwriteNonPrimitiveClassName(String className, DataOutput out)Writes class name to aDataOutput.static voidwriteObject(Object o, DataOutput out)Writes an arbitrary object to aDataOutput.static voidwriteObject(Object o, DataOutput out, boolean allowJavaSerialization)Writes an arbitrary object to aDataOutput.static voidwriteObjectArray(Object[] array, DataOutput out)Writes an array ofObjects to aDataOutput.static voidwriteObjectAsByteArray(Object obj, 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 voidwritePrimitiveBoolean(boolean value, DataOutput out)Writes a primitivebooleanto aDataOutput.static voidwritePrimitiveByte(byte value, DataOutput out)Writes a primitivebyteto aDataOutput.static voidwritePrimitiveChar(char value, DataOutput out)Writes a primitivecharto aDataOutput.static voidwritePrimitiveDouble(double value, DataOutput out)Writes a primtivedoubleto aDataOutput.static voidwritePrimitiveFloat(float value, DataOutput out)Writes a primitivefloatto aDataOutput.static voidwritePrimitiveInt(int value, DataOutput out)Writes a primitiveintto aDataOutput.static voidwritePrimitiveLong(long value, DataOutput out)Writes a primitivelongto aDataOutput.static voidwritePrimitiveShort(short value, DataOutput out)Writes a primitiveshortto aDataOutput.static voidwriteProperties(Properties props, DataOutput out)Writes aPropertiesto aDataOutput.static voidwriteRegion(Region<?,?> rgn, DataOutput out)Writes an instance of Region.static voidwriteShort(Short value, DataOutput out)Writes an instance ofShortto aDataOutput.static voidwriteShortArray(short[] array, DataOutput out)Writes an array ofshorts to aDataOutput.static voidwriteStack(Stack<?> list, DataOutput out)Writes anStackto aDataOutput.static voidwriteString(String value, DataOutput out)Writes an instance ofStringto aDataOutput.static voidwriteStringArray(String[] array, DataOutput out)Writes an array ofStrings to aDataOutput.static voidwriteTreeMap(TreeMap<?,?> map, DataOutput out)Writes aTreeMapto aDataOutput.static voidwriteTreeSet(TreeSet<?> set, DataOutput out)Writes aTreeSetto aDataOutput.static voidwriteUnsignedByte(int value, DataOutput out)Writes a primitiveintas an unsigned byte to aDataOutput.static voidwriteUnsignedShort(int value, DataOutput out)Writes a primitiveintas an unsigned short to aDataOutput.static voidwriteVector(Vector<?> list, DataOutput out)Writes anVectorto aDataOutput.
-
-
-
Field Detail
-
TRACE_SERIALIZABLE
@Deprecated protected static final boolean TRACE_SERIALIZABLE
Deprecated.Use Boolean.getBoolean("DataSerializer.TRACE_SERIALIZABLE") instead.
-
DISALLOW_JAVA_SERIALIZATION
protected static final ThreadLocal<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(Class<?> c, DataOutput out) throws IOException
Writes an instance ofClassto aDataOutput. This method will handle anullvalue and not throw aNullPointerException.- Parameters:
c- theClassto writeout- theDataInputto write to- Throws:
IOException- A problem occurs while writing toout- See Also:
readClass(java.io.DataInput)
-
writeNonPrimitiveClassName
public static void writeNonPrimitiveClassName(String className, DataOutput out) throws IOException
Writes class name to aDataOutput. This method will handle anullvalue and not throw aNullPointerException.- Parameters:
className- the class name to writeout- theDataInputto write to- Throws:
IOException- A problem occurs while writing toout- See Also:
readNonPrimitiveClassName(DataInput)
-
readClass
public static Class<?> readClass(DataInput in) throws IOException, ClassNotFoundException
Reads 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:
IOException- A problem occurs while reading frominClassNotFoundException- The class cannot be loaded
-
readNonPrimitiveClassName
public static String readNonPrimitiveClassName(DataInput in) throws IOException
Reads name of an instance ofClassfrom aDataInput. The return value may benull.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized Class name
- Throws:
IOException- A problem occurs while reading fromin- 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 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:
IOException- if a problem occurs while reading fromin
-
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 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 CacheIOException- if a problem occurs while reading frominClassNotFoundException- if the class of one of the Region's elements cannot be found.
-
writeDate
public static void writeDate(Date date, DataOutput out) throws IOException
Writes 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:
IOException- A problem occurs while writing toout- See Also:
readDate(java.io.DataInput)
-
readDate
public static Date readDate(DataInput in) throws IOException
Reads an instance ofDatefrom aDataInput. The return value may benull.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized
Date - Throws:
IOException- A problem occurs while reading fromin
-
writeFile
public static void writeFile(File file, DataOutput out) throws IOException
Writes 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:
IOException- A problem occurs while writing toout- See Also:
readFile(java.io.DataInput),File.getCanonicalPath()
-
readFile
public static File readFile(DataInput in) throws IOException
Reads an instance ofFilefrom aDataInput. The return value may benull.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized
File - Throws:
IOException- A problem occurs while reading fromin
-
writeInetAddress
public static void writeInetAddress(InetAddress address, DataOutput out) throws IOException
Writes 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:
IOException- A problem occurs while writing toout- See Also:
readInetAddress(java.io.DataInput)
-
readInetAddress
public static InetAddress readInetAddress(DataInput in) throws IOException
Reads an instance ofInetAddressfrom aDataInput. The return value may benull.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized
InetAddress - Throws:
IOException- A problem occurs while reading frominor the address read frominis unknown- See Also:
InetAddress.getAddress()
-
writeString
public static void writeString(String value, DataOutput out) throws IOException
Writes 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:
IOException- A problem occurs while writing toout- See Also:
readString(java.io.DataInput)
-
readString
public static String readString(DataInput in) throws IOException
Reads an instance ofStringfrom aDataInput. The return value may benull.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized
String - Throws:
IOException- A problem occurs while reading fromin- See Also:
writeString(java.lang.String, java.io.DataOutput)
-
writeBoolean
public static void writeBoolean(Boolean value, DataOutput out) throws IOException
Writes an instance ofBooleanto aDataOutput.- Parameters:
value- theBooleanto writeout- theDataInputto write to- Throws:
IOException- A problem occurs while writing tooutNullPointerException- if value is null.- See Also:
readBoolean(java.io.DataInput)
-
readBoolean
public static Boolean readBoolean(DataInput in) throws IOException
Reads an instance ofBooleanfrom aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized
Boolean - Throws:
IOException- A problem occurs while reading fromin
-
writeCharacter
public static void writeCharacter(Character value, DataOutput out) throws IOException
Writes an instance ofCharacterto aDataOutput.- Parameters:
value- theCharacterto writeout- theDataInputto write to- Throws:
IOException- A problem occurs while writing tooutNullPointerException- if value is null.- See Also:
readCharacter(java.io.DataInput)
-
readCharacter
public static Character readCharacter(DataInput in) throws IOException
Reads an instance ofCharacterfrom aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized
Character - Throws:
IOException- A problem occurs while reading fromin
-
writeByte
public static void writeByte(Byte value, DataOutput out) throws IOException
Writes an instance ofByteto aDataOutput.- Parameters:
value- theByteto writeout- theDataInputto write to- Throws:
IOException- A problem occurs while writing tooutNullPointerException- if value is null.- See Also:
readByte(java.io.DataInput)
-
readByte
public static Byte readByte(DataInput in) throws IOException
Reads an instance ofBytefrom aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized
Byte - Throws:
IOException- A problem occurs while reading fromin
-
writeShort
public static void writeShort(Short value, DataOutput out) throws IOException
Writes an instance ofShortto aDataOutput.- Parameters:
value- theShortto writeout- theDataInputto write to- Throws:
IOException- A problem occurs while writing tooutNullPointerException- if value is null.- See Also:
readShort(java.io.DataInput)
-
readShort
public static Short readShort(DataInput in) throws IOException
Reads an instance ofShortfrom aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized
Short - Throws:
IOException- A problem occurs while reading fromin
-
writeInteger
public static void writeInteger(Integer value, DataOutput out) throws IOException
Writes an instance ofIntegerto aDataOutput.- Parameters:
value- theIntegerto writeout- theDataInputto write to- Throws:
IOException- A problem occurs while writing tooutNullPointerException- if value is null.- See Also:
readInteger(java.io.DataInput)
-
readInteger
public static Integer readInteger(DataInput in) throws IOException
Reads an instance ofIntegerfrom aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized
Integer - Throws:
IOException- A problem occurs while reading fromin
-
writeLong
public static void writeLong(Long value, DataOutput out) throws IOException
Writes an instance ofLongto aDataOutput.- Parameters:
value- theLongto writeout- theDataInputto write to- Throws:
IOException- A problem occurs while writing tooutNullPointerException- if value is null.- See Also:
readLong(java.io.DataInput)
-
readLong
public static Long readLong(DataInput in) throws IOException
Reads an instance ofLongfrom aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized
Long - Throws:
IOException- A problem occurs while reading fromin
-
writeFloat
public static void writeFloat(Float value, DataOutput out) throws IOException
Writes an instance ofFloatto aDataOutput.- Parameters:
value- theFloatto writeout- theDataInputto write to- Throws:
IOException- A problem occurs while writing tooutNullPointerException- if value is null.- See Also:
readFloat(java.io.DataInput)
-
readFloat
public static Float readFloat(DataInput in) throws IOException
Reads an instance ofFloatfrom aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized
Float - Throws:
IOException- A problem occurs while reading fromin
-
writeDouble
public static void writeDouble(Double value, DataOutput out) throws IOException
Writes an instance ofDoubleto aDataOutput.- Parameters:
value- theDoubleto writeout- theDataInputto write to- Throws:
IOException- A problem occurs while writing tooutNullPointerException- if value is null.- See Also:
readDouble(java.io.DataInput)
-
readDouble
public static Double readDouble(DataInput in) throws IOException
Reads an instance ofDoublefrom aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized
Double - Throws:
IOException- A problem occurs while reading fromin
-
writePrimitiveBoolean
public static void writePrimitiveBoolean(boolean value, DataOutput out) throws IOExceptionWrites a primitivebooleanto aDataOutput.- Parameters:
value- the primitivebooleanto writeout- theDataInputto write to- Throws:
IOException- A problem occurs while writing toout- Since:
- GemFire 5.1
- See Also:
DataOutput.writeBoolean(boolean)
-
readPrimitiveBoolean
public static boolean readPrimitiveBoolean(DataInput in) throws IOException
Reads a primitivebooleanfrom aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized primitive
boolean - Throws:
IOException- A problem occurs while reading fromin- Since:
- GemFire 5.1
- See Also:
DataInput.readBoolean()
-
writePrimitiveByte
public static void writePrimitiveByte(byte value, DataOutput out) throws IOExceptionWrites a primitivebyteto aDataOutput.- Parameters:
value- the primitivebyteto writeout- theDataInputto write to- Throws:
IOException- A problem occurs while writing toout- Since:
- GemFire 5.1
- See Also:
DataOutput.writeByte(int)
-
readPrimitiveByte
public static byte readPrimitiveByte(DataInput in) throws IOException
Reads a primitivebytefrom aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized primitive
byte - Throws:
IOException- A problem occurs while reading fromin- Since:
- GemFire 5.1
- See Also:
DataInput.readByte()
-
writePrimitiveChar
public static void writePrimitiveChar(char value, DataOutput out) throws IOExceptionWrites a primitivecharto aDataOutput.- Parameters:
value- the primitivecharto writeout- theDataInputto write to- Throws:
IOException- A problem occurs while writing toout- Since:
- GemFire 5.1
- See Also:
DataOutput.writeChar(int)
-
readPrimitiveChar
public static char readPrimitiveChar(DataInput in) throws IOException
Reads a primitivecharfrom aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized primitive
char - Throws:
IOException- A problem occurs while reading fromin- Since:
- GemFire 5.1
- See Also:
DataInput.readChar()
-
writePrimitiveShort
public static void writePrimitiveShort(short value, DataOutput out) throws IOExceptionWrites a primitiveshortto aDataOutput.- Parameters:
value- the primitiveshortto writeout- theDataInputto write to- Throws:
IOException- A problem occurs while writing toout- Since:
- GemFire 5.1
- See Also:
DataOutput.writeShort(int)
-
readPrimitiveShort
public static short readPrimitiveShort(DataInput in) throws IOException
Reads a primitiveshortfrom aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized primitive
short - Throws:
IOException- A problem occurs while reading fromin- Since:
- GemFire 5.1
- See Also:
DataInput.readShort()
-
writeUnsignedByte
public static void writeUnsignedByte(int value, DataOutput out) throws IOExceptionWrites a primitiveintas an unsigned byte to aDataOutput.- Parameters:
value- the primitiveintas an unsigned byte to writeout- theDataInputto write to- Throws:
IOException- A problem occurs while writing toout- Since:
- GemFire 5.1
- See Also:
DataOutput.writeByte(int),DataInput.readUnsignedByte()
-
readUnsignedByte
public static int readUnsignedByte(DataInput in) throws IOException
- Parameters:
in- theDataInputto read from- Returns:
- the deserialized primitive
intas an unsigned byte - Throws:
IOException- A problem occurs while reading fromin- Since:
- GemFire 5.1
-
writeUnsignedShort
public static void writeUnsignedShort(int value, DataOutput out) throws IOExceptionWrites a primitiveintas an unsigned short to aDataOutput.- Parameters:
value- the primitiveintas an unsigned short to writeout- theDataInputto write to- Throws:
IOException- A problem occurs while writing toout- Since:
- GemFire 5.1
- See Also:
DataOutput.writeShort(int),DataInput.readUnsignedShort()
-
readUnsignedShort
public static int readUnsignedShort(DataInput in) throws IOException
- Parameters:
in- theDataInputto read from- Returns:
- the deserialized primitive
intas an unsigned short - Throws:
IOException- A problem occurs while reading fromin- Since:
- GemFire 5.1
-
writePrimitiveInt
public static void writePrimitiveInt(int value, DataOutput out) throws IOExceptionWrites a primitiveintto aDataOutput.- Parameters:
value- the primitiveintto writeout- theDataOutputto write to- Throws:
IOException- A problem occurs while writing toout- See Also:
DataOutput.writeInt(int)
-
readPrimitiveInt
public static int readPrimitiveInt(DataInput in) throws IOException
Reads a primitiveintfrom aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- a primitive
int - Throws:
IOException- A problem occurs while reading fromin- Since:
- GemFire 5.1
- See Also:
DataInput.readInt()
-
writePrimitiveLong
public static void writePrimitiveLong(long value, DataOutput out) throws IOExceptionWrites a primitivelongto aDataOutput.- Parameters:
value- the primitivelongto writeout- theDataOutputto write to- Throws:
IOException- A problem occurs while writing toout- Since:
- GemFire 5.1
- See Also:
DataOutput.writeLong(long)
-
readPrimitiveLong
public static long readPrimitiveLong(DataInput in) throws IOException
Reads a primitivelongfrom aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- a primitive
long - Throws:
IOException- A problem occurs while reading fromin- Since:
- GemFire 5.1
- See Also:
DataInput.readLong()
-
writePrimitiveFloat
public static void writePrimitiveFloat(float value, DataOutput out) throws IOExceptionWrites a primitivefloatto aDataOutput.- Parameters:
value- the primitivefloatto writeout- theDataOutputto write to- Throws:
IOException- A problem occurs while writing toout- Since:
- GemFire 5.1
- See Also:
DataOutput.writeFloat(float)
-
readPrimitiveFloat
public static float readPrimitiveFloat(DataInput in) throws IOException
Reads a primitivefloatfrom aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- a primitive
float - Throws:
IOException- A problem occurs while reading fromin- Since:
- GemFire 5.1
- See Also:
DataInput.readFloat()
-
writePrimitiveDouble
public static void writePrimitiveDouble(double value, DataOutput out) throws IOExceptionWrites a primtivedoubleto aDataOutput.- Parameters:
value- the primitivedoubleto writeout- theDataOutputto write to- Throws:
IOException- A problem occurs while writing toout- Since:
- GemFire 5.1
- See Also:
DataOutput.writeDouble(double)
-
readPrimitiveDouble
public static double readPrimitiveDouble(DataInput in) throws IOException
Reads a primitivedoublefrom aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- a primitive
double - Throws:
IOException- A problem occurs while reading fromin- Since:
- GemFire 5.1
- See Also:
DataInput.readDouble()
-
writeByteArray
public static void writeByteArray(byte[] array, DataOutput out) throws 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:
IOException- A problem occurs while writing toout- See Also:
readByteArray(java.io.DataInput)
-
writeByteArray
public static void writeByteArray(byte[] array, int len, DataOutput out) throws 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:
IOException- A problem occurs while writing toout- See Also:
readByteArray(java.io.DataInput)
-
writeObjectAsByteArray
public static void writeObjectAsByteArray(Object obj, DataOutput out) throws IOException
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. 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:
IllegalArgumentException- if a problem occurs while serializeobjIOException- if a problem occurs while writing toout- Since:
- GemFire 5.0.2
- See Also:
readByteArray(java.io.DataInput)
-
readByteArray
public static byte[] readByteArray(DataInput in) throws IOException
Reads an array ofbytes from aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized array of
bytes - Throws:
IOException- A problem occurs while reading fromin- See Also:
writeByteArray(byte[], DataOutput)
-
writeStringArray
public static void writeStringArray(String[] array, DataOutput out) throws IOException
Writes 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:
IOException- A problem occurs while writing toout- 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 ofStrings from aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized array of
Strings - Throws:
IOException- A problem occurs while reading fromin- See Also:
writeStringArray(java.lang.String[], java.io.DataOutput)
-
writeShortArray
public static void writeShortArray(short[] array, DataOutput out) throws 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:
IOException- A problem occurs while writing toout- See Also:
readShortArray(java.io.DataInput)
-
readShortArray
public static short[] readShortArray(DataInput in) throws IOException
Reads an array ofshorts from aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized array of
shorts - Throws:
IOException- A problem occurs while reading fromin- See Also:
writeShortArray(short[], java.io.DataOutput)
-
writeCharArray
public static void writeCharArray(char[] array, DataOutput out) throws IOExceptionWrites an array ofchars to aDataOutput.- Parameters:
array- the array ofchars to writeout- theDataInputto write to- Throws:
IOException- A problem occurs while writing toout- Since:
- GemFire 5.7
- See Also:
readCharArray(java.io.DataInput)
-
readCharArray
public static char[] readCharArray(DataInput in) throws IOException
Reads an array ofchars from aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized array of
chars - Throws:
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, DataOutput out) throws IOExceptionWrites an array ofbooleans to aDataOutput.- Parameters:
array- the array ofbooleans to writeout- theDataInputto write to- Throws:
IOException- A problem occurs while writing toout- Since:
- GemFire 5.7
- See Also:
readBooleanArray(java.io.DataInput)
-
readBooleanArray
public static boolean[] readBooleanArray(DataInput in) throws IOException
Reads an array ofbooleans from aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized array of
booleans - Throws:
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, DataOutput out) throws IOExceptionWrites anintarray to aDataOutput. This method will serialize anullarray and not throw aNullPointerException.- Parameters:
array- the array ofints to writeout- theDataInputto write to- Throws:
IOException- A problem occurs while writing toout- See Also:
readIntArray(java.io.DataInput)
-
readIntArray
public static int[] readIntArray(DataInput in) throws IOException
Reads anintarray from aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized array of
ints - Throws:
IOException- A problem occurs while reading fromin- See Also:
writeIntArray(int[], java.io.DataOutput)
-
writeLongArray
public static void writeLongArray(long[] array, DataOutput out) throws 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:
IOException- A problem occurs while writing toout- See Also:
readLongArray(java.io.DataInput)
-
readLongArray
public static long[] readLongArray(DataInput in) throws IOException
Reads an array oflongs from aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized array of
longs - Throws:
IOException- A problem occurs while reading fromin- See Also:
writeLongArray(long[], java.io.DataOutput)
-
writeFloatArray
public static void writeFloatArray(float[] array, DataOutput out) throws 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:
IOException- A problem occurs while writing toout- See Also:
readFloatArray(java.io.DataInput)
-
readFloatArray
public static float[] readFloatArray(DataInput in) throws IOException
Reads an array offloats from aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized array of
floats - Throws:
IOException- A problem occurs while reading fromin- See Also:
writeFloatArray(float[], java.io.DataOutput)
-
writeDoubleArray
public static void writeDoubleArray(double[] array, DataOutput out) throws 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:
IOException- A problem occurs while writing toout- See Also:
readDoubleArray(java.io.DataInput)
-
readDoubleArray
public static double[] readDoubleArray(DataInput in) throws IOException
Reads an array ofdoubles from aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized array of
doubles - Throws:
IOException- A problem occurs while reading fromin- See Also:
writeDoubleArray(double[], java.io.DataOutput)
-
writeObjectArray
public static void writeObjectArray(Object[] array, DataOutput out) throws IOException
Writes 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:
IOException- A problem occurs while writing toout- See Also:
readObjectArray(java.io.DataInput),writeObject(Object, DataOutput)
-
readObjectArray
public static Object[] readObjectArray(DataInput in) throws IOException, ClassNotFoundException
Reads an array ofObjects from aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized array of
Objects - Throws:
IOException- A problem occurs while reading frominClassNotFoundException- 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, DataOutput out) throws IOExceptionWrites an array ofbyte[]to aDataOutput.- Parameters:
array- the array ofbyte[]s to writeout- theDataInputto write to- Throws:
IOException- A problem occurs while writing toout.
-
readArrayOfByteArrays
public static byte[][] readArrayOfByteArrays(DataInput in) throws IOException
Reads an array ofbyte[]s from aDataInput.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized array of
byte[]s - Throws:
IOException- A problem occurs while reading fromin
-
writeArrayList
public static void writeArrayList(ArrayList<?> list, DataOutput out) throws IOException
Writes 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:
IOException- A problem occurs while writing toout- See Also:
readArrayList(java.io.DataInput)
-
readArrayList
public static <E> ArrayList<E> readArrayList(DataInput in) throws IOException, ClassNotFoundException
Reads anArrayListfrom aDataInput.- Type Parameters:
E- – the type of elements in the list- Parameters:
in- theDataInputto read from- Returns:
- the deserialized
ArrayList - Throws:
IOException- A problem occurs while reading frominClassNotFoundException- 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(Vector<?> list, DataOutput out) throws IOException
Writes anVectorto 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- theDataInputto write to- Throws:
IOException- A problem occurs while writing toout- Since:
- GemFire 5.7
- See Also:
readVector(java.io.DataInput)
-
readVector
public static <E> Vector<E> readVector(DataInput in) throws IOException, ClassNotFoundException
Reads anVectorfrom aDataInput.- Type Parameters:
E- – the type of elements in the vector- Parameters:
in- theDataInputto read from- Returns:
- the deserialized
Vector - Throws:
IOException- A problem occurs while reading frominClassNotFoundException- 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(Stack<?> list, DataOutput out) throws IOException
Writes anStackto 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:
IOException- A problem occurs while writing toout- Since:
- GemFire 5.7
- See Also:
readStack(java.io.DataInput)
-
readStack
public static <E> Stack<E> readStack(DataInput in) throws IOException, ClassNotFoundException
Reads anStackfrom aDataInput.- Type Parameters:
E- – the type of elements in the stack- Parameters:
in- theDataInputto read from- Returns:
- the deserialized
Stack - Throws:
IOException- A problem occurs while reading frominClassNotFoundException- 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(LinkedList<?> list, DataOutput out) throws IOException
Writes anLinkedListto 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:
IOException- A problem occurs while writing toout- See Also:
readLinkedList(java.io.DataInput)
-
readLinkedList
public static <E> LinkedList<E> readLinkedList(DataInput in) throws IOException, ClassNotFoundException
Reads anLinkedListfrom aDataInput.- Type Parameters:
E- – the type of elements in the list- Parameters:
in- theDataInputto read from- Returns:
- the deserialized
LinkedList - Throws:
IOException- A problem occurs while reading frominClassNotFoundException- 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(HashSet<?> set, DataOutput out) throws IOException
Writes 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:
IOException- A problem occurs while writing toout- See Also:
readHashSet(java.io.DataInput)
-
readHashSet
public static <E> HashSet<E> readHashSet(DataInput in) throws IOException, ClassNotFoundException
Reads aHashSetfrom aDataInput.- Type Parameters:
E- – the type of elements in the set- Parameters:
in- theDataInputto read from- Returns:
- the deserialized
HashSet - Throws:
IOException- A problem occurs while reading frominClassNotFoundException- 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(LinkedHashSet<?> set, DataOutput out) throws IOException
Writes 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:
IOException- A problem occurs while writing toout- Since:
- GemFire 5.7
- See Also:
readLinkedHashSet(java.io.DataInput)
-
readLinkedHashSet
public static <E> LinkedHashSet<E> readLinkedHashSet(DataInput in) throws IOException, ClassNotFoundException
Reads aLinkedHashSetfrom aDataInput.- Type Parameters:
E- – the type of elements in the set- Parameters:
in- theDataInputto read from- Returns:
- the deserialized
LinkedHashSet - Throws:
IOException- A problem occurs while reading frominClassNotFoundException- 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(Map<?,?> map, DataOutput out) throws IOException
Writes 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:
IOException- A problem occurs while writing toout- See Also:
readHashMap(java.io.DataInput)
-
readHashMap
public static <K,V> HashMap<K,V> readHashMap(DataInput in) throws IOException, ClassNotFoundException
Reads 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:
IOException- A problem occurs while reading frominClassNotFoundException- 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(IdentityHashMap<?,?> map, DataOutput out) throws IOException
Writes aIdentityHashMapto 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:
IOException- A problem occurs while writing toout- See Also:
readIdentityHashMap(java.io.DataInput)
-
readIdentityHashMap
public static <K,V> IdentityHashMap<K,V> readIdentityHashMap(DataInput in) throws IOException, ClassNotFoundException
Reads aIdentityHashMapfrom 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:
IOException- A problem occurs while reading frominClassNotFoundException- 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(ConcurrentHashMap<?,?> map, DataOutput out) throws IOException
Writes 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:
IOException- A problem occurs while writing toout- Since:
- GemFire 6.6
- See Also:
readConcurrentHashMap(java.io.DataInput)
-
readConcurrentHashMap
public static <K,V> ConcurrentHashMap<K,V> readConcurrentHashMap(DataInput in) throws IOException, ClassNotFoundException
Reads 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:
IOException- A problem occurs while reading frominClassNotFoundException- 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(Hashtable<?,?> map, DataOutput out) throws IOException
Writes 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:
IOException- A problem occurs while writing toout- Since:
- GemFire 5.7
- See Also:
readHashtable(java.io.DataInput)
-
readHashtable
public static <K,V> Hashtable<K,V> readHashtable(DataInput in) throws IOException, ClassNotFoundException
Reads 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:
IOException- A problem occurs while reading frominClassNotFoundException- 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(TreeMap<?,?> map, DataOutput out) throws IOException
Writes 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:
IOException- A problem occurs while writing toout- Since:
- GemFire 5.7
- See Also:
readTreeMap(java.io.DataInput)
-
readTreeMap
public static <K,V> TreeMap<K,V> readTreeMap(DataInput in) throws IOException, ClassNotFoundException
Reads 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:
IOException- A problem occurs while reading frominClassNotFoundException- 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(Map<?,?> map, DataOutput out) throws IOException
Writes 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:
IOException- A problem occurs while writing toout- See Also:
readLinkedHashMap(java.io.DataInput)
-
readLinkedHashMap
public static <K,V> LinkedHashMap<K,V> readLinkedHashMap(DataInput in) throws IOException, ClassNotFoundException
Reads 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:
IOException- A problem occurs while reading frominClassNotFoundException- 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(TreeSet<?> set, DataOutput out) throws IOException
Writes 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:
IOException- A problem occurs while writing toout- See Also:
readTreeSet(java.io.DataInput)
-
readTreeSet
public static <E> TreeSet<E> readTreeSet(DataInput in) throws IOException, ClassNotFoundException
Reads aTreeSetfrom aDataInput.- Type Parameters:
E- the type contained in theTreeSet- Parameters:
in- theDataInputto read from- Returns:
- the deserialized
TreeSet - Throws:
IOException- A problem occurs while reading frominClassNotFoundException- 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(Properties props, DataOutput out) throws IOException
Writes 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:
IOException- A problem occurs while writing toout- See Also:
readProperties(java.io.DataInput)
-
readProperties
public static Properties readProperties(DataInput in) throws IOException, ClassNotFoundException
Reads aPropertiesfrom aDataInput.NOTE: the
defaultsare always empty in the returnedProperties.- Parameters:
in- theDataInputto read from- Returns:
- the deserialized Properties
- Throws:
IOException- If this serializer cannot read an object fromin.ClassNotFoundException- If the class cannot be loaded- See Also:
writeProperties(java.util.Properties, java.io.DataOutput)
-
writeObject
public static void writeObject(Object o, DataOutput out, boolean allowJavaSerialization) throws IOException
Writes an arbitrary object to aDataOutput. Ifois not an instance of a specially-handled standard Java class (see the list ingetSupportedClasses()), thetoDatamethod of each registeredDataSerializeris invoked until the object is serialized. If no registered serializer can serialize the object andodoes not implementDataSerializable, then it is serialized tooutusing standard Java serialization. This method will serialize anullo and not throw aNullPointerException.- 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 subobject ofo. This is used to prevent Java serialization from being used when sending data to a non-Java client- Throws:
IOException- A problem occurs while writingotoout- See Also:
readObject(DataInput),Instantiator,ObjectOutputStream.writeObject(java.lang.Object)
-
writeObject
public static void writeObject(Object o, DataOutput out) throws IOException
Writes an arbitrary object to aDataOutput. Ifois not an instance of a specially-handled standard Java class (such asDate,Integer, orArrayList), thetoDatamethod of each registeredDataSerializeris invoked until the object is serialized. If no registered serializer can serialize the object andodoes not implementDataSerializable, then it is serialized tooutusing standard Java serialization. This method will serialize anullo and not throw aNullPointerException.- Parameters:
o- the object to writeout- theDataOutputto write to- Throws:
IOException- A problem occurs while writingotoout- See Also:
readObject(DataInput),DataSerializer,ObjectOutputStream.writeObject(java.lang.Object)
-
readObject
public static <T> T readObject(DataInput in) throws IOException, ClassNotFoundException
Reads 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:
IOException- A problem occurred while reading fromin(may wrap another exception)ClassNotFoundException- The class of an object read fromincould not be found- See Also:
writeObject(Object, DataOutput),ObjectInputStream.readObject()
-
register
public static DataSerializer register(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:
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 elementsIllegalStateException- 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 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 serializer:- Returns:
- the
Classes whose instances are data serialized by thisDataSerializer
-
toData
public abstract boolean toData(Object o, DataOutput out) throws IOException
Data 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:
IOException- If this serializer cannot write an object toout.
-
fromData
public abstract Object fromData(DataInput in) throws IOException, ClassNotFoundException
Reads 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:
IOException- If this serializer cannot read an object fromin.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(Object o)
TwoDataSerializers are consider to be equal if they have the same id and the same class
-
setEventId
public void setEventId(Object eventId)
For internal use only. Sets the uniqueeventIdof thisDataSerializer.- Parameters:
eventId- the uniqueeventIdof thisDataSerializer- Since:
- GemFire 6.5
-
getEventId
public Object getEventId()
For internal use only. Returns the uniqueeventIdof thisDataSerializer.- Returns:
- the unique
eventIdof thisDataSerializer - Since:
- GemFire 6.5
-
setContext
public void setContext(Object context)
For internal use only. Sets the context of thisDataSerializer.- Parameters:
context- the context of thisDataSerializer- Since:
- GemFire 6.5
-
getContext
public 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(Enum<?> e, DataOutput out) throws IOException
Writes 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:
IOException- if a problem occurs while writing toout- Since:
- GemFire 6.5
- See Also:
readEnum(Class, DataInput)
-
readEnum
public static <E extends Enum<E>> E readEnum(Class<E> clazz, DataInput in) throws IOException
Reads aEnum 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:
IOException- if a problem occurs while reading frominArrayIndexOutOfBoundsException- 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)
-
-