Package org.jivesoftware.util.cache
Class DefaultExternalizableUtil
java.lang.Object
org.jivesoftware.util.cache.DefaultExternalizableUtil
- All Implemented Interfaces:
ExternalizableUtilStrategy
Default serialization strategy.
- Author:
- Tom Evans, Gaston Dombiak
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Class<?>
loadClass
(ClassLoader classLoader, String className) static Class<?>
static ObjectInputStream
static ObjectInputStream
newObjectInputStream
(ClassLoader classLoader, InputStream in) boolean
readBoolean
(DataInput in) byte[]
int
readExternalizableCollection
(DataInput in, Collection<? extends Externalizable> value, ClassLoader loader) Reads a collection of Externalizable objects and adds them to the collection passed as a parameter.int
readExternalizableMap
(DataInput in, Map<String, ? extends Externalizable> map, ClassLoader loader) Reads a Map of String key and value pairs.int
long
long[]
Reads an array of long values.Reads a Map of Long key and Integer value pairs.static Object
readObject
(DataInput in) static Object
readObject
(ClassLoader classLoader, DataInput in) readSafeUTF
(DataInput in) int
readSerializableCollection
(DataInput in, Collection<? extends Serializable> value, ClassLoader loader) Reads a collection of Serializable objects and adds them to the collection passed as a parameter.int
readSerializableMap
(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.int
readStrings
(DataInput in, Collection<String> collection) int
Reads a Map of String key and Set of Strings value pairs.void
writeBoolean
(DataOutput out, boolean value) void
writeByteArray
(DataOutput out, byte[] value) void
writeExternalizableCollection
(DataOutput out, Collection<? extends Externalizable> value) Writes a collection of Externalizable objects.void
writeExternalizableMap
(DataOutput out, Map<String, ? extends Externalizable> map) Writes a Map of String key and value pairs.void
writeInt
(DataOutput out, int value) void
writeLong
(DataOutput out, long value) void
writeLongArray
(DataOutput out, long[] array) Writes an array of long values.void
writeLongIntMap
(DataOutput out, Map<Long, Integer> map) Writes a Map of Long key and Integer value pairs.static void
writeObject
(DataOutput out, Object obj) void
writeSafeUTF
(DataOutput out, String value) void
writeSerializable
(DataOutput out, Serializable value) void
writeSerializableCollection
(DataOutput out, Collection<? extends Serializable> value) Writes a collection of Serializable objects.void
writeSerializableMap
(DataOutput out, Map<? extends Serializable, ? extends Serializable> map) Writes a Map of Serializable key and value pairs.void
writeStringList
(DataOutput out, List<String> stringList) Writes a List of Strings.void
writeStringMap
(DataOutput out, Map<String, String> stringMap) Writes a Map of String key and value pairs.void
writeStrings
(DataOutput out, Collection<String> collection) void
writeStringsMap
(DataOutput out, Map<String, Set<String>> map) Writes a Map of String key and Set of Strings value pairs.
-
Constructor Details
-
DefaultExternalizableUtil
public DefaultExternalizableUtil()
-
-
Method Details
-
writeStringMap
Writes a Map of String key and value pairs. This method handles the case when the Map is null.- Specified by:
writeStringMap
in interfaceExternalizableUtilStrategy
- 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 return null if the Map written to the stream was null.- Specified by:
readStringMap
in interfaceExternalizableUtilStrategy
- Parameters:
in
- the input stream.- Returns:
- a Map of String key/value pairs.
- 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 is null.- Specified by:
writeStringsMap
in interfaceExternalizableUtilStrategy
- 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.- Specified by:
readStringsMap
in interfaceExternalizableUtilStrategy
- 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.
-
writeLongIntMap
Writes a Map of Long key and Integer value pairs. This method handles the case when the Map is null.- Specified by:
writeLongIntMap
in interfaceExternalizableUtilStrategy
- 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 return null if the Map written to the stream was null.- Specified by:
readLongIntMap
in interfaceExternalizableUtilStrategy
- 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 is null.- Specified by:
writeStringList
in interfaceExternalizableUtilStrategy
- 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 return null if the List written to the stream was null.- Specified by:
readStringList
in interfaceExternalizableUtilStrategy
- 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 is null.- Specified by:
writeLongArray
in interfaceExternalizableUtilStrategy
- 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 return null if the array written to the stream was null.- Specified by:
readLongArray
in interfaceExternalizableUtilStrategy
- Parameters:
in
- the input stream.- Returns:
- an array of long values.
- Throws:
IOException
- if an error occurs.
-
writeLong
- Specified by:
writeLong
in interfaceExternalizableUtilStrategy
- Throws:
IOException
-
readLong
- Specified by:
readLong
in interfaceExternalizableUtilStrategy
- Throws:
IOException
-
writeByteArray
- Specified by:
writeByteArray
in interfaceExternalizableUtilStrategy
- Throws:
IOException
-
readByteArray
- Specified by:
readByteArray
in interfaceExternalizableUtilStrategy
- Throws:
IOException
-
writeInt
- Specified by:
writeInt
in interfaceExternalizableUtilStrategy
- Throws:
IOException
-
readInt
- Specified by:
readInt
in interfaceExternalizableUtilStrategy
- Throws:
IOException
-
writeBoolean
- Specified by:
writeBoolean
in interfaceExternalizableUtilStrategy
- Throws:
IOException
-
readBoolean
- Specified by:
readBoolean
in interfaceExternalizableUtilStrategy
- Throws:
IOException
-
writeSerializable
- Specified by:
writeSerializable
in interfaceExternalizableUtilStrategy
- Throws:
IOException
-
readSerializable
- Specified by:
readSerializable
in interfaceExternalizableUtilStrategy
- Throws:
IOException
-
writeSafeUTF
- Specified by:
writeSafeUTF
in interfaceExternalizableUtilStrategy
- Throws:
IOException
-
readSafeUTF
- Specified by:
readSafeUTF
in interfaceExternalizableUtilStrategy
- 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 a null value.- Specified by:
writeExternalizableCollection
in interfaceExternalizableUtilStrategy
- 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 a null value.- Specified by:
writeSerializableCollection
in interfaceExternalizableUtilStrategy
- 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 a null value.- Specified by:
readExternalizableCollection
in interfaceExternalizableUtilStrategy
- 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.
-
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 a null value.- Specified by:
readSerializableCollection
in interfaceExternalizableUtilStrategy
- 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.
-
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 is null.- Specified by:
writeExternalizableMap
in interfaceExternalizableUtilStrategy
- Parameters:
out
- the output stream.map
- the Map of String key and Externalizable value pairs.- 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 is null.- Specified by:
writeSerializableMap
in interfaceExternalizableUtilStrategy
- 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 return null if the Map written to the stream was null.- Specified by:
readExternalizableMap
in interfaceExternalizableUtilStrategy
- 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 return null if the Map written to the stream was null.- Specified by:
readSerializableMap
in interfaceExternalizableUtilStrategy
- 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.
-
writeStrings
- Specified by:
writeStrings
in interfaceExternalizableUtilStrategy
- Throws:
IOException
-
readStrings
- Specified by:
readStrings
in interfaceExternalizableUtilStrategy
- Throws:
IOException
-
writeObject
- Throws:
IOException
-
readObject
- Throws:
IOException
-
readObject
- Throws:
IOException
-
newObjectInputStream
public static ObjectInputStream newObjectInputStream(@Nullable ClassLoader classLoader, InputStream in) throws IOException - Throws:
IOException
-
newObjectInputStream
- Throws:
IOException
-
loadClass
- Throws:
ClassNotFoundException
-
loadClass
public static Class<?> loadClass(@Nullable ClassLoader classLoader, String className) throws ClassNotFoundException - Throws:
ClassNotFoundException
-