@Immutable
public class MarshallUtil
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static interface |
MarshallUtil.ArrayBuilder<E> |
static interface |
MarshallUtil.CollectionBuilder<E,T extends java.util.Collection<E>> |
static interface |
MarshallUtil.ElementReader<E> |
static interface |
MarshallUtil.ElementWriter<E> |
static interface |
MarshallUtil.EnumBuilder<E extends java.lang.Enum<E>> |
static interface |
MarshallUtil.MapBuilder<K,V,T extends java.util.Map<K,V>> |
static interface |
MarshallUtil.UnboundedCollectionBuilder<E,T extends java.util.Collection<E>> |
| Constructor and Description |
|---|
MarshallUtil() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
isSafeClass(java.lang.String className,
java.util.List<java.lang.String> whitelist)
Checks whether class name is matched by the class name white list regular expressions provided.
|
static <E> void |
marshallArray(E[] array,
java.io.ObjectOutput out)
Marshall arrays.
|
static void |
marshallByteArray(byte[] array,
java.io.ObjectOutput out)
Same as
marshallArray(Object[], ObjectOutput) but specialized for byte arrays. |
static <E> void |
marshallCollection(java.util.Collection<E> collection,
java.io.ObjectOutput out)
Marshall a
Collection. |
static <E> void |
marshallCollection(java.util.Collection<E> collection,
java.io.ObjectOutput out,
MarshallUtil.ElementWriter<E> writer)
Marshall a
Collection. |
static <E extends java.lang.Enum<E>> |
marshallEnum(E e,
java.io.ObjectOutput output) |
static void |
marshallIntCollection(java.util.Collection<java.lang.Integer> collection,
java.io.ObjectOutput out)
Marshalls a collection of integers.
|
static <K,V,T extends java.util.Map<K,V>> |
marshallMap(T map,
MarshallUtil.ElementWriter<K> keyWriter,
MarshallUtil.ElementWriter<V> valueWrite,
java.io.ObjectOutput out)
Marshall the
map to the ObjectOutput. |
static <K,V,T extends java.util.Map<K,V>> |
marshallMap(T map,
java.io.ObjectOutput out)
Marshall the
map to the ObjectOutput. |
static void |
marshallSize(java.io.ObjectOutput out,
int value)
A special marshall implementation for integer.
|
static void |
marshallString(java.lang.String string,
java.io.ObjectOutput out)
Marshall the
String. |
static void |
marshallUUID(java.util.UUID uuid,
java.io.ObjectOutput out,
boolean checkNull)
Marshall the
UUID by sending the most and lest significant bits. |
static <E> E[] |
unmarshallArray(java.io.ObjectInput in,
MarshallUtil.ArrayBuilder<E> builder)
Unmarshall arrays.
|
static byte[] |
unmarshallByteArray(java.io.ObjectInput in)
Same as
unmarshallArray(ObjectInput, ArrayBuilder) but specialized for byte array. |
static <E,T extends java.util.Collection<E>> |
unmarshallCollection(java.io.ObjectInput in,
MarshallUtil.CollectionBuilder<E,T> builder)
Unmarshal a
Collection. |
static <E,T extends java.util.Collection<E>> |
unmarshallCollection(java.io.ObjectInput in,
MarshallUtil.CollectionBuilder<E,T> builder,
MarshallUtil.ElementReader<E> reader)
Unmarshal a
Collection. |
static <E,T extends java.util.Collection<E>> |
unmarshallCollectionUnbounded(java.io.ObjectInput in,
MarshallUtil.UnboundedCollectionBuilder<E,T> builder)
|
static <E extends java.lang.Enum<E>> |
unmarshallEnum(java.io.ObjectInput input,
MarshallUtil.EnumBuilder<E> builder) |
static <T extends java.util.Collection<java.lang.Integer>> |
unmarshallIntCollection(java.io.ObjectInput in,
MarshallUtil.CollectionBuilder<java.lang.Integer,T> builder)
Unmarshalls a collection of integers.
|
static <K,V,T extends java.util.Map<K,V>> |
unmarshallMap(java.io.ObjectInput in,
MarshallUtil.ElementReader<K> keyReader,
MarshallUtil.ElementReader<V> valueReader,
MarshallUtil.MapBuilder<K,V,T> builder)
Unmarshall the
Map. |
static <K,V,T extends java.util.Map<K,V>> |
unmarshallMap(java.io.ObjectInput in,
MarshallUtil.MapBuilder<K,V,T> builder)
Unmarshall the
Map. |
static int |
unmarshallSize(java.io.ObjectInput in)
Unmarshall an integer.
|
static java.lang.String |
unmarshallString(java.io.ObjectInput in)
Unmarshall a
String. |
static java.util.UUID |
unmarshallUUID(java.io.ObjectInput in,
boolean checkNull)
Unmarshall
UUID. |
public static <K,V,T extends java.util.Map<K,V>> void marshallMap(T map,
java.io.ObjectOutput out)
throws java.io.IOException
map to the ObjectOutput.
null maps are supported.
K - Key type of the map.V - Value type of the map.T - Type of the Map.map - Map to marshall.out - ObjectOutput to write. It must be non-null.java.io.IOException - If any of the usual Input/Output related exceptions occur.public static <K,V,T extends java.util.Map<K,V>> T unmarshallMap(java.io.ObjectInput in,
MarshallUtil.MapBuilder<K,V,T> builder)
throws java.io.IOException,
java.lang.ClassNotFoundException
Map.
If the marshalled map is null, then the MarshallUtil.MapBuilder is not invoked.
in - ObjectInput to read.builder - MarshallUtil.MapBuilder to create the concrete Map implementation.Map created by the MarshallUtil.MapBuilder or null.java.io.IOException - If any of the usual Input/Output related exceptions occur.java.lang.ClassNotFoundException - If the class of a serialized object cannot be found.marshallMap(Map, ObjectOutput)public static <K,V,T extends java.util.Map<K,V>> void marshallMap(T map,
MarshallUtil.ElementWriter<K> keyWriter,
MarshallUtil.ElementWriter<V> valueWrite,
java.io.ObjectOutput out)
throws java.io.IOException
map to the ObjectOutput.
null maps are supported.
K - Key type of the map.V - Value type of the map.T - Type of the Map.map - Map to marshall.out - ObjectOutput to write. It must be non-null.java.io.IOException - If any of the usual Input/Output related exceptions occur.public static <K,V,T extends java.util.Map<K,V>> T unmarshallMap(java.io.ObjectInput in,
MarshallUtil.ElementReader<K> keyReader,
MarshallUtil.ElementReader<V> valueReader,
MarshallUtil.MapBuilder<K,V,T> builder)
throws java.io.IOException,
java.lang.ClassNotFoundException
Map.
If the marshalled map is null, then the MarshallUtil.MapBuilder is not invoked.
in - ObjectInput to read.builder - MarshallUtil.MapBuilder to create the concrete Map implementation.Map created by the MarshallUtil.MapBuilder or null.java.io.IOException - If any of the usual Input/Output related exceptions occur.java.lang.ClassNotFoundException - If the class of a serialized object cannot be found.marshallMap(Map, ElementWriter, ElementWriter, ObjectOutput)public static void marshallUUID(java.util.UUID uuid,
java.io.ObjectOutput out,
boolean checkNull)
throws java.io.IOException
UUID by sending the most and lest significant bits.
This method supports null if checkNull is set to true.
uuid - UUID to marshall.out - ObjectOutput to write.checkNull - If true, it checks if uuid is null.java.io.IOException - If any of the usual Input/Output related exceptions occur.public static java.util.UUID unmarshallUUID(java.io.ObjectInput in,
boolean checkNull)
throws java.io.IOException
UUID.in - ObjectInput to read.checkNull - If true, it checks if the UUID marshalled was null.UUID marshalled.java.io.IOException - If any of the usual Input/Output related exceptions occur.marshallUUID(UUID, ObjectOutput, boolean).public static <E> void marshallArray(E[] array,
java.io.ObjectOutput out)
throws java.io.IOException
This method supports null array.
E - Array type.array - Array to marshall.out - ObjectOutput to write.java.io.IOException - If any of the usual Input/Output related exceptions occur.public static <E> E[] unmarshallArray(java.io.ObjectInput in,
MarshallUtil.ArrayBuilder<E> builder)
throws java.io.IOException,
java.lang.ClassNotFoundException
E - Array type.in - ObjectInput to read.builder - MarshallUtil.ArrayBuilder to build the array.java.io.IOException - If any of the usual Input/Output related exceptions occur.java.lang.ClassNotFoundException - If the class of a serialized object cannot be found.marshallArray(Object[], ObjectOutput).public static <E> void marshallCollection(java.util.Collection<E> collection,
java.io.ObjectOutput out)
throws java.io.IOException
Collection.
This method supports null collection.
E - Collection's element type.collection - Collection to marshal.out - ObjectOutput to write.java.io.IOException - If any of the usual Input/Output related exceptions occur.public static <E> void marshallCollection(java.util.Collection<E> collection,
java.io.ObjectOutput out,
MarshallUtil.ElementWriter<E> writer)
throws java.io.IOException
Collection.
This method supports null collection.
E - Collection's element type.collection - Collection to marshal.out - ObjectOutput to write.writer - MarshallUtil.ElementWriter that writes single element to the output.java.io.IOException - If any of the usual Input/Output related exceptions occur.public static <E,T extends java.util.Collection<E>> T unmarshallCollection(java.io.ObjectInput in,
MarshallUtil.CollectionBuilder<E,T> builder,
MarshallUtil.ElementReader<E> reader)
throws java.io.IOException,
java.lang.ClassNotFoundException
Collection.E - Collection's element type.T - Collection implementation.in - ObjectInput to read.builder - MarshallUtil.CollectionBuilder builds the concrete Collection based on size.reader - MarshallUtil.ElementReader reads one element from the input.Collection implementation.java.io.IOException - If any of the usual Input/Output related exceptions occur.java.lang.ClassNotFoundException - If the class of a serialized object cannot be found.public static <E,T extends java.util.Collection<E>> T unmarshallCollection(java.io.ObjectInput in,
MarshallUtil.CollectionBuilder<E,T> builder)
throws java.io.IOException,
java.lang.ClassNotFoundException
Collection.E - Collection's element type.T - Collection implementation.in - ObjectInput to read.builder - MarshallUtil.CollectionBuilder builds the concrete Collection based on size.Collection implementation.java.io.IOException - If any of the usual Input/Output related exceptions occur.java.lang.ClassNotFoundException - If the class of a serialized object cannot be found.public static <E,T extends java.util.Collection<E>> T unmarshallCollectionUnbounded(java.io.ObjectInput in,
MarshallUtil.UnboundedCollectionBuilder<E,T> builder)
throws java.io.IOException,
java.lang.ClassNotFoundException
unmarshallCollection(ObjectInput, CollectionBuilder).
Used when the size of the Collection is not needed for it construction.
java.io.IOExceptionjava.lang.ClassNotFoundExceptionunmarshallCollection(ObjectInput, CollectionBuilder).public static void marshallString(java.lang.String string,
java.io.ObjectOutput out)
throws java.io.IOException
String.
Same behavior as DataOutput.writeUTF(String) but it checks for null. If the string is
never null, it is better to use DataOutput.writeUTF(String).
string - String to marshall.out - ObjectOutput to write.java.io.IOException - If any of the usual Input/Output related exceptions occur.public static java.lang.String unmarshallString(java.io.ObjectInput in)
throws java.io.IOException
String.in - ObjectInput to read.String or null.java.io.IOException - If any of the usual Input/Output related exceptions occur.marshallString(String, ObjectOutput).public static void marshallByteArray(byte[] array,
java.io.ObjectOutput out)
throws java.io.IOException
marshallArray(Object[], ObjectOutput) but specialized for byte arrays.java.io.IOExceptionmarshallArray(Object[], ObjectOutput).public static byte[] unmarshallByteArray(java.io.ObjectInput in)
throws java.io.IOException
unmarshallArray(ObjectInput, ArrayBuilder) but specialized for byte array.
No MarshallUtil.ArrayBuilder is necessary.
java.io.IOExceptionunmarshallArray(ObjectInput, ArrayBuilder).public static void marshallSize(java.io.ObjectOutput out,
int value)
throws java.io.IOException
This method supports negative values but they are handles as NULL_VALUE. It means that the real value is
lost and NULL_VALUE is returned by unmarshallSize(ObjectInput).
The integer is marshalled in a variable length from 1 to 5 bytes. Negatives values are always marshalled in 1 byte.
out - ObjectOutput to write.value - Integer value to marshall.java.io.IOException - If any of the usual Input/Output related exceptions occur.public static int unmarshallSize(java.io.ObjectInput in)
throws java.io.IOException
in - ObjectInput to read.NULL_VALUE if the original value was negative.java.io.IOException - If any of the usual Input/Output related exceptions occur.marshallSize(ObjectOutput, int).public static <E extends java.lang.Enum<E>> void marshallEnum(E e,
java.io.ObjectOutput output)
throws java.io.IOException
java.io.IOExceptionpublic static <E extends java.lang.Enum<E>> E unmarshallEnum(java.io.ObjectInput input,
MarshallUtil.EnumBuilder<E> builder)
throws java.io.IOException
java.io.IOExceptionpublic static void marshallIntCollection(java.util.Collection<java.lang.Integer> collection,
java.io.ObjectOutput out)
throws java.io.IOException
collection - the collection to marshall.out - the ObjectOutput to write to.java.io.IOException - if an error occurs.public static <T extends java.util.Collection<java.lang.Integer>> T unmarshallIntCollection(java.io.ObjectInput in,
MarshallUtil.CollectionBuilder<java.lang.Integer,T> builder)
throws java.io.IOException
T - the concrete type of the collection.in - the ObjectInput to read from.builder - the MarshallUtil.CollectionBuilder to build the collection of integer.java.io.IOException - if an error occurs.public static boolean isSafeClass(java.lang.String className,
java.util.List<java.lang.String> whitelist)
className - class to verifywhitelist - list of regular expressions to match class name against