Package org.jivesoftware.util.cache
Class DefaultExternalizableUtil
- java.lang.Object
-
- org.jivesoftware.util.cache.DefaultExternalizableUtil
-
- All Implemented Interfaces:
ExternalizableUtilStrategy
public class DefaultExternalizableUtil extends Object implements ExternalizableUtilStrategy
Default serialization strategy.- Author:
- Tom Evans, Gaston Dombiak
-
-
Constructor Summary
Constructors Constructor Description DefaultExternalizableUtil()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Class<?>loadClass(ClassLoader classLoader, String className)static Class<?>loadClass(String className)static ObjectInputStreamnewObjectInputStream(InputStream in)booleanreadBoolean(DataInput in)byte[]readByteArray(DataInput in)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.intreadInt(DataInput in)longreadLong(DataInput in)long[]readLongArray(DataInput in)Reads an array of long values.Map<Long,Integer>readLongIntMap(DataInput in)Reads a Map of Long key and Integer value pairs.static ObjectreadObject(DataInput in)StringreadSafeUTF(DataInput in)SerializablereadSerializable(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.List<String>readStringList(DataInput in)Reads a List of Strings.Map<String,String>readStringMap(DataInput in)Reads a Map of String key and value pairs.intreadStrings(DataInput in, Collection<String> collection)intreadStringsMap(DataInput in, Map<String,Set<String>> map)Reads a Map of String key and Set of Strings value pairs.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.static voidwriteObject(DataOutput out, Object obj)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)voidwriteStringsMap(DataOutput out, Map<String,Set<String>> map)Writes a Map of String key and Set of Strings value pairs.
-
-
-
Method Detail
-
writeStringMap
public void writeStringMap(DataOutput out, Map<String,String> stringMap) throws IOException
Writes a Map of String key and value pairs. This method handles the case when the Map is null.- Specified by:
writeStringMapin interfaceExternalizableUtilStrategy- Parameters:
out- the output stream.stringMap- the Map of String key/value pairs.- Throws:
IOException- if an error occurs.
-
readStringMap
public Map<String,String> readStringMap(DataInput in) throws IOException
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:
readStringMapin interfaceExternalizableUtilStrategy- Parameters:
in- the input stream.- Returns:
- a Map of String key/value pairs.
- Throws:
IOException- if an error occurs.
-
writeStringsMap
public void writeStringsMap(DataOutput out, Map<String,Set<String>> map) throws IOException
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:
writeStringsMapin 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
public int readStringsMap(DataInput in, Map<String,Set<String>> map) throws IOException
Reads a Map of String key and Set of Strings value pairs.- Specified by:
readStringsMapin 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
public void writeLongIntMap(DataOutput out, Map<Long,Integer> map) throws IOException
Writes a Map of Long key and Integer value pairs. This method handles the case when the Map is null.- Specified by:
writeLongIntMapin interfaceExternalizableUtilStrategy- Parameters:
out- the output stream.map- the Map of Long key/Integer value pairs.- Throws:
IOException- if an error occurs.
-
readLongIntMap
public Map<Long,Integer> readLongIntMap(DataInput in) throws IOException
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:
readLongIntMapin interfaceExternalizableUtilStrategy- Parameters:
in- the input stream.- Returns:
- a Map of Long key/Integer value pairs.
- Throws:
IOException- if an error occurs.
-
writeStringList
public void writeStringList(DataOutput out, List<String> stringList) throws IOException
Writes a List of Strings. This method handles the case when the List is null.- Specified by:
writeStringListin interfaceExternalizableUtilStrategy- Parameters:
out- the output stream.stringList- the List of Strings.- Throws:
IOException- if an error occurs.
-
readStringList
public List<String> readStringList(DataInput in) throws IOException
Reads a List of Strings. This method will return null if the List written to the stream was null.- Specified by:
readStringListin interfaceExternalizableUtilStrategy- Parameters:
in- the input stream.- Returns:
- a List of Strings.
- Throws:
IOException- if an error occurs.
-
writeLongArray
public void writeLongArray(DataOutput out, long[] array) throws IOException
Writes an array of long values. This method handles the case when the array is null.- Specified by:
writeLongArrayin interfaceExternalizableUtilStrategy- Parameters:
out- the output stream.array- the array of long values.- Throws:
IOException- if an error occurs.
-
readLongArray
public long[] readLongArray(DataInput in) throws IOException
Reads an array of long values. This method will return null if the array written to the stream was null.- Specified by:
readLongArrayin interfaceExternalizableUtilStrategy- Parameters:
in- the input stream.- Returns:
- an array of long values.
- Throws:
IOException- if an error occurs.
-
writeLong
public void writeLong(DataOutput out, long value) throws IOException
- Specified by:
writeLongin interfaceExternalizableUtilStrategy- Throws:
IOException
-
readLong
public long readLong(DataInput in) throws IOException
- Specified by:
readLongin interfaceExternalizableUtilStrategy- Throws:
IOException
-
writeByteArray
public void writeByteArray(DataOutput out, byte[] value) throws IOException
- Specified by:
writeByteArrayin interfaceExternalizableUtilStrategy- Throws:
IOException
-
readByteArray
public byte[] readByteArray(DataInput in) throws IOException
- Specified by:
readByteArrayin interfaceExternalizableUtilStrategy- Throws:
IOException
-
writeInt
public void writeInt(DataOutput out, int value) throws IOException
- Specified by:
writeIntin interfaceExternalizableUtilStrategy- Throws:
IOException
-
readInt
public int readInt(DataInput in) throws IOException
- Specified by:
readIntin interfaceExternalizableUtilStrategy- Throws:
IOException
-
writeBoolean
public void writeBoolean(DataOutput out, boolean value) throws IOException
- Specified by:
writeBooleanin interfaceExternalizableUtilStrategy- Throws:
IOException
-
readBoolean
public boolean readBoolean(DataInput in) throws IOException
- Specified by:
readBooleanin interfaceExternalizableUtilStrategy- Throws:
IOException
-
writeSerializable
public void writeSerializable(DataOutput out, Serializable value) throws IOException
- Specified by:
writeSerializablein interfaceExternalizableUtilStrategy- Throws:
IOException
-
readSerializable
public Serializable readSerializable(DataInput in) throws IOException
- Specified by:
readSerializablein interfaceExternalizableUtilStrategy- Throws:
IOException
-
writeSafeUTF
public void writeSafeUTF(DataOutput out, String value) throws IOException
- Specified by:
writeSafeUTFin interfaceExternalizableUtilStrategy- Throws:
IOException
-
readSafeUTF
public String readSafeUTF(DataInput in) throws IOException
- Specified by:
readSafeUTFin 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:
writeExternalizableCollectionin 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:
writeSerializableCollectionin 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:
readExternalizableCollectionin 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:
readSerializableCollectionin 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 IOException
Writes a Map of String key and value pairs. This method handles the case when the Map is null.- Specified by:
writeExternalizableMapin 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 IOException
Writes a Map of Serializable key and value pairs. This method handles the case when the Map is null.- Specified by:
writeSerializableMapin 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 IOException
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:
readExternalizableMapin 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 IOException
Reads a Map of Serializable key and value pairs. This method will return null if the Map written to the stream was null.- Specified by:
readSerializableMapin 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
public void writeStrings(DataOutput out, Collection<String> collection) throws IOException
- Specified by:
writeStringsin interfaceExternalizableUtilStrategy- Throws:
IOException
-
readStrings
public int readStrings(DataInput in, Collection<String> collection) throws IOException
- Specified by:
readStringsin interfaceExternalizableUtilStrategy- Throws:
IOException
-
writeObject
public static void writeObject(DataOutput out, Object obj) throws IOException
- Throws:
IOException
-
readObject
public static Object readObject(DataInput in) throws IOException
- Throws:
IOException
-
newObjectInputStream
public static ObjectInputStream newObjectInputStream(InputStream in) throws IOException
- Throws:
IOException
-
loadClass
public static Class<?> loadClass(String className) throws ClassNotFoundException
- Throws:
ClassNotFoundException
-
loadClass
public static Class<?> loadClass(ClassLoader classLoader, String className) throws ClassNotFoundException
- Throws:
ClassNotFoundException
-
-