@Immutable public class MarshallUtil extends Object
| Modifier and Type | Class and Description |
|---|---|
static interface |
MarshallUtil.ArrayBuilder<E> |
static interface |
MarshallUtil.CollectionBuilder<E,T extends Collection<E>> |
static interface |
MarshallUtil.ElementReader<E> |
static interface |
MarshallUtil.ElementWriter<E> |
static interface |
MarshallUtil.EnumBuilder<E extends Enum<E>> |
static interface |
MarshallUtil.MapBuilder<K,V,T extends Map<K,V>> |
static interface |
MarshallUtil.UnboundedCollectionBuilder<E,T extends Collection<E>> |
| Constructor and Description |
|---|
MarshallUtil() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
isSafeClass(String className,
List<String> whitelist)
Checks whether class name is matched by the class name white list regular expressions provided.
|
static <E> void |
marshallArray(E[] array,
ObjectOutput out)
Marshall arrays.
|
static void |
marshallByteArray(byte[] array,
ObjectOutput out)
Same as
marshallArray(Object[], ObjectOutput) but specialized for byte arrays. |
static <E> void |
marshallCollection(Collection<E> collection,
ObjectOutput out)
Marshall a
Collection. |
static <E> void |
marshallCollection(Collection<E> collection,
ObjectOutput out,
MarshallUtil.ElementWriter<E> writer)
Marshall a
Collection. |
static <E extends Enum<E>> |
marshallEnum(E e,
ObjectOutput output) |
static void |
marshallIntCollection(Collection<Integer> collection,
ObjectOutput out)
Marshalls a collection of integers.
|
static <K,V,T extends Map<K,V>> |
marshallMap(T map,
MarshallUtil.ElementWriter<K> keyWriter,
MarshallUtil.ElementWriter<V> valueWrite,
ObjectOutput out)
Marshall the
map to the ObjectOutput. |
static <K,V,T extends Map<K,V>> |
marshallMap(T map,
ObjectOutput out)
Marshall the
map to the ObjectOutput. |
static void |
marshallSize(ObjectOutput out,
int value)
A special marshall implementation for integer.
|
static void |
marshallString(String string,
ObjectOutput out)
Marshall the
String. |
static void |
marshallUUID(UUID uuid,
ObjectOutput out,
boolean checkNull)
Marshall the
UUID by sending the most and lest significant bits. |
static <E> E[] |
unmarshallArray(ObjectInput in,
MarshallUtil.ArrayBuilder<E> builder)
Unmarshall arrays.
|
static byte[] |
unmarshallByteArray(ObjectInput in)
Same as
unmarshallArray(ObjectInput, ArrayBuilder) but specialized for byte array. |
static <E,T extends Collection<E>> |
unmarshallCollection(ObjectInput in,
MarshallUtil.CollectionBuilder<E,T> builder)
Unmarshal a
Collection. |
static <E,T extends Collection<E>> |
unmarshallCollection(ObjectInput in,
MarshallUtil.CollectionBuilder<E,T> builder,
MarshallUtil.ElementReader<E> reader)
Unmarshal a
Collection. |
static <E,T extends Collection<E>> |
unmarshallCollectionUnbounded(ObjectInput in,
MarshallUtil.UnboundedCollectionBuilder<E,T> builder)
|
static <E extends Enum<E>> |
unmarshallEnum(ObjectInput input,
MarshallUtil.EnumBuilder<E> builder) |
static <T extends Collection<Integer>> |
unmarshallIntCollection(ObjectInput in,
MarshallUtil.CollectionBuilder<Integer,T> builder)
Unmarshalls a collection of integers.
|
static <K,V,T extends Map<K,V>> |
unmarshallMap(ObjectInput in,
MarshallUtil.ElementReader<K> keyReader,
MarshallUtil.ElementReader<V> valueReader,
MarshallUtil.MapBuilder<K,V,T> builder)
Unmarshall the
Map. |
static <K,V,T extends Map<K,V>> |
unmarshallMap(ObjectInput in,
MarshallUtil.MapBuilder<K,V,T> builder)
Unmarshall the
Map. |
static int |
unmarshallSize(ObjectInput in)
Unmarshall an integer.
|
static String |
unmarshallString(ObjectInput in)
Unmarshall a
String. |
static UUID |
unmarshallUUID(ObjectInput in,
boolean checkNull)
Unmarshall
UUID. |
public static <K,V,T extends Map<K,V>> void marshallMap(T map, ObjectOutput out) throws 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.IOException - If any of the usual Input/Output related exceptions occur.public static <K,V,T extends Map<K,V>> T unmarshallMap(ObjectInput in, MarshallUtil.MapBuilder<K,V,T> builder) throws IOException, 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.IOException - If any of the usual Input/Output related exceptions occur.ClassNotFoundException - If the class of a serialized object cannot be found.marshallMap(Map, ObjectOutput)public static <K,V,T extends Map<K,V>> void marshallMap(T map, MarshallUtil.ElementWriter<K> keyWriter, MarshallUtil.ElementWriter<V> valueWrite, ObjectOutput out) throws 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.IOException - If any of the usual Input/Output related exceptions occur.public static <K,V,T extends Map<K,V>> T unmarshallMap(ObjectInput in, MarshallUtil.ElementReader<K> keyReader, MarshallUtil.ElementReader<V> valueReader, MarshallUtil.MapBuilder<K,V,T> builder) throws IOException, 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.IOException - If any of the usual Input/Output related exceptions occur.ClassNotFoundException - If the class of a serialized object cannot be found.marshallMap(Map, ElementWriter, ElementWriter, ObjectOutput)public static void marshallUUID(UUID uuid, ObjectOutput out, boolean checkNull) throws 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.IOException - If any of the usual Input/Output related exceptions occur.public static UUID unmarshallUUID(ObjectInput in, boolean checkNull) throws IOException
UUID.in - ObjectInput to read.checkNull - If true, it checks if the UUID marshalled was null.UUID marshalled.IOException - If any of the usual Input/Output related exceptions occur.marshallUUID(UUID, ObjectOutput, boolean).public static <E> void marshallArray(E[] array,
ObjectOutput out)
throws IOException
This method supports null array.
E - Array type.array - Array to marshall.out - ObjectOutput to write.IOException - If any of the usual Input/Output related exceptions occur.public static <E> E[] unmarshallArray(ObjectInput in, MarshallUtil.ArrayBuilder<E> builder) throws IOException, ClassNotFoundException
E - Array type.in - ObjectInput to read.builder - MarshallUtil.ArrayBuilder to build the array.IOException - If any of the usual Input/Output related exceptions occur.ClassNotFoundException - If the class of a serialized object cannot be found.marshallArray(Object[], ObjectOutput).public static <E> void marshallCollection(Collection<E> collection, ObjectOutput out) throws IOException
Collection.
This method supports null collection.
E - Collection's element type.collection - Collection to marshal.out - ObjectOutput to write.IOException - If any of the usual Input/Output related exceptions occur.public static <E> void marshallCollection(Collection<E> collection, ObjectOutput out, MarshallUtil.ElementWriter<E> writer) throws 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.IOException - If any of the usual Input/Output related exceptions occur.public static <E,T extends Collection<E>> T unmarshallCollection(ObjectInput in, MarshallUtil.CollectionBuilder<E,T> builder, MarshallUtil.ElementReader<E> reader) throws IOException, 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.IOException - If any of the usual Input/Output related exceptions occur.ClassNotFoundException - If the class of a serialized object cannot be found.public static <E,T extends Collection<E>> T unmarshallCollection(ObjectInput in, MarshallUtil.CollectionBuilder<E,T> builder) throws IOException, 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.IOException - If any of the usual Input/Output related exceptions occur.ClassNotFoundException - If the class of a serialized object cannot be found.public static <E,T extends Collection<E>> T unmarshallCollectionUnbounded(ObjectInput in, MarshallUtil.UnboundedCollectionBuilder<E,T> builder) throws IOException, ClassNotFoundException
unmarshallCollection(ObjectInput, CollectionBuilder).
Used when the size of the Collection is not needed for it construction.
public static void marshallString(String string, ObjectOutput out) throws 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.IOException - If any of the usual Input/Output related exceptions occur.public static String unmarshallString(ObjectInput in) throws IOException
String.in - ObjectInput to read.String or null.IOException - If any of the usual Input/Output related exceptions occur.marshallString(String, ObjectOutput).public static void marshallByteArray(byte[] array,
ObjectOutput out)
throws IOException
marshallArray(Object[], ObjectOutput) but specialized for byte arrays.IOExceptionmarshallArray(Object[], ObjectOutput).public static byte[] unmarshallByteArray(ObjectInput in) throws IOException
unmarshallArray(ObjectInput, ArrayBuilder) but specialized for byte array.
No MarshallUtil.ArrayBuilder is necessary.
IOExceptionunmarshallArray(ObjectInput, ArrayBuilder).public static void marshallSize(ObjectOutput out, int value) throws 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.IOException - If any of the usual Input/Output related exceptions occur.public static int unmarshallSize(ObjectInput in) throws IOException
in - ObjectInput to read.NULL_VALUE if the original value was negative.IOException - If any of the usual Input/Output related exceptions occur.marshallSize(ObjectOutput, int).public static <E extends Enum<E>> void marshallEnum(E e, ObjectOutput output) throws IOException
IOExceptionpublic static <E extends Enum<E>> E unmarshallEnum(ObjectInput input, MarshallUtil.EnumBuilder<E> builder) throws IOException
IOExceptionpublic static void marshallIntCollection(Collection<Integer> collection, ObjectOutput out) throws IOException
collection - the collection to marshall.out - the ObjectOutput to write to.IOException - if an error occurs.public static <T extends Collection<Integer>> T unmarshallIntCollection(ObjectInput in, MarshallUtil.CollectionBuilder<Integer,T> builder) throws IOException
T - the concrete type of the collection.in - the ObjectInput to read from.builder - the MarshallUtil.CollectionBuilder to build the collection of integer.IOException - if an error occurs.public static boolean isSafeClass(String className, List<String> whitelist)
className - class to verifywhitelist - list of regular expressions to match class name againstCopyright © 2018 JBoss, a division of Red Hat. All rights reserved.