Class MarshallUtil
- java.lang.Object
-
- org.infinispan.commons.marshall.MarshallUtil
-
@Immutable public class MarshallUtil extends java.lang.ObjectMarshallUtil.- Since:
- 4.0
- Author:
- Galder ZamarreƱo
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceMarshallUtil.ArrayBuilder<E>static interfaceMarshallUtil.CollectionBuilder<E,T extends java.util.Collection<E>>static interfaceMarshallUtil.ElementReader<E>static interfaceMarshallUtil.ElementWriter<E>static interfaceMarshallUtil.EnumBuilder<E extends java.lang.Enum<E>>static interfaceMarshallUtil.MapBuilder<K,V,T extends java.util.Map<K,V>>static interfaceMarshallUtil.UnboundedCollectionBuilder<E,T extends java.util.Collection<E>>
-
Constructor Summary
Constructors Constructor Description MarshallUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanisSafeClass(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> voidmarshallArray(E[] array, java.io.ObjectOutput out)Marshall arrays.static voidmarshallByteArray(byte[] array, java.io.ObjectOutput out)Same asmarshallArray(Object[], ObjectOutput)but specialized for byte arrays.static <E> voidmarshallCollection(java.util.Collection<E> collection, java.io.ObjectOutput out)Marshall aCollection.static <E> voidmarshallCollection(java.util.Collection<E> collection, java.io.ObjectOutput out, MarshallUtil.ElementWriter<E> writer)Marshall aCollection.static <E extends java.lang.Enum<E>>
voidmarshallEnum(E e, java.io.ObjectOutput output)static voidmarshallIntCollection(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>>
voidmarshallMap(T map, java.io.ObjectOutput out)Marshall themapto theObjectOutput.static <K,V,T extends java.util.Map<K,V>>
voidmarshallMap(T map, MarshallUtil.ElementWriter<K> keyWriter, MarshallUtil.ElementWriter<V> valueWrite, java.io.ObjectOutput out)Marshall themapto theObjectOutput.static voidmarshallSize(java.io.ObjectOutput out, int value)A special marshall implementation for integer.static voidmarshallString(java.lang.String string, java.io.ObjectOutput out)Marshall theString.static voidmarshallUUID(java.util.UUID uuid, java.io.ObjectOutput out, boolean checkNull)Marshall theUUIDby sending the most and lest significant bits.static byte[]toByteArray(ByteBuffer buf)static <E> E[]unmarshallArray(java.io.ObjectInput in, MarshallUtil.ArrayBuilder<E> builder)Unmarshall arrays.static byte[]unmarshallByteArray(java.io.ObjectInput in)Same asunmarshallArray(ObjectInput, ArrayBuilder)but specialized for byte array.static <E,T extends java.util.Collection<E>>
TunmarshallCollection(java.io.ObjectInput in, MarshallUtil.CollectionBuilder<E,T> builder)Unmarshal aCollection.static <E,T extends java.util.Collection<E>>
TunmarshallCollection(java.io.ObjectInput in, MarshallUtil.CollectionBuilder<E,T> builder, MarshallUtil.ElementReader<E> reader)Unmarshal aCollection.static <E,T extends java.util.Collection<E>>
TunmarshallCollectionUnbounded(java.io.ObjectInput in, MarshallUtil.UnboundedCollectionBuilder<E,T> builder)static <E extends java.lang.Enum<E>>
EunmarshallEnum(java.io.ObjectInput input, MarshallUtil.EnumBuilder<E> builder)static <T extends java.util.Collection<java.lang.Integer>>
TunmarshallIntCollection(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>>
TunmarshallMap(java.io.ObjectInput in, MarshallUtil.ElementReader<K> keyReader, MarshallUtil.ElementReader<V> valueReader, MarshallUtil.MapBuilder<K,V,T> builder)Unmarshall theMap.static <K,V,T extends java.util.Map<K,V>>
TunmarshallMap(java.io.ObjectInput in, MarshallUtil.MapBuilder<K,V,T> builder)Unmarshall theMap.static intunmarshallSize(java.io.ObjectInput in)Unmarshall an integer.static java.lang.StringunmarshallString(java.io.ObjectInput in)Unmarshall aString.static java.util.UUIDunmarshallUUID(java.io.ObjectInput in, boolean checkNull)UnmarshallUUID.
-
-
-
Method Detail
-
toByteArray
public static byte[] toByteArray(ByteBuffer buf)
-
marshallMap
public static <K,V,T extends java.util.Map<K,V>> void marshallMap(T map, java.io.ObjectOutput out) throws java.io.IOExceptionMarshall themapto theObjectOutput.nullmaps are supported.- Type Parameters:
K- Key type of the map.V- Value type of the map.T- Type of theMap.- Parameters:
map-Mapto marshall.out-ObjectOutputto write. It must be non-null.- Throws:
java.io.IOException- If any of the usual Input/Output related exceptions occur.
-
unmarshallMap
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.ClassNotFoundExceptionUnmarshall theMap.If the marshalled map is
null, then theMarshallUtil.MapBuilderis not invoked.- Parameters:
in-ObjectInputto read.builder-MarshallUtil.MapBuilderto create the concreteMapimplementation.- Returns:
- The populated
Mapcreated by theMarshallUtil.MapBuilderornull. - Throws:
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.- See Also:
marshallMap(Map, ObjectOutput)
-
marshallMap
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.IOExceptionMarshall themapto theObjectOutput.nullmaps are supported.- Type Parameters:
K- Key type of the map.V- Value type of the map.T- Type of theMap.- Parameters:
map-Mapto marshall.out-ObjectOutputto write. It must be non-null.- Throws:
java.io.IOException- If any of the usual Input/Output related exceptions occur.
-
unmarshallMap
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.ClassNotFoundExceptionUnmarshall theMap.If the marshalled map is
null, then theMarshallUtil.MapBuilderis not invoked.- Parameters:
in-ObjectInputto read.builder-MarshallUtil.MapBuilderto create the concreteMapimplementation.- Returns:
- The populated
Mapcreated by theMarshallUtil.MapBuilderornull. - Throws:
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.- See Also:
marshallMap(Map, ElementWriter, ElementWriter, ObjectOutput)
-
marshallUUID
public static void marshallUUID(java.util.UUID uuid, java.io.ObjectOutput out, boolean checkNull) throws java.io.IOExceptionMarshall theUUIDby sending the most and lest significant bits.This method supports
nullifcheckNullis set totrue.- Parameters:
uuid-UUIDto marshall.out-ObjectOutputto write.checkNull- Iftrue, it checks ifuuidisnull.- Throws:
java.io.IOException- If any of the usual Input/Output related exceptions occur.
-
unmarshallUUID
public static java.util.UUID unmarshallUUID(java.io.ObjectInput in, boolean checkNull) throws java.io.IOExceptionUnmarshallUUID.- Parameters:
in-ObjectInputto read.checkNull- Iftrue, it checks if theUUIDmarshalled wasnull.- Returns:
UUIDmarshalled.- Throws:
java.io.IOException- If any of the usual Input/Output related exceptions occur.
-
marshallArray
public static <E> void marshallArray(E[] array, java.io.ObjectOutput out) throws java.io.IOExceptionMarshall arrays.This method supports
nullarray.- Type Parameters:
E- Array type.- Parameters:
array- Array to marshall.out-ObjectOutputto write.- Throws:
java.io.IOException- If any of the usual Input/Output related exceptions occur.
-
unmarshallArray
public static <E> E[] unmarshallArray(java.io.ObjectInput in, MarshallUtil.ArrayBuilder<E> builder) throws java.io.IOException, java.lang.ClassNotFoundExceptionUnmarshall arrays.- Type Parameters:
E- Array type.- Parameters:
in-ObjectInputto read.builder-MarshallUtil.ArrayBuilderto build the array.- Returns:
- The populated array.
- Throws:
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.
-
marshallCollection
public static <E> void marshallCollection(java.util.Collection<E> collection, java.io.ObjectOutput out) throws java.io.IOExceptionMarshall aCollection.This method supports
nullcollection.- Type Parameters:
E- Collection's element type.- Parameters:
collection-Collectionto marshal.out-ObjectOutputto write.- Throws:
java.io.IOException- If any of the usual Input/Output related exceptions occur.
-
marshallCollection
public static <E> void marshallCollection(java.util.Collection<E> collection, java.io.ObjectOutput out, MarshallUtil.ElementWriter<E> writer) throws java.io.IOExceptionMarshall aCollection.This method supports
nullcollection.- Type Parameters:
E- Collection's element type.- Parameters:
collection-Collectionto marshal.out-ObjectOutputto write.writer-MarshallUtil.ElementWriterthat writes single element to the output.- Throws:
java.io.IOException- If any of the usual Input/Output related exceptions occur.
-
unmarshallCollection
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.ClassNotFoundExceptionUnmarshal aCollection.- Type Parameters:
E- Collection's element type.T-Collectionimplementation.- Parameters:
in-ObjectInputto read.builder-MarshallUtil.CollectionBuilderbuilds the concreteCollectionbased on size.reader-MarshallUtil.ElementReaderreads one element from the input.- Returns:
- The concrete
Collectionimplementation. - Throws:
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.
-
unmarshallCollection
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.ClassNotFoundExceptionUnmarshal aCollection.- Type Parameters:
E- Collection's element type.T-Collectionimplementation.- Parameters:
in-ObjectInputto read.builder-MarshallUtil.CollectionBuilderbuilds the concreteCollectionbased on size.- Returns:
- The concrete
Collectionimplementation. - Throws:
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.
-
unmarshallCollectionUnbounded
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.ClassNotFoundExceptionSame asunmarshallCollection(ObjectInput, CollectionBuilder).Used when the size of the
Collectionis not needed for it construction.- Throws:
java.io.IOExceptionjava.lang.ClassNotFoundException
-
marshallString
public static void marshallString(java.lang.String string, java.io.ObjectOutput out) throws java.io.IOExceptionMarshall theString.Same behavior as
DataOutput.writeUTF(String)but it checks fornull. If thestringis nevernull, it is better to useDataOutput.writeUTF(String).- Parameters:
string-Stringto marshall.out-ObjectOutputto write.- Throws:
java.io.IOException- If any of the usual Input/Output related exceptions occur.
-
unmarshallString
public static java.lang.String unmarshallString(java.io.ObjectInput in) throws java.io.IOExceptionUnmarshall aString.- Parameters:
in-ObjectInputto read.- Returns:
- The
Stringornull. - Throws:
java.io.IOException- If any of the usual Input/Output related exceptions occur.
-
marshallByteArray
public static void marshallByteArray(byte[] array, java.io.ObjectOutput out) throws java.io.IOExceptionSame asmarshallArray(Object[], ObjectOutput)but specialized for byte arrays.- Throws:
java.io.IOException
-
unmarshallByteArray
public static byte[] unmarshallByteArray(java.io.ObjectInput in) throws java.io.IOExceptionSame asunmarshallArray(ObjectInput, ArrayBuilder)but specialized for byte array.No
MarshallUtil.ArrayBuilderis necessary.- Throws:
java.io.IOException
-
marshallSize
public static void marshallSize(java.io.ObjectOutput out, int value) throws java.io.IOExceptionA special marshall implementation for integer.This method supports negative values but they are handles as
NULL_VALUE. It means that the real value is lost andNULL_VALUEis returned byunmarshallSize(ObjectInput).The integer is marshalled in a variable length from 1 to 5 bytes. Negatives values are always marshalled in 1 byte.
- Parameters:
out-ObjectOutputto write.value- Integer value to marshall.- Throws:
java.io.IOException- If any of the usual Input/Output related exceptions occur.
-
unmarshallSize
public static int unmarshallSize(java.io.ObjectInput in) throws java.io.IOExceptionUnmarshall an integer.- Parameters:
in-ObjectInputto read.- Returns:
- The integer value or
NULL_VALUEif the original value was negative. - Throws:
java.io.IOException- If any of the usual Input/Output related exceptions occur.
-
marshallEnum
public static <E extends java.lang.Enum<E>> void marshallEnum(E e, java.io.ObjectOutput output) throws java.io.IOException- Throws:
java.io.IOException
-
unmarshallEnum
public static <E extends java.lang.Enum<E>> E unmarshallEnum(java.io.ObjectInput input, MarshallUtil.EnumBuilder<E> builder) throws java.io.IOException- Throws:
java.io.IOException
-
marshallIntCollection
public static void marshallIntCollection(java.util.Collection<java.lang.Integer> collection, java.io.ObjectOutput out) throws java.io.IOExceptionMarshalls a collection of integers.- Parameters:
collection- the collection to marshall.out- theObjectOutputto write to.- Throws:
java.io.IOException- if an error occurs.
-
unmarshallIntCollection
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.IOExceptionUnmarshalls a collection of integers.- Type Parameters:
T- the concrete type of the collection.- Parameters:
in- theObjectInputto read from.builder- theMarshallUtil.CollectionBuilderto build the collection of integer.- Returns:
- the collection.
- Throws:
java.io.IOException- if an error occurs.
-
isSafeClass
public 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.- Parameters:
className- class to verifywhitelist- list of regular expressions to match class name against- Returns:
- true if the class matched at least one of the regular expressions, false otherwise
-
-