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

Added new util methods.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@8173 b35dd754-fafc-0310-a699-88a17e54d16e
parent fa4db90b
......@@ -14,10 +14,7 @@ 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;
import java.util.*;
/**
* Dummy implementation that does nothing. The open source version of the server uses this
......@@ -163,4 +160,41 @@ public class DummyExternalizableUtil implements ExternalizableUtilStrategy {
// Do nothing
return 0;
}
public void writeExternalizableMap(DataOutput out, Map<String, ? extends Externalizable> map) throws IOException {
// Do nothing
}
public int readExternalizableMap(DataInput in, Map<String, ? extends Externalizable> map, ClassLoader loader)
throws IOException {
// Do nothing
return 0;
}
public void writeStringsMap(DataOutput out, Map<String, Set<String>> map) throws IOException {
// Do nothing
}
public int readStringsMap(DataInput in, Map<String, Set<String>> map) throws IOException {
// Do nothing
return 0;
}
public void writeStrings(DataOutput out, Collection<String> collection) throws IOException {
// Do nothing
}
public int readStrings(DataInput in, Collection<String> collection) throws IOException {
// Do nothing
return 0;
}
public void writeInt(DataOutput out, int value) {
// Do nothing
}
public int readInt(DataInput in) {
// Do nothing
return 0;
}
}
......@@ -18,6 +18,7 @@ import java.io.IOException;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* Utility methods to assist in working with the Externalizable interfaces. This class
......@@ -177,6 +178,14 @@ public class ExternalizableUtil {
return strategy.readLong(in);
}
public void writeInt(DataOutput out, int value) throws IOException {
strategy.writeInt(out, value);
}
public int readInt(DataInput in) throws IOException {
return strategy.readInt(in);
}
public void writeBoolean(DataOutput out, boolean value) throws IOException {
strategy.writeBoolean(out, value);
}
......@@ -219,4 +228,77 @@ public class ExternalizableUtil {
throws IOException {
return strategy.readExternalizableCollection(in, value, loader);
}
/**
* Writes a Map of String key and value pairs. This method handles the
* case when the Map is <tt>null</tt>.
*
* @param out the output stream.
* @param map the Map of String key and Externalizable value pairs.
* @throws java.io.IOException if an error occurs.
*/
public void writeExternalizableMap(DataOutput out, Map<String, ? extends Externalizable> map) throws IOException {
strategy.writeExternalizableMap(out, map);
}
/**
* Reads a Map of String key and value pairs. This method will return
* <tt>null</tt> if the Map written to the stream was <tt>null</tt>.
*
* @param in the input stream.
* @param map a Map of String key and Externalizable value pairs.
* @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 readExternalizableMap(DataInput in, Map<String, ? extends Externalizable> map, ClassLoader loader) throws IOException {
return strategy.readExternalizableMap(in, map, loader);
}
/**
* Writes a Map of String key and Set of Strings value pairs. This method DOES NOT handle the
* case when the Map is <tt>null</tt>.
*
* @param out the output stream.
* @param map the Map of String key and Set of Strings value pairs.
* @throws java.io.IOException if an error occurs.
*/
public void writeStringsMap(DataOutput out, Map<String, Set<String>> map) throws IOException {
strategy.writeStringsMap(out, map);
}
/**
* Reads a Map of String key and Set of Strings value pairs.
*
* @param in the input stream.
* @param map a Map of String key and Set of Strings value pairs.
* @return number of elements added to the collection.
* @throws IOException if an error occurs.
*/
public int readStringsMap(DataInput in, Map<String, Set<String>> map) throws IOException {
return strategy.readStringsMap(in, map);
}
/**
* Writes content of collection of strings to the output stream.
*
* @param out the output stream.
* @param collection the Collection of Strings.
* @throws IOException if an error occurs.
*/
public void writeStrings(DataOutput out, Collection<String> collection) throws IOException {
strategy.writeStrings(out, collection);
}
/**
* Reads the string array from the input stream and adds them to the specified collection.
*
* @param in the input stream.
* @param collection the collection to add the read strings from the input stream.
* @return number of elements added to the collection.
* @throws IOException if an error occurs.
*/
public int readStrings(DataInput in, Collection<String> collection) throws IOException {
return strategy.readStrings(in, collection);
}
}
......@@ -17,6 +17,7 @@ import java.io.IOException;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* Interface that allows to provide different ways for implementing serialization of objects.
......@@ -123,4 +124,20 @@ public interface ExternalizableUtilStrategy {
int readExternalizableCollection(DataInput in, Collection<? extends Externalizable> value, ClassLoader loader)
throws IOException;
void writeExternalizableMap(DataOutput out, Map<String, ? extends Externalizable> map) throws IOException;
int readExternalizableMap(DataInput in, Map<String, ? extends Externalizable> map, ClassLoader loader) throws IOException;
void writeStringsMap(DataOutput out, Map<String, Set<String>> map) throws IOException;
int readStringsMap(DataInput in, Map<String, Set<String>> map) throws IOException;
void writeStrings(DataOutput out, Collection<String> collection) throws IOException;
int readStrings(DataInput in, Collection<String> collection) throws IOException;
void writeInt(DataOutput out, int value) throws IOException;
int readInt(DataInput in) 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