Commit c621a512 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Added support for serializing collections of Externalizable objects.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@8148 b35dd754-fafc-0310-a699-88a17e54d16e
parent 4d814ba2
......@@ -12,7 +12,9 @@ package org.jivesoftware.util.cache;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.Externalizable;
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
......@@ -150,4 +152,15 @@ public class DummyExternalizableUtil implements ExternalizableUtilStrategy {
// Do nothing
return "";
}
public void writeExternalizableCollection(DataOutput out, Collection<? extends Externalizable> value)
throws IOException {
// Do nothing
}
public int readExternalizableCollection(DataInput in, Collection<? extends Externalizable> value,
ClassLoader loader) throws IOException {
// Do nothing
return 0;
}
}
......@@ -13,7 +13,9 @@ package org.jivesoftware.util.cache;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.Externalizable;
import java.io.IOException;
import java.util.Collection;
import java.util.List;
import java.util.Map;
......@@ -190,4 +192,31 @@ public class ExternalizableUtil {
public String readSafeUTF(DataInput in) throws IOException {
return strategy.readSafeUTF(in);
}
/**
* Writes a collection of Externalizable objects. The collection passed as a parameter
* must be a collection and not a <tt>null</null> value.
*
* @param out the output stream.
* @param value the collection of Externalizable objects. This value must not be null.
* @throws IOException if an error occurs.
*/
public void writeExternalizableCollection(DataOutput out, Collection<? extends Externalizable> value) throws IOException {
strategy.writeExternalizableCollection(out, value);
}
/**
* 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 <tt>null</null> value.
*
* @param in the input stream.
* @param value the collection of Externalizable objects. This value must not be null.
* @param loader class loader to use to build elements inside of the serialized collection.
* @throws IOException if an error occurs.
* @return the number of elements added to the collection.
*/
public int readExternalizableCollection(DataInput in, Collection<? extends Externalizable> value, ClassLoader loader)
throws IOException {
return strategy.readExternalizableCollection(in, value, loader);
}
}
......@@ -12,7 +12,9 @@ package org.jivesoftware.util.cache;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.Externalizable;
import java.io.IOException;
import java.util.Collection;
import java.util.List;
import java.util.Map;
......@@ -24,7 +26,7 @@ import java.util.Map;
* @author Gaston Dombiak
*/
public interface ExternalizableUtilStrategy {
/**
* Writes a Map of String key and value pairs. This method handles the
* case when the Map is <tt>null</tt>.
......@@ -33,7 +35,7 @@ public interface ExternalizableUtilStrategy {
* @param stringMap the Map of String key/value pairs.
* @throws java.io.IOException if an error occurs.
*/
public void writeStringMap(DataOutput out, Map<String, String> stringMap) throws IOException;
void writeStringMap(DataOutput out, Map<String, String> stringMap) throws IOException;
/**
* Reads a Map of String key and value pairs. This method will return
......@@ -43,7 +45,7 @@ public interface ExternalizableUtilStrategy {
* @return a Map of String key/value pairs.
* @throws IOException if an error occurs.
*/
public Map<String, String> readStringMap(DataInput in) throws IOException;
Map<String, String> readStringMap(DataInput in) throws IOException;
/**
* Writes a Map of Long key and Integer value pairs. This method handles
......@@ -53,7 +55,7 @@ public interface ExternalizableUtilStrategy {
* @param map the Map of Long key/Integer value pairs.
* @throws IOException if an error occurs.
*/
public void writeLongIntMap(DataOutput out, Map<Long, Integer> map) throws IOException;
void writeLongIntMap(DataOutput out, Map<Long, Integer> map) throws IOException;
/**
* Reads a Map of Long key and Integer value pairs. This method will return
......@@ -63,7 +65,7 @@ public interface ExternalizableUtilStrategy {
* @return a Map of Long key/Integer value pairs.
* @throws IOException if an error occurs.
*/
public Map readLongIntMap(DataInput in) throws IOException;
Map readLongIntMap(DataInput in) throws IOException;
/**
* Writes a List of Strings. This method handles the case when the List is
......@@ -73,7 +75,7 @@ public interface ExternalizableUtilStrategy {
* @param stringList the List of Strings.
* @throws IOException if an error occurs.
*/
public void writeStringList(DataOutput out, List stringList) throws IOException;
void writeStringList(DataOutput out, List stringList) throws IOException;
/**
* Reads a List of Strings. This method will return <tt>null</tt> if the List
......@@ -83,7 +85,7 @@ public interface ExternalizableUtilStrategy {
* @return a List of Strings.
* @throws IOException if an error occurs.
*/
public List<String> readStringList(DataInput in) throws IOException;
List<String> readStringList(DataInput in) throws IOException;
/**
* Writes an array of long values. This method handles the case when the
......@@ -93,7 +95,7 @@ public interface ExternalizableUtilStrategy {
* @param array the array of long values.
* @throws IOException if an error occurs.
*/
public void writeLongArray(DataOutput out, long [] array) throws IOException;
void writeLongArray(DataOutput out, long[] array) throws IOException;
/**
* Reads an array of long values. This method will return <tt>null</tt> if
......@@ -103,17 +105,22 @@ public interface ExternalizableUtilStrategy {
* @return an array of long values.
* @throws IOException if an error occurs.
*/
public long [] readLongArray(DataInput in) throws IOException;
long[] readLongArray(DataInput in) throws IOException;
void writeLong(DataOutput out, long value) throws IOException;
long readLong(DataInput in) throws IOException;
public void writeLong(DataOutput out, long value) throws IOException;
void writeBoolean(DataOutput out, boolean value) throws IOException;
public long readLong(DataInput in) throws IOException;
boolean readBoolean(DataInput in) throws IOException;
public void writeBoolean(DataOutput out, boolean value) throws IOException;
void writeSafeUTF(DataOutput out, String value) throws IOException;
public boolean readBoolean(DataInput in) throws IOException;
String readSafeUTF(DataInput in) throws IOException;
public void writeSafeUTF(DataOutput out, String value) throws IOException;
void writeExternalizableCollection(DataOutput out, Collection<? extends Externalizable> value) throws IOException;
public String readSafeUTF(DataInput in) throws IOException;
int readExternalizableCollection(DataInput in, Collection<? extends Externalizable> value, ClassLoader loader)
throws IOException;
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment