Package org.jivesoftware.util.cache
Class ExternalizableUtil
java.lang.Object
org.jivesoftware.util.cache.ExternalizableUtil
Utility methods to assist in working with the
Externalizable interfaces.- Author:
- Gaston Dombiak
-
Method Summary
Modifier and TypeMethodDescriptionstatic ExternalizableUtilReturns the implementation to use for serializing and deserializing objects.booleanreadBoolean(DataInput in) byte[]intreadExternalizableCollection(DataInput in, Collection<? extends Externalizable> value, ClassLoader loader) Reads a collection of Externalizable objects and adds them to the collection passed as a parameter.intreadExternalizableMap(DataInput in, Map<String, ? extends Externalizable> map, ClassLoader loader) Reads a Map of String key and value pairs.intlonglong[]Reads an array of long values.Reads a Map of Long key and Integer value pairs.readSafeUTF(DataInput in) intreadSerializableCollection(DataInput in, Collection<? extends Serializable> value, ClassLoader loader) Reads a collection of Serializable objects and adds them to the collection passed as a parameter.intreadSerializableMap(DataInput in, Map<? extends Serializable, ? extends Serializable> map, ClassLoader loader) Reads a Map of Serializable key and value pairs.Reads a List of Strings.Reads a Map of String key and value pairs.intreadStrings(DataInput in, Collection<String> collection) Reads the string array from the input stream and adds them to the specified collection.intReads a Map of String key and Set of Strings value pairs.org.dom4j.ElementReads an XML element from the input stream.voidsetStrategy(ExternalizableUtilStrategy strategy) Sets the implementation to use for serializing and deserializing objects.voidwriteBoolean(DataOutput out, boolean value) voidwriteByteArray(DataOutput out, byte[] value) voidwriteExternalizableCollection(DataOutput out, Collection<? extends Externalizable> value) Writes a collection of Externalizable objects.voidwriteExternalizableMap(DataOutput out, Map<String, ? extends Externalizable> map) Writes a Map of String key and value pairs.voidwriteInt(DataOutput out, int value) voidwriteLong(DataOutput out, long value) voidwriteLongArray(DataOutput out, long[] array) Writes an array of long values.voidwriteLongIntMap(DataOutput out, Map<Long, Integer> map) Writes a Map of Long key and Integer value pairs.voidwriteSafeUTF(DataOutput out, String value) voidwriteSerializable(DataOutput out, Serializable value) voidwriteSerializableCollection(DataOutput out, Collection<? extends Serializable> value) Writes a collection of Serializable objects.voidwriteSerializableMap(DataOutput out, Map<? extends Serializable, ? extends Serializable> map) Writes a Map of Serializable key and value pairs.voidwriteStringList(DataOutput out, List<String> stringList) Writes a List of Strings.voidwriteStringMap(DataOutput out, Map<String, String> stringMap) Writes a Map of String key and value pairs.voidwriteStrings(DataOutput out, Collection<String> collection) Writes content of collection of strings to the output stream.voidwriteStringsMap(DataOutput out, Map<String, Set<String>> map) Writes a Map of String key and Set of Strings value pairs.voidwriteXML(DataOutput out, org.dom4j.Element element) Writes an XML element to the output.
-
Method Details
-
getInstance
-
setStrategy
Sets the implementation to use for serializing and deserializing objects.- Parameters:
strategy- the new strategy to use.
-
getStrategy
Returns the implementation to use for serializing and deserializing objects.- Returns:
- the implementation to use for serializing and deserializing objects.
-
writeStringMap
Writes a Map of String key and value pairs. This method handles the case when the Map isnull.- Parameters:
out- the output stream.stringMap- the Map of String key/value pairs.- Throws:
IOException- if an error occurs.
-
readStringMap
Reads a Map of String key and value pairs. This method will returnnullif the Map written to the stream wasnull.- Parameters:
in- the input stream.- Returns:
- a Map of String key/value pairs.
- Throws:
IOException- if an error occurs.
-
writeLongIntMap
Writes a Map of Long key and Integer value pairs. This method handles the case when the Map isnull.- Parameters:
out- the output stream.map- the Map of Long key/Integer value pairs.- Throws:
IOException- if an error occurs.
-
readLongIntMap
Reads a Map of Long key and Integer value pairs. This method will returnnullif the Map written to the stream wasnull.- Parameters:
in- the input stream.- Returns:
- a Map of Long key/Integer value pairs.
- Throws:
IOException- if an error occurs.
-
writeStringList
Writes a List of Strings. This method handles the case when the List isnull.- Parameters:
out- the output stream.stringList- the List of Strings.- Throws:
IOException- if an error occurs.
-
readStringList
Reads a List of Strings. This method will returnnullif the List written to the stream wasnull.- Parameters:
in- the input stream.- Returns:
- a List of Strings.
- Throws:
IOException- if an error occurs.
-
writeLongArray
Writes an array of long values. This method handles the case when the array isnull.- Parameters:
out- the output stream.array- the array of long values.- Throws:
IOException- if an error occurs.
-
readLongArray
Reads an array of long values. This method will returnnullif the array written to the stream wasnull.- Parameters:
in- the input stream.- Returns:
- an array of long values.
- Throws:
IOException- if an error occurs.
-
writeLong
- Throws:
IOException
-
readLong
- Throws:
IOException
-
writeInt
- Throws:
IOException
-
readInt
- Throws:
IOException
-
writeBoolean
- Throws:
IOException
-
readBoolean
- Throws:
IOException
-
writeByteArray
- Throws:
IOException
-
readByteArray
- Throws:
IOException
-
writeSerializable
- Throws:
IOException
-
readSerializable
- Throws:
IOException
-
writeSafeUTF
- Throws:
IOException
-
readSafeUTF
- Throws:
IOException
-
writeExternalizableCollection
public void writeExternalizableCollection(DataOutput out, Collection<? extends Externalizable> value) throws IOException Writes a collection of Externalizable objects. The collection passed as a parameter must be a collection and not anullvalue.- Parameters:
out- the output stream.value- the collection of Externalizable objects. This value must not be null.- Throws:
IOException- if an error occurs.
-
writeSerializableCollection
public void writeSerializableCollection(DataOutput out, Collection<? extends Serializable> value) throws IOException Writes a collection of Serializable objects. The collection passed as a parameter must be a collection and not anullvalue.- Parameters:
out- the output stream.value- the collection of Serializable objects. This value must not be null.- Throws:
IOException- if an error occurs.
-
readExternalizableCollection
public int readExternalizableCollection(DataInput in, Collection<? extends Externalizable> value, ClassLoader loader) throws IOException Reads a collection of Externalizable objects and adds them to the collection passed as a parameter. The collection passed as a parameter must be a collection and not anullvalue.- Parameters:
in- the input stream.value- the collection of Externalizable objects. This value must not be null.loader- class loader to use to build elements inside of the serialized collection.- Returns:
- the number of elements added to the collection.
- Throws:
IOException- if an error occurs.
-
writeExternalizableMap
public void writeExternalizableMap(DataOutput out, Map<String, ? extends Externalizable> map) throws IOExceptionWrites a Map of String key and value pairs. This method handles the case when the Map isnull.- Parameters:
out- the output stream.map- the Map of String key and Externalizable value pairs.- Throws:
IOException- if an error occurs.
-
readSerializableCollection
public int readSerializableCollection(DataInput in, Collection<? extends Serializable> value, ClassLoader loader) throws IOException Reads a collection of Serializable objects and adds them to the collection passed as a parameter. The collection passed as a parameter must be a collection and not anullvalue.- Parameters:
in- the input stream.value- the collection of Serializable objects. This value must not be null.loader- class loader to use to build elements inside of the serialized collection.- Returns:
- the number of elements added to the collection.
- Throws:
IOException- if an error occurs.
-
writeSerializableMap
public void writeSerializableMap(DataOutput out, Map<? extends Serializable, ? extends Serializable> map) throws IOExceptionWrites a Map of Serializable key and value pairs. This method handles the case when the Map isnull.- Parameters:
out- the output stream.map- the Map of Serializable key and value pairs.- Throws:
IOException- if an error occurs.
-
readExternalizableMap
public int readExternalizableMap(DataInput in, Map<String, ? extends Externalizable> map, ClassLoader loader) throws IOExceptionReads a Map of String key and value pairs. This method will returnnullif the Map written to the stream wasnull.- Parameters:
in- the input stream.map- a Map of String key and Externalizable value pairs.loader- class loader to use to build elements inside of the serialized collection.- Returns:
- the number of elements added to the collection.
- Throws:
IOException- if an error occurs.
-
readSerializableMap
public int readSerializableMap(DataInput in, Map<? extends Serializable, ? extends Serializable> map, ClassLoader loader) throws IOExceptionReads a Map of Serializable key and value pairs. This method will returnnullif the Map written to the stream wasnull.- Parameters:
in- the input stream.map- a Map of Serializable key and value pairs.loader- class loader to use to build elements inside of the serialized collection.- Returns:
- the number of elements added to the collection.
- Throws:
IOException- if an error occurs.
-
writeStringsMap
Writes a Map of String key and Set of Strings value pairs. This method DOES NOT handle the case when the Map isnull.- Parameters:
out- the output stream.map- the Map of String key and Set of Strings value pairs.- Throws:
IOException- if an error occurs.
-
readStringsMap
Reads a Map of String key and Set of Strings value pairs.- Parameters:
in- the input stream.map- a Map of String key and Set of Strings value pairs.- Returns:
- number of elements added to the collection.
- Throws:
IOException- if an error occurs.
-
writeStrings
Writes content of collection of strings to the output stream.- Parameters:
out- the output stream.collection- the Collection of Strings.- Throws:
IOException- if an error occurs.
-
readStrings
Reads the string array from the input stream and adds them to the specified collection.- Parameters:
in- the input stream.collection- the collection to add the read strings from the input stream.- Returns:
- number of elements added to the collection.
- Throws:
IOException- if an error occurs.
-
writeXML
Writes an XML element to the output.- Parameters:
out- the output stream.element- the XML element.- Throws:
IOException- if an error occurs.
-
readXML
Reads an XML element from the input stream.- Parameters:
in- The input stream- Returns:
- An XML element.
- Throws:
IOException- if an error occurs.
-