saker.util Documentation TaskDoc JavaDoc Packages
public class SerialUtils
Class containing utility functions related to object and data serialization.

This class defines methods for complex object to read from and write to object streams. Any method that starts with readExternal or writeExternal implement functionality that read or write the argument object(s) to a specified stream in a given format. The format of the serialization is unified among the externalizing functions:

  • For collections:
    • The size of the collection is written to the stream as a raw int.
    • If the collections is null, the size of -1 is written to the stream, and no elements are written.
    • Each element in the externalized collection is written out to the stream after each other.
  • For maps:
    • The size of the map is written to the stream as a raw int.
    • If the map is null, the size -1 is written to the stream, and no map entries are written.
    • Each entry in the externalized map is written out as key and pair objects separately, in this order.
  • For iterables:
    • If the iterable is null, an implementation dependent sentinel enum object is written to the stream to signal that.
    • An iterator is created, and every element encountered is written out to the output.
    • An end-of-iterable sentinel enum object is written to the output, to signal that no more elements are present.
  • For array:
    • Same as for collections.
The size of the collections/maps are queried from them before any serialization is done. Keep in mind, if that they are concurrent collections, this query may not have O(1) complexity.

The elements of collections/maps are written out in the order they are encountered by their iterators.

If the externalized collections are sorted by a comparator, such as SortedSet or SortedMap instances, the utility functions will not write the comparator of the collections. Callers should manually write the comparators of such collections to the stream if necessary. When appropriate, consider sorting these collections by their natural order, so there will be no such problems.

If the collections are concurrently modified during the serialization, meaning that if the externalizing methods fail to enumerate enough elements in respect to the queried size, or there are more elements after size amount of them have been written out, a SerializationConcurrentModificationException will be thrown. The difference count of the written elements can be queried from the exception.

Callers may optionally handle such scenario, but they are recommended to ensure that this never occurs, and fail the serialization completely instead. If this happens, make sure to cease all modifications to the externalized collections by employing some sort of synchronization.

Some functions in this class define themselves to read a specific type of collection from an input, or read them as immutable collections. Using this can greatly reduce the memory footprint of the read objects, and greatly improve the reading performance of deserialization. However, users should use great care when calling these functions.

Important: If an external reading method name starts with readExternalSorted, then that method expects the underlying deserialized elements to be sorted in a given order to work. If the underlying elements are not sorted for the associated comparator, then the returned collection will not work correctly. When using such methods, make sure that the elements were externalized in appropriate order, or use a deserializing function that doesn't have this requirement. The reading methods will not throw any exception if the elements are encountered out of order.

Important: The deserializing methods auto-cast the objects to the required element type. These casts are unchecked, therefore callers may run into runtime errors if the deserialized objects have different type. If callers are unsure about the underlying type of the objects, they should either check the types of the elements, or not use serialization methods provided by this class.

The serializing and deserializing methods are interchangeable, meaning that if a collection of a type was written out using one of the externalizing methods, then it may be deserialized by any collection deserializing methods in this class. E.g. A Set is written out using writeExternalCollection(ObjectOutput, Collection<?>). When it is being deserialized, the caller can use readExternalCollection(C, ObjectInput), readExternalImmutableList(ObjectInput), readExternalHashSet(ObjectInput), or any other collection reading methods... (Unless noted otherwise in the documentation.) This only works for same object structured types, meaning that collections cannot be read back as maps, or iterables, and vice versa. (The above mentioned sorted requirements still in place.)

Methods that use custom serialization for objects are only interchangeable with other functions that use the same custom serialization functions. (Such as writeExternalCollection(OUT, Collection<E>, ObjectWriterFunction<super OUT, ? super E>), writeExternalExternalizableCollection(ObjectOutput, Collection<extends Externalizable>), writeExternalUTFCollection(DataOutput, Collection<String>), etc...)

In the documentation of the externalizing methods, there will be an identifier for the format of the serialized data. Check these identifiers in the methods to help identify the interchangeable methods.

If you're using methods in this class, make sure that you understand the inner workings, and implications of them.

Methods
public static byte
readByteFromBuffer(byte[] buf, int offset)
Reads a byte from the argument buffer at the given offset.
public static char
readCharFromBuffer(byte[] buf, int offset)
Reads a char from the argument buffer at the given offset.
public static <E, IN extends DataInput> E[]
readExternalArray(IN in, IntFunction<extends E[]> arraycreator, ObjectReaderFunction<super IN, ? extends E> reader)
Reads an array from the object input using a custom deserializer for its elements.
public static <E> E[]
readExternalArray(ObjectInput in, IntFunction<extends E[]> arraycreator)
Reads an array from the object input.
public static <E> ArrayList<E>
Reads a ArrayList from the object input.
public static byte[]
Reads a byte array from the object input.
public static <C extends Collection<E>, E, IN extends DataInput> C
readExternalCollection(C coll, IN in, ObjectReaderFunction<super IN, ? extends E> reader)
Reads a collection from the object input using a custom deserializer and adds its elements to the argument collection.
public static <C extends Collection<E>, E> C
Reads a collection from the object input and adds its elements to the argument collection.
public static <C extends Collection<E>, E> C
readExternalCollectionSize(ObjectInput in, IntFunction<extends C> collsupplier)
Reads a collection from the object input, that is instantiated by the argument supplier.
public static <E extends Enum<E>> EnumSet<E>
Reads an EnumSet from the object input.
public static <E extends Externalizable, C extends Collection<E>> C
readExternalExternalizableCollection(C coll, ObjectInput in, Supplier<extends E> elementsupplier)
Reads a collection of externalizable elements and adds its elements to the argument collection.
public static <M extends Map<K, V>, K extends Externalizable, V extends Externalizable> M
readExternalExternalizableMap(M map, ObjectInput in, Supplier<extends K> keysupplier, Supplier<extends V> valuesupplier)
Reads a map containing Externalizable keys and values from the object input.
public static <K, V> HashMap<K, V>
Reads a HashMap from the object input.
public static <E> HashSet<E>
Reads a HashSet from the object input.
public static <K, V> Map<K, V>
Reads an immutable hash map from the object input.
public static <E> Set<E>
Reads an immutable hash set from the object input.
public static <K, V> Map<K, V>
Reads an immutable identity hash map from the object input.
public static <K, V> Map<K, V>
Reads an immutable linked hash map from the object input.
public static <E> Set<E>
Reads an immutable linked hash set from the object input.
public static <E, IN extends DataInput> List<E>
readExternalImmutableList(IN in, ObjectReaderFunction<super IN, ? extends E> reader)
Reads an immutable list from the object input using a custom deserializer for its elements.
public static <E> List<E>
Reads an immutable list from the object input.
public static <K, V> NavigableMap<K, V>
Reads an immutable navigable map from the object input.
public static <K, V> NavigableMap<K, V>
Reads an immutable navigable map from the object input.
public static <E> NavigableSet<E>
Reads an immutable navigable set from the object input.
public static <E> NavigableSet<E>
Reads an immutable navigable set with the given sorting order from the object input.
public static <E> Iterable<E>
Reads an iterable from the object input.
public static <C extends Collection<super E>, E> C
Reads an iterable from the object input and adds the elements to the argument collection.
public static <K extends Externalizable, V> Map<K, V>
readExternalKeyExternalizableMap(Map<K, V> map, ObjectInput in, Supplier<extends K> keysupplier)
Reads a map containing Externalizable keys from the object input.
public static <K, V> LinkedHashMap<K, V>
Reads a LinkedHashMap from the object input.
public static <E> LinkedHashSet<E>
Reads a LinkedHashSet from the object input.
public static <M extends Map<K, V>, K, V, IN extends DataInput> M
readExternalMap(M map, IN in, ObjectReaderFunction<super IN, ? extends K> keyreader, ObjectReaderFunction<super IN, ? extends V> valuereader)
Reads a map from the object input using a custom deserializer for its keys and values, and adds its entries to the argument map.
public static <M extends Map<K, V>, K, V> M
Reads a map from the object input and puts its entries to the argument map.
public static <M extends Map<K, V>, K, V> M
readExternalMapSize(ObjectInput in, IntFunction<extends M> mapsupplier)
Reads a map from the object input, that is instantiated by the argument supplier.
public static <E> E
Reads an objects from the object input.
public static <K, V, IN extends DataInput> NavigableMap<K, V>
readExternalSortedImmutableNavigableMap(IN in, Comparator<super K> comparator, ObjectReaderFunction<super IN, ? extends K> keyreader, ObjectReaderFunction<super IN, ? extends V> valuereader)
Reads an immutable navigable map from the object input using a custom deserializer for its keys and values, given that the deserialized entries are already in order for the argument comparator.
public static <K, V, IN extends DataInput> NavigableMap<K, V>
readExternalSortedImmutableNavigableMap(IN in, ObjectReaderFunction<super IN, ? extends K> keyreader, ObjectReaderFunction<super IN, ? extends V> valuereader)
Reads an immutable navigable map from the object input using a custom deserializer for its keys and values, given that the deserialized entries are already in order.
public static <K, V> NavigableMap<K, V>
Reads an immutable navigable map from the object input given that the deserialized entries are already in order.
public static <K, V> NavigableMap<K, V>
Reads an immutable navigable map from the object input given that the deserialized entries are already in order for the argument comparator.
public static <E> NavigableSet<E>
Reads an immutable navigable set from the object input given that the deserialized objects are already in order.
public static <E> NavigableSet<E>
Reads an immutable navigable set from the object input given that the deserialized objects are already in order for the argument comparator.
public static <K, V, IN extends DataInput> TreeMap<K, V>
readExternalSortedTreeMap(IN in, Comparator<super K> comparator, ObjectReaderFunction<super IN, ? extends K> keyreader, ObjectReaderFunction<super IN, ? extends V> valuereader)
Reads a tree map map from the object input using a custom deserializer for its keys and values, given that the deserialized entries are already in order for the argument comparator.
public static <K, V, IN extends DataInput> TreeMap<K, V>
readExternalSortedTreeMap(IN in, ObjectReaderFunction<super IN, ? extends K> keyreader, ObjectReaderFunction<super IN, ? extends V> valuereader)
Reads a tree map from the object input using a custom deserializer for its keys and values, given that the deserialized entries are already in order.
public static <K, V> TreeMap<K, V>
Reads a tree map from the object input given that the deserialized entries are already in order.
public static <K, V> TreeMap<K, V>
Reads a tree map from the object input given that the deserialized entries are already in order for the argument comparator.
public static <E> TreeSet<E>
Reads a tree set from the object input given that the deserialized objects are already in order.
public static <E> TreeSet<E>
Reads a tree set from the object input given that the deserialized objects are already in order for the argument comparator.
public static StackTraceElement
Reads an externalized stack trace element from the object input.
public static <C extends Collection<super String>> C
Reads a collection of string elements from the object input.
public static <K, V extends Externalizable> Map<K, V>
readExternalValueExternalizableMap(Map<K, V> map, ObjectInput in, Supplier<extends V> valuesupplier)
Reads a map containing Externalizable values from the object input.
public static int
readIntFromBuffer(byte[] buf, int offset)
Reads a int from the argument buffer at the given offset.
public static long
readLongFromBuffer(byte[] buf, int offset)
Reads a long from the argument buffer at the given offset.
public static short
readShortFromBuffer(byte[] buf, int offset)
Reads a short from the argument buffer at the given offset.
public static void
writeByteToBuffer(byte v, byte[] buf, int offset)
Writes a byte to the argument buffer at the given offset.
public static void
writeCharToBuffer(char v, byte[] buf, int offset)
Writes a char to the argument buffer at the given offset.
public static <E, OUT extends DataOutput> void
writeExternalArray(OUT out, E[] array, ObjectWriterFunction<super OUT, ? super E> elemwriter)
Writes an array to the object output using the custom element serializer.
public static void
Writes an array to the object output.
public static void
writeExternalArray(ObjectOutput out, Object[] array, int offset, int length)
Writes a specific range of an array to the object output.
public static void
Writes a byte array to the object output.
public static void
writeExternalByteArray(ObjectOutput out, byte[] array, int offset, int length)
Writes the given range of the argument byte array to the object output.
public static <E, OUT extends DataOutput> void
writeExternalCollection(OUT out, Collection<E> coll, ObjectWriterFunction<super OUT, ? super E> writer)
Writes a collection to the object output using a custom serializer.
public static void
Writes a collection to the object output.
public static void
Writes a collection of externalizable elements to the object output.
public static <K extends Externalizable, V extends Externalizable> void
Writes a map containing Externalizable keys and values to the object output.
public static void
Writes an iterable to the object output.
public static <K extends Externalizable> void
Writes a map containing Externalizable keys to the object output.
public static <K, V, OUT extends DataOutput> void
writeExternalMap(OUT out, Map<extends K, ? extends V> map, ObjectWriterFunction<super OUT, ? super K> keywriter, ObjectWriterFunction<super OUT, ? super V> valuewriter)
Writes a map to the object output using the custom key and value serializers.
public static void
Writes a map to the object output.
public static void
Writes an object to the object output.
public static void
Writes a stack trace element externally to the object output.
public static void
Writes a collection of string elements to the object output.
public static <V extends Externalizable> void
Writes a map containing Externalizable values to the object output.
public static void
writeIntToBuffer(int v, byte[] buf, int offset)
Writes a int to the argument buffer at the given offset.
public static void
writeLongToBuffer(long v, byte[] buf, int offset)
Writes a long to the argument buffer at the given offset.
public static void
writeShortToBuffer(short v, byte[] buf, int offset)
Writes a short to the argument buffer at the given offset.
public static byte readByteFromBuffer(byte[] buf, int offset) throws NullPointerException, IndexOutOfBoundsException
Reads a byte from the argument buffer at the given offset.
bufThe byte buffer.
offsetThe offset to read the byte from.
The byte read from the given offset.
NullPointerExceptionIf the buffer is null.
IndexOutOfBoundsExceptionIf the offset index is outside of the array.
public static char readCharFromBuffer(byte[] buf, int offset) throws NullPointerException, IndexOutOfBoundsException
Reads a char from the argument buffer at the given offset.

The char is read in big-endian order.

bufThe byte buffer.
offsetThe offset to read the char from.
The char read from the given offset.
NullPointerExceptionIf the buffer is null.
IndexOutOfBoundsExceptionIf the offset index and the next 2 bytes are outside of the array.
public static <E, IN extends DataInput> E[] readExternalArray(IN in, IntFunction<extends E[]> arraycreator, ObjectReaderFunction<super IN, ? extends E> reader) throws IOException, ClassNotFoundException, NullPointerException
Reads an array from the object input using a custom deserializer for its elements.

Format identifier: collection-object

EThe element type.
INThe type of the object input.
inThe object input.
arraycreatorThe function to create the result array for the requested size.
readerThe custom deserializer for each element object.
An array, or null if a null collection was deserialized.
IOExceptionIn case of I/O error.
ClassNotFoundExceptionIf a class was not found during serialization.
NullPointerExceptionIf the input, the array creator, the created array, or the element reader is null.
Reads an array from the object input.

Format identifier: collection-object

EThe element type.
inThe object input.
arraycreatorThe function to create the result array for the requested size.
An array, or null if a null collection was deserialized.
IOExceptionIn case of I/O error.
ClassNotFoundExceptionIf a class was not found during serialization.
NullPointerExceptionIf the input, the array creator, or the created array is null.
ArrayStoreExceptionIf a deserialized object cannot be stored in the created array.
Reads a ArrayList from the object input.

Format identifier: collection-object

The elements of the returned array list is uncheckedly casted to the result element type.

Same as:

 readExternalCollectionSize(in, ArrayList::new);
 
EThe element type.
inThe object input.
An array list, or null if a null collection was deserialized.
ClassNotFoundExceptionIf a class was not found during serialization.
IOExceptionIn case of I/O error.
NullPointerExceptionIf the input is null.
Reads a byte array from the object input.

Format identifier: collection-byte

inThe object input.
An array, or null if a null collection was deserialized.
IOExceptionIn case of I/O error.
NullPointerExceptionIf the input is null.
public static <C extends Collection<E>, E, IN extends DataInput> C readExternalCollection(C coll, IN in, ObjectReaderFunction<super IN, ? extends E> reader) throws IOException, ClassNotFoundException, NullPointerException
Reads a collection from the object input using a custom deserializer and adds its elements to the argument collection.

Format identifier: collection-custom

The caller is responsible for passing the reader function that reads the object in the same format as it was written out.

CThe type of the collection.
EThe element type.
INThe type of the object input.
collThe collection to add the deserialized objects to.
inThe object input.
readerThe custom deserializer for each element object.
The argument collection, or null if a null collection was deserialized.
IOExceptionIn case of I/O error.
ClassNotFoundExceptionIf a class was not found during serialization.
NullPointerExceptionIf the input, the collection, or the reader is null.
Reads a collection from the object input and adds its elements to the argument collection.

Format identifier: collection-object

The element type of the deserialized objects are uncheckedly casted.

CThe type of the collection.
EThe element type.
collThe collection to add the deserialized objects to.
inThe object input.
The argument collection, or null if a null collection was deserialized.
IOExceptionIn case of I/O error.
ClassNotFoundExceptionIf a class was not found during serialization.
NullPointerExceptionIf the input or the collection is null.
public static <C extends Collection<E>, E> C readExternalCollectionSize(ObjectInput in, IntFunction<extends C> collsupplier) throws IOException, ClassNotFoundException, NullPointerException
Reads a collection from the object input, that is instantiated by the argument supplier.

Format identifier: collection-object

The argument collection supplier can be used to construct an appropriate collection for a given number of elements.
Example use-case:

 readExternalCollectionSize(ArrayList::new);
 

The element type of the deserialized objects are uncheckedly casted.

CThe type of the collection.
EThe element type.
inThe object input.
collsupplierThe collection supplier for the count of elements to be deserialized.
The deserialized collection. This is either null or the same collection returned by the supplier.
IOExceptionIn case of I/O error.
ClassNotFoundExceptionIf a class was not found during serialization.
NullPointerExceptionIf the input, the collection supplier, or the created collection is null.
Reads an EnumSet from the object input.

Format identifier: collection-object

EThe element enum type.
enumclassThe type of the element enums.
inThe object input.
An enum set, or null if a null collection was deserialized.
IOExceptionIn case of I/O error.
ClassNotFoundExceptionIf a class was not found during serialization.
ClassCastExceptionIf a deserialized object is not an instance of the enum type.
NullPointerExceptionIf the input, or any of the deserialized elements are null.
public static <E extends Externalizable, C extends Collection<E>> C readExternalExternalizableCollection(C coll, ObjectInput in, Supplier<extends E> elementsupplier) throws IOException, ClassNotFoundException, NullPointerException
Reads a collection of externalizable elements and adds its elements to the argument collection.

Format identifier: collection-externalizable

EThe element type.
CThe type of the collection.
collThe collection to add the deserialized objects to.
inThe object input.
elementsupplierThe supplier which instantiates the externalizable elements.
The argument collection, or null if a null collection was deserialized.
IOExceptionIn case of I/O error.
ClassNotFoundExceptionIf a class was not found during serialization.
NullPointerExceptionIf the input, the supplier, or the element returned by the supplier is null.
public static <M extends Map<K, V>, K extends Externalizable, V extends Externalizable> M readExternalExternalizableMap(M map, ObjectInput in, Supplier<extends K> keysupplier, Supplier<extends V> valuesupplier) throws IOException, ClassNotFoundException, NullPointerException
Reads a map containing Externalizable keys and values from the object input.

Format identifier: map-externalizable-externalizable

MThe type of the map.
KThe key type.
VThe value type.
mapThe map to add the deserialized entries to.
inThe object input.
keysupplierThe supplier which instantiates the externalizable keys.
valuesupplierThe supplier which instantiates the externalizable values.
The argument map, or null if a null map was deserialized.
IOExceptionIn case of I/O error.
ClassNotFoundExceptionIf a class was not found during serialization.
NullPointerExceptionIf the input, the key supplier, the value supplier, the map, the created keys, or the crated values are null.
Reads a HashMap from the object input.

Format identifier: map-object-object

The key and value types of the deserialized entries are uncheckedly casted.

Similar to:

 readExternalMap(new HashMap<>(), in);
 
KThe key type.
VThe value type.
inThe object input.
A hash map, or null if a null map was deserialized.
ClassNotFoundExceptionIf a class was not found during serialization.
IOExceptionIn case of I/O error.
NullPointerExceptionIf the input is null.
Reads a HashSet from the object input.

Format identifier: collection-object

The elements of the returned hash set is uncheckedly casted to the result element type.

Similar to:

 readExternalCollection(new HashSet<>(), in);
 
EThe element type.
inThe object input.
A hash set, or null if a null collection was deserialized.
ClassNotFoundExceptionIf a class was not found during serialization.
IOExceptionIn case of I/O error.
NullPointerExceptionIf the input is null.
Reads an immutable hash map from the object input.

Format identifier: map-object-object

The key and value types of the deserialized entries are uncheckedly casted.

The iteration order in the returned map might not be the same as order of the deserialized entries.

KThe key type.
VThe value type.
inThe object input.
An immutable hash map, or null if a null map was deserialized.
IOExceptionIn case of I/O error.
ClassNotFoundExceptionIf a class was not found during serialization.
NullPointerExceptionIf the input is null.
Reads an immutable hash set from the object input.

Format identifier: collection-object

The element type of the deserialized objects are uncheckedly casted.

The iteration order in the returned set might not be the same as order of the deserialized objects.

EThe element type.
inThe object input.
An immutable hash set, or null if a null collection was deserialized.
IOExceptionIn case of I/O error.
ClassNotFoundExceptionIf a class was not found during serialization.
NullPointerExceptionIf the input is null.
Reads an immutable identity hash map from the object input.

Format identifier: map-object-object

The key and value types of the deserialized entries are uncheckedly casted.

The iteration order in the returned map might not be the same as order of the deserialized entries.

KThe key type.
VThe value type.
inThe object input.
An immutable identity hash map, or null if a null map was deserialized.
IOExceptionIn case of I/O error.
ClassNotFoundExceptionIf a class was not found during serialization.
NullPointerExceptionIf the input is null.
Reads an immutable linked hash map from the object input.

Format identifier: map-object-object

The key and value types of the deserialized entries are uncheckedly casted.

The iteration order in the returned map is the same as order of the deserialized entries.

KThe key type.
VThe value type.
inThe object input.
An immutable linked hash map, or null if a null map was deserialized.
IOExceptionIn case of I/O error.
ClassNotFoundExceptionIf a class was not found during serialization.
NullPointerExceptionIf the input is null.
Reads an immutable linked hash set from the object input.

Format identifier: collection-object

The element type of the deserialized objects are uncheckedly casted.

The iteration order in the returned set is the same as order of the deserialized objects.

EThe element type.
inThe object input.
An immutable linked hash set, or null if a null collection was deserialized.
IOExceptionIn case of I/O error.
ClassNotFoundExceptionIf a class was not found during serialization.
NullPointerExceptionIf the input is null.
public static <E, IN extends DataInput> List<E> readExternalImmutableList(IN in, ObjectReaderFunction<super IN, ? extends E> reader) throws IOException, ClassNotFoundException, NullPointerException
Reads an immutable list from the object input using a custom deserializer for its elements.

Format identifier: collection-custom

EThe element type.
INThe type of the object input.
inThe object input.
readerThe custom deserializer for each element object.
An immutable list, or null if a null collection was deserialized.
IOExceptionIn case of I/O error.
ClassNotFoundExceptionIf a class was not found during serialization.
NullPointerExceptionIf the input, or the element reader is null.
Reads an immutable list from the object input.

Format identifier: collection-object

The element type of the deserialized objects are uncheckedly casted.

EThe element type.
inThe object input.
An immutable list, or null if a null collection was deserialized.
IOExceptionIn case of I/O error.
ClassNotFoundExceptionIf a class was not found during serialization.
NullPointerExceptionIf the input is null.
Reads an immutable navigable map from the object input.

Format identifier: map-object-object

The key and value types of the deserialized entries are uncheckedly casted.

The returned map will be ordered by the natural order of the keys.

The entries in the stream are not required to be already in order.

KThe key type.
VThe value type.
inThe object input.
An immutable navigable map, or null if a null map was deserialized.
IOExceptionIn case of I/O error.
ClassNotFoundExceptionIf a class was not found during serialization.
NullPointerExceptionIf the input is null.
Reads an immutable navigable map from the object input.

Format identifier: map-object-object

The key and value types of the deserialized entries are uncheckedly casted.

The returned map will be ordered using the argument comparator.

The entries in the stream are not required to be already in order.

KThe key type.
VThe value type.
inThe object input.
comparatorThe comparator that defines the order of the entries.
An immutable navigable map, or null if a null map was deserialized.
IOExceptionIn case of I/O error.
ClassNotFoundExceptionIf a class was not found during serialization.
NullPointerExceptionIf the input is null.
Reads an immutable navigable set from the object input.

Format identifier: collection-object

The element type of the deserialized objects are uncheckedly casted.

The returned set will be ordered by the natural order of the elements.

The elements in the stream are not required to be already in order.

EThe element type.
inThe object input.
An immutable navigable set, or null if a null collection was deserialized.
IOExceptionIn case of I/O error.
ClassNotFoundExceptionIf a class was not found during serialization.
NullPointerExceptionIf the input is null.
Reads an immutable navigable set with the given sorting order from the object input.

Format identifier: collection-object

The element type of the deserialized objects are uncheckedly casted.

The returned set will be ordered using the argument comparator.

The elements in the stream are not required to be already in order.

EThe element type.
inThe object input.
comparatorThe comparator that defines the order of the returned set.
An immutable navigable set, or null if a null collection was deserialized.
IOExceptionIn case of I/O error.
ClassNotFoundExceptionIf a class was not found during serialization.
NullPointerExceptionIf the input is null.
Reads an iterable from the object input.

Format identifier: iterable-object

The elements of the returned iterable is uncheckedly casted to the result element type.

EThe element type.
inThe object input.
The deserialized iterable.
IOExceptionIn case of I/O error.
ClassNotFoundExceptionIf a class was not found during serialization.
NullPointerExceptionIf the input is null.
public static <C extends Collection<super E>, E> C readExternalIterable(C coll, ObjectInput in) throws IOException, ClassNotFoundException, NullPointerException
Reads an iterable from the object input and adds the elements to the argument collection.

Format identifier: iterable-object

The element type of the deserialized objects are uncheckedly casted.

CThe type of the collection.
EThe element type.
collThe collection to add the deserialized objects to.
inThe object input.
The argument collection, or null if a null iterable was deserialized.
IOExceptionIn case of I/O error.
ClassNotFoundExceptionIf a class was not found during serialization.
NullPointerExceptionIf the input or the collection is null.
public static <K extends Externalizable, V> Map<K, V> readExternalKeyExternalizableMap(Map<K, V> map, ObjectInput in, Supplier<extends K> keysupplier) throws IOException, ClassNotFoundException, NullPointerException
Reads a map containing Externalizable keys from the object input.

Format identifier: map-externalizable-object

The key types of the deserialized entries are uncheckedly casted.

KThe key type.
VThe value type.
mapThe map to add the deserialized entries to.
inThe object input.
keysupplierThe supplier which instantiates the externalizable keys.
The argument map, or null if a null map was deserialized.
IOExceptionIn case of I/O error.
ClassNotFoundExceptionIf a class was not found during serialization.
NullPointerExceptionIf the input, the key supplier, the map, or the created keys are null.
Reads a LinkedHashMap from the object input.

Format identifier: map-object-object

The key and value types of the deserialized entries are uncheckedly casted.

Similar to:

 readExternalMap(new LinkedHashMap<>(), in);
 
KThe key type.
VThe value type.
inThe object input.
A linked hash map, or null if a null map was deserialized.
ClassNotFoundExceptionIf a class was not found during serialization.
IOExceptionIn case of I/O error.
NullPointerExceptionIf the input is null.
Reads a LinkedHashSet from the object input.

Format identifier: collection-object

The elements of the returned linked hash set is uncheckedly casted to the result element type.

Similar to:

 readExternalCollection(new LinkedHashSet<>(), in);
 
EThe element type.
inThe object input.
A linked hash set, or null if a null collection was deserialized.
ClassNotFoundExceptionIf a class was not found during serialization.
IOExceptionIn case of I/O error.
NullPointerExceptionIf the input is null.
public static <M extends Map<K, V>, K, V, IN extends DataInput> M readExternalMap(M map, IN in, ObjectReaderFunction<super IN, ? extends K> keyreader, ObjectReaderFunction<super IN, ? extends V> valuereader) throws IOException, ClassNotFoundException, NullPointerException
Reads a map from the object input using a custom deserializer for its keys and values, and adds its entries to the argument map.

Format identifier: map-custom-custom

The caller is responsible for passing the reader functions that reads the objects in the same format as it was written out.

MThe type of the map.
KThe key type.
VThe value type.
INThe type of the object input.
mapThe map to add the deserialized entries to.
inThe object input.
keyreaderThe custom deserializer for each key object.
valuereaderThe custom deserializer for each value object.
The argument map, or null if a null map was deserialized.
IOExceptionIn case of I/O error.
ClassNotFoundExceptionIf a class was not found during serialization.
NullPointerExceptionIf the input, the map, the key reader, or the value reader is null.
public static <M extends Map<K, V>, K, V> M readExternalMap(M map, ObjectInput in) throws IOException, ClassNotFoundException, NullPointerException
Reads a map from the object input and puts its entries to the argument map.

Format identifier: map-object-object

The key and value types of the deserialized entries are uncheckedly casted.

MThe type of the map.
KThe key type.
VThe value type.
mapThe map to add the deserialized entries to.
inThe object input.
The argument map, or null if a null map was deserialized.
IOExceptionIn case of I/O error.
ClassNotFoundExceptionIf a class was not found during serialization.
NullPointerExceptionIf the input or the map is null.
public static <M extends Map<K, V>, K, V> M readExternalMapSize(ObjectInput in, IntFunction<extends M> mapsupplier) throws IOException, ClassNotFoundException, NullPointerException
Reads a map from the object input, that is instantiated by the argument supplier.

Format identifier: map-object-object

The argument map supplier can be used to construct an appropriate map for a given number of entries.
Example use-case:

 readExternalMapSize(size -> new HashMap<>(size * 4 / 3 + 1));
 

The key and value types of the deserialized entries are uncheckedly casted.

MThe type of the map.
KThe key type.
VThe value type.
inThe object input.
mapsupplierThe map supplier for the count of elements to be deserialized.
The deserialized map. This is either null or the same map returned by the supplier.
IOExceptionIn case of I/O error.
ClassNotFoundExceptionIf a class was not found during serialization.
NullPointerExceptionIf the input, the map supplier, or the created map is null.
Reads an objects from the object input.

Format identifer: object

This method simply calls ObjectInput.readObject(), and uncheckedly casts it to the return type.

EThe return type.
inThe object input.
The deserialized object.
IOExceptionIn case of I/O error.
ClassNotFoundExceptionIf a class was not found during serialization.
NullPointerExceptionIf the input is null.
public static <K, V, IN extends DataInput> NavigableMap<K, V> readExternalSortedImmutableNavigableMap(IN in, Comparator<super K> comparator, ObjectReaderFunction<super IN, ? extends K> keyreader, ObjectReaderFunction<super IN, ? extends V> valuereader) throws IOException, ClassNotFoundException, NullPointerException
Reads an immutable navigable map from the object input using a custom deserializer for its keys and values, given that the deserialized entries are already in order for the argument comparator.

Important: This method relies on that the deserialized entries are ordered by the specified comparator. If this requirement is violated, the returned map will not work correctly.

Format identifier: map-custom-custom

If you're unsure whether the serialized entries are in appropriate order, use:

 ImmutableUtils.unmodifiableNavigableMap(readExternalMap(new TreeMap<>(comparator), in, keyreader, valuereader));
 
KThe key type.
VThe value type.
INThe type of the object input.
inThe object input.
comparatorThe comparator which defines the order of the serialized entries and the returned map. null means the natural order.
keyreaderThe custom deserializer for each key object.
valuereaderThe custom deserializer for each value object.
An immutable navigable map, or null if a null map was deserialized.
IOExceptionIn case of I/O error.
ClassNotFoundExceptionIf a class was not found during serialization.
NullPointerExceptionIf the input, the key reader, or the value reader is null.
public static <K, V, IN extends DataInput> NavigableMap<K, V> readExternalSortedImmutableNavigableMap(IN in, ObjectReaderFunction<super IN, ? extends K> keyreader, ObjectReaderFunction<super IN, ? extends V> valuereader) throws IOException, ClassNotFoundException, NullPointerException
Reads an immutable navigable map from the object input using a custom deserializer for its keys and values, given that the deserialized entries are already in order.

Important: This method relies on that the deserialized entries are ordered by their natural order. If this requirement is violated, the returned map will not work correctly.

Format identifier: map-custom-custom

Same as:

 readExternalSortedImmutableNavigableMap(in, null, keyreader, valuereader);
 

If you're unsure whether the serialized entries are in appropriate order, use:

 ImmutableUtils.unmodifiableNavigableMap(readExternalMap(new TreeMap<>(), in, keyreader, valuereader));
 
KThe key type.
VThe value type.
INThe type of the object input.
inThe object input.
keyreaderThe custom deserializer for each key object.
valuereaderThe custom deserializer for each value object.
An immutable navigable map, or null if a null map was deserialized.
IOExceptionIn case of I/O error.
ClassNotFoundExceptionIf a class was not found during serialization.
NullPointerExceptionIf the input, the key reader, or the value reader is null.
Reads an immutable navigable map from the object input given that the deserialized entries are already in order.

Important: This method relies on that the deserialized entries are ordered by their natural order. If this requirement is violated, the returned map will not work correctly.

Format identifier: map-object-object

The key and value types of the deserialized entries are uncheckedly casted.

Same as:

 readExternalSortedImmutableNavigableMap(in, null);
 
If you're unsure whether the serialized entries are in appropriate order, use:
 ImmutableUtils.unmodifiableNavigableMap(readExternalMap(new TreeMap<>(), in));
 
KThe key type.
VThe value type.
inThe object input.
An immutable navigable map, or null if a null map was deserialized.
IOExceptionIn case of I/O error.
ClassNotFoundExceptionIf a class was not found during serialization.
NullPointerExceptionIf the input is null.
Reads an immutable navigable map from the object input given that the deserialized entries are already in order for the argument comparator.

Important: This method relies on that the deserialized entries are ordered by the specified comparator. If this requirement is violated, the returned map will not work correctly.

Format identifier: map-object-object

The key and value types of the deserialized entries are uncheckedly casted.

If you're unsure whether the serialized entries are in appropriate order, use:

 ImmutableUtils.unmodifiableNavigableMap(readExternalMap(new TreeMap<>(comparator), in));
 
KThe key type.
VThe value type.
inThe object input.
comparatorThe comparator which defines the order of the serialized entries and the returned map. null means the natural order.
An immutable navigable map, or null if a null map was deserialized.
IOExceptionIn case of I/O error.
ClassNotFoundExceptionIf a class was not found during serialization.
NullPointerExceptionIf the input is null.
Reads an immutable navigable set from the object input given that the deserialized objects are already in order.

Important: This method relies on that the deserialized objects are ordered by their natural order. If this requirement is violated, the returned set will not work correctly.

Format identifier: collection-object

The element type of the deserialized objects are uncheckedly casted.

Same as:

 readExternalSortedImmutableNavigableSet(in, null);
 
If you're unsure whether the serialized entries are in appropriate order, use:
 ImmutableUtils.unmodifiableNavigableSet(readExternalCollection(new TreeSet<>(), in));
 
EThe element type.
inThe object input.
An immutable navigable set, or null if a null collection was deserialized.
IOExceptionIn case of I/O error.
ClassNotFoundExceptionIf a class was not found during serialization.
NullPointerExceptionIf the input is null.
Reads an immutable navigable set from the object input given that the deserialized objects are already in order for the argument comparator.

Important: This method relies on that the deserialized objects are ordered by the specified comparator. If this requirement is violated, the returned set will not work correctly.

Format identifier: collection-object

The element type of the deserialized objects are uncheckedly casted.

If you're unsure whether the serialized entries are in appropriate order, use:

 ImmutableUtils.unmodifiableNavigableSet(readExternalCollection(new TreeSet<>(comparator), in));
 
EThe element type.
inThe object input.
comparatorThe comparator which defines the order of the serialized objects and the returned set. null means the natural order.
an immutable navigable set, or null if a null collection was deserialized.
IOExceptionIn case of I/O error.
ClassNotFoundExceptionIf a class was not found during serialization.
NullPointerExceptionIf the input is null.
public static <K, V, IN extends DataInput> TreeMap<K, V> readExternalSortedTreeMap(IN in, Comparator<super K> comparator, ObjectReaderFunction<super IN, ? extends K> keyreader, ObjectReaderFunction<super IN, ? extends V> valuereader) throws IOException, ClassNotFoundException, NullPointerException
Reads a tree map map from the object input using a custom deserializer for its keys and values, given that the deserialized entries are already in order for the argument comparator.

Important: This method relies on that the deserialized entries are ordered by the specified comparator. If this requirement is violated, the returned map will not work correctly.

Format identifier: map-custom-custom

If you're unsure whether the serialized entries are in appropriate order, use:

 readExternalMap(new TreeMap<>(comparator), in, keyreader, valuereader);
 
KThe key type.
VThe value type.
INThe type of the object input.
inThe object input.
comparatorThe comparator which defines the order of the serialized entries and the returned map. null means the natural order.
keyreaderThe custom deserializer for each key object.
valuereaderThe custom deserializer for each value object.
A tree map map, or null if a null map was deserialized.
IOExceptionIn case of I/O error.
ClassNotFoundExceptionIf a class was not found during serialization.
NullPointerExceptionIf the input, the key reader, or the value reader is null.
public static <K, V, IN extends DataInput> TreeMap<K, V> readExternalSortedTreeMap(IN in, ObjectReaderFunction<super IN, ? extends K> keyreader, ObjectReaderFunction<super IN, ? extends V> valuereader) throws IOException, ClassNotFoundException, NullPointerException
Reads a tree map from the object input using a custom deserializer for its keys and values, given that the deserialized entries are already in order.

Important: This method relies on that the deserialized entries are ordered by their natural order. If this requirement is violated, the returned map will not work correctly.

Format identifier: map-custom-custom

Same as:

 readExternalSortedTreeMap(in, null, keyreader, valuereader);
 

If you're unsure whether the serialized entries are in appropriate order, use:

 readExternalMap(new TreeMap<>(), in, keyreader, valuereader);
 
KThe key type.
VThe value type.
INThe type of the object input.
inThe object input.
keyreaderThe custom deserializer for each key object.
valuereaderThe custom deserializer for each value object.
A tree map, or null if a null map was deserialized.
IOExceptionIn case of I/O error.
ClassNotFoundExceptionIf a class was not found during serialization.
NullPointerExceptionIf the input, the key reader, or the value reader is null.
Reads a tree map from the object input given that the deserialized entries are already in order.

Important: This method relies on that the deserialized entries are ordered by their natural order. If this requirement is violated, the returned map will not work correctly.

Format identifier: map-object-object

The key and value types of the deserialized entries are uncheckedly casted.

Same as:

 readExternalSortedTreeMap(in, null);
 
If you're unsure whether the serialized entries are in appropriate order, use:
 readExternalMap(new TreeMap<>(), in);
 
KThe key type.
VThe value type.
inThe object input.
A tree map, or null if a null map was deserialized.
IOExceptionIn case of I/O error.
ClassNotFoundExceptionIf a class was not found during serialization.
NullPointerExceptionIf the input is null.
public static <K, V> TreeMap<K, V> readExternalSortedTreeMap(ObjectInput in, Comparator<super K> comparator) throws IOException, ClassNotFoundException, NullPointerException
Reads a tree map from the object input given that the deserialized entries are already in order for the argument comparator.

Important: This method relies on that the deserialized entries are ordered by the specified comparator. If this requirement is violated, the returned map will not work correctly.

Format identifier: map-object-object

The key and value types of the deserialized entries are uncheckedly casted.

If you're unsure whether the serialized entries are in appropriate order, use:

 readExternalMap(new TreeMap<>(comparator), in);
 
KThe key type.
VThe value type.
inThe object input.
comparatorThe comparator which defines the order of the serialized entries and the returned map. null means the natural order.
A tree map, or null if a null map was deserialized.
IOExceptionIn case of I/O error.
ClassNotFoundExceptionIf a class was not found during serialization.
NullPointerExceptionIf the input is null.
Reads a tree set from the object input given that the deserialized objects are already in order.

Important: This method relies on that the deserialized objects are ordered by their natural order. If this requirement is violated, the returned set will not work correctly.

Format identifier: collection-object

The element type of the deserialized objects are uncheckedly casted.

Same as:

 readExternalSortedTreeSet(in, null);
 
If you're unsure whether the serialized entries are in appropriate order, use:
 readExternalCollection(new TreeSet<>(), in);
 
EThe element type.
inThe object input.
A tree set, or null if a null collection was deserialized.
IOExceptionIn case of I/O error.
ClassNotFoundExceptionIf a class was not found during serialization.
NullPointerExceptionIf the input is null.
Reads a tree set from the object input given that the deserialized objects are already in order for the argument comparator.

Important: This method relies on that the deserialized objects are ordered by the specified comparator. If this requirement is violated, the returned set will not work correctly.

Format identifier: collection-object

The element type of the deserialized objects are uncheckedly casted.

If you're unsure whether the serialized entries are in appropriate order, use:

 readExternalCollection(new TreeSet<>(comparator), in);
 
EThe element type.
inThe object input.
comparatorThe comparator which defines the order of the serialized objects and the returned set. null means the natural order.
A tree set, or null if a null collection was deserialized.
IOExceptionIn case of I/O error.
ClassNotFoundExceptionIf a class was not found during serialization.
NullPointerExceptionIf the input is null.
Reads an externalized stack trace element from the object input.

Format identifier: stack_trace_element

See writeExternalStackTraceElement(ObjectOutput, StackTraceElement) for the exact internal format.

inThe object input.
The deserialized stack trace element.
IOExceptionIn case of I/O error.
ClassNotFoundExceptionIf a class was not found during serialization.
NullPointerExceptionIf the input is null.
public static <C extends Collection<super String>> C readExternalUTFCollection(C coll, DataInput in) throws IOException, NullPointerException
Reads a collection of string elements from the object input.

Format identifier: collection-utf

CThe type of the collection.
collThe collection to add the deserialized objects to.
inThe object input.
The argument collection, or null if a null collection was deserialized.
IOExceptionIn case of I/O error.
NullPointerExceptionIf the input is null.
public static <K, V extends Externalizable> Map<K, V> readExternalValueExternalizableMap(Map<K, V> map, ObjectInput in, Supplier<extends V> valuesupplier) throws IOException, ClassNotFoundException, NullPointerException
Reads a map containing Externalizable values from the object input.

Format identifier: map-object-externalizable

The value types of the deserialized entries are uncheckedly casted.

KThe key type.
VThe value type.
mapThe map to add the deserialized entries to.
inThe object input.
valuesupplierThe supplier which instantiates the externalizable values.
The argument map, or null if a null map was deserialized.
IOExceptionIn case of I/O error.
ClassNotFoundExceptionIf a class was not found during serialization.
NullPointerExceptionIf the input, the value supplier, the map, or the created values are null.
public static int readIntFromBuffer(byte[] buf, int offset) throws NullPointerException, IndexOutOfBoundsException
Reads a int from the argument buffer at the given offset.

The int is read in big-endian order.

bufThe byte buffer.
offsetThe offset to read the itn from.
The int read from the given offset.
NullPointerExceptionIf the buffer is null.
IndexOutOfBoundsExceptionIf the offset index and the next 4 bytes are outside of the array.
public static long readLongFromBuffer(byte[] buf, int offset) throws NullPointerException, IndexOutOfBoundsException
Reads a long from the argument buffer at the given offset.

The long is read in big-endian order.

bufThe byte buffer.
offsetThe offset to read the long from.
The long read from the given offset.
NullPointerExceptionIf the buffer is null.
IndexOutOfBoundsExceptionIf the offset index and the next 8 bytes are outside of the array.
public static short readShortFromBuffer(byte[] buf, int offset) throws NullPointerException, IndexOutOfBoundsException
Reads a short from the argument buffer at the given offset.

The short is read in big-endian order.

bufThe byte buffer.
offsetThe offset to read the short from.
The short read from the given offset.
NullPointerExceptionIf the buffer is null.
IndexOutOfBoundsExceptionIf the offset index and the next 2 bytes are outside of the array.
public static void writeByteToBuffer(byte v, byte[] buf, int offset) throws NullPointerException, IndexOutOfBoundsException
Writes a byte to the argument buffer at the given offset.
vThe byte to write.
bufThe byte buffer.
offsetThe offset to write the byte to.
NullPointerExceptionIf the buffer is null.
IndexOutOfBoundsExceptionIf the offset index is outside of the array.
public static void writeCharToBuffer(char v, byte[] buf, int offset) throws NullPointerException, IndexOutOfBoundsException
Writes a char to the argument buffer at the given offset.

The char is written in big-endian order.

vThe char to write.
bufThe byte buffer.
offsetThe offset to write the char to.
NullPointerExceptionIf the buffer is null.
IndexOutOfBoundsExceptionIf the offset index, and the next 2 bytes are outside of the array.
public static <E, OUT extends DataOutput> void writeExternalArray(OUT out, E[] array, ObjectWriterFunction<super OUT, ? super E> elemwriter) throws IOException, NullPointerException
Writes an array to the object output using the custom element serializer.

Format identifier: collection-custom

EThe element type.
OUTThe type of the object output.
outThe object output.
arrayThe array to write.
elemwriterThe custom serializer for each element object.
IOExceptionIn case of I/O error.
NullPointerExceptionIf the output, or the element writer is null.
public static void writeExternalArray(ObjectOutput out, Object[] array) throws IOException, NullPointerException
Writes an array to the object output.

Format identifier: collection-object

outThe object output.
arrayThe array to write.
IOExceptionIn case of I/O error.
NullPointerExceptionIf the output is null.
Writes a specific range of an array to the object output.

Format identifier: collection-object

outThe object output.
arrayThe array to write.
offsetThe offset index of the range.
lengthThe number of objects to write starting from the offset index.
IOExceptionIn case of I/O error.
NullPointerExceptionIf the output is null.
IllegalArgumentExceptionIf the length is negative.
IndexOutOfBoundsExceptionIf the range does not fully reside in the array.
public static void writeExternalByteArray(ObjectOutput out, byte[] array) throws IOException, NullPointerException
Writes a byte array to the object output.

Format identifier: collection-byte

outThe object output.
arrayThe array to write.
IOExceptionIn case of I/O error.
NullPointerExceptionIf the output is null.
public static void writeExternalByteArray(ObjectOutput out, byte[] array, int offset, int length) throws IOException, NullPointerException, IllegalArgumentException, IndexOutOfBoundsException
Writes the given range of the argument byte array to the object output.

Format identifier: collection-byte

outThe object output.
arrayThe array to write.
offsetThe offset index of the range.
lengthThe number of bytes to write starting from the offset index.
IOExceptionIn case of I/O error.
NullPointerExceptionIf the output is null.
IllegalArgumentExceptionIf the length is negative.
IndexOutOfBoundsExceptionIf the range does not fully reside in the array.
public static <E, OUT extends DataOutput> void writeExternalCollection(OUT out, Collection<E> coll, ObjectWriterFunction<super OUT, ? super E> writer) throws IOException, NullPointerException, SerializationConcurrentModificationException
Writes a collection to the object output using a custom serializer.

Format identifier: collection-custom

EThe type of the elements.
OUTThe type of the object output.
outThe object output.
collThe collection to write.
writerThe custom serializer for each element object.
IOExceptionIn case of I/O error.
NullPointerExceptionIf the output or the writer is null.
SerializationConcurrentModificationExceptionIf the size of the collection doesn't match the numer of elements encountered in it.
Writes a collection to the object output.

Format identifier: collection-object

outThe object output.
collThe collection to write.
IOExceptionIn case of I/O error.
NullPointerExceptionIf the output is null.
SerializationConcurrentModificationExceptionIf the size of the collection doesn't match the numer of elements encountered in it.
Writes a collection of externalizable elements to the object output.

Format identifier: collection-externalizable

The collection may not contain null elements.

outThe object output.
collThe collection to write.
IOExceptionIn case of I/O error.
NullPointerExceptionIf the output or any of the elements are null.
SerializationConcurrentModificationExceptionIf the size of the collection doesn't match the numer of elements encountered in it.
Writes a map containing Externalizable keys and values to the object output.

Format identifier: map-externalizable-externalizable

KThe key type.
VThe value type.
outThe object output.
mapThe map to write.
IOExceptionIn case of I/O error.
NullPointerExceptionIf the output, the map entry set, any of the entries, any of the keys, or any of the values are null.
SerializationConcurrentModificationExceptionIf the size of the map doesn't match the numer of entries encountered in it.
public static void writeExternalIterable(ObjectOutput out, Iterable<?> iterable) throws IOException, NullPointerException
Writes an iterable to the object output.

Format identifier: iterable-object

outThe object output.
iterableThe iterable to write.
IOExceptionIn case of I/O error.
NullPointerExceptionIf the output is null.
Writes a map containing Externalizable keys to the object output.

Format identifier: map-externalizable-object

KThe key type.
outThe object output.
mapThe map to write.
IOExceptionIn case of I/O error.
NullPointerExceptionIf the output, the map entry set, any of the entries, or any of the keys are null.
SerializationConcurrentModificationExceptionIf the size of the map doesn't match the numer of entries encountered in it.
public static <K, V, OUT extends DataOutput> void writeExternalMap(OUT out, Map<extends K, ? extends V> map, ObjectWriterFunction<super OUT, ? super K> keywriter, ObjectWriterFunction<super OUT, ? super V> valuewriter) throws IOException, NullPointerException, SerializationConcurrentModificationException
Writes a map to the object output using the custom key and value serializers.

Format identifier: map-custom-custom

KThe key type.
VThe value type.
OUTThe type of the object output.
outThe object output.
mapThe map to write.
keywriterThe custom serializer for each key object.
valuewriterThe custom serializer for each value object.
IOExceptionIn case of I/O error.
NullPointerExceptionIf the output, the map entry set, any of the entries, the key writer, or the value writer is null.
SerializationConcurrentModificationExceptionIf the size of the map doesn't match the numer of entries encountered in it.
Writes a map to the object output.

Format identifier: map-object-object

outThe object output.
mapThe map to write.
IOExceptionIn case of I/O error.
NullPointerExceptionIf the output, the map entry set, or any of the entries are null.
SerializationConcurrentModificationExceptionIf the size of the map doesn't match the numer of entries encountered in it.
Writes an object to the object output.

Format identifer: object

This method calls ObjectOutput.writeObject(Object) with the argument. Although it is very simple, it is present as a counterpart of readExternalObject(ObjectInput).

outThe object output.
objectThe object to write.
IOExceptionIn case of I/O error.
NullPointerExceptionIf the output is null.
Writes a stack trace element externally to the object output.

Format identifier: stack_trace_element

The format of an externalized stack trace element is the following:

outThe object output.
elemThe stack trace element.
IOExceptionIn case of I/O error.
NullPointerExceptionIf any of the arguments are null.
Writes a collection of string elements to the object output.

Format identifier: collection-utf

outThe object output.
collThe collection to write.
IOExceptionIn case of I/O error.
NullPointerExceptionIf the output is null. If the object output doesn't allow null strings to be written out, and any of the elements are null.
SerializationConcurrentModificationExceptionIf the size of the collection doesn't match the numer of elements encountered in it.
Writes a map containing Externalizable values to the object output.

Format identifier: map-object-externalizable

VThe value type.
outThe object output.
mapThe map to write.
IOExceptionIn case of I/O error.
NullPointerExceptionIf the output, the map entry set, any of the entries, or any of the values are null.
SerializationConcurrentModificationExceptionIf the size of the map doesn't match the numer of entries encountered in it.
public static void writeIntToBuffer(int v, byte[] buf, int offset) throws NullPointerException, IndexOutOfBoundsException
Writes a int to the argument buffer at the given offset.

The int is written in big-endian order.

vThe int to write.
bufThe byte buffer.
offsetThe offset to write the int to.
NullPointerExceptionIf the buffer is null.
IndexOutOfBoundsExceptionIf the offset index, and the next 4 bytes are outside of the array.
public static void writeLongToBuffer(long v, byte[] buf, int offset) throws NullPointerException, IndexOutOfBoundsException
Writes a long to the argument buffer at the given offset.

The long is written in big-endian order.

vThe long to write.
bufThe byte buffer.
offsetThe offset to write the long to.
NullPointerExceptionIf the buffer is null.
IndexOutOfBoundsExceptionIf the offset index, and the next 8 bytes are outside of the array.
public static void writeShortToBuffer(short v, byte[] buf, int offset) throws NullPointerException, IndexOutOfBoundsException
Writes a short to the argument buffer at the given offset.

The short is written in big-endian order.

vThe short to write.
bufThe byte buffer.
offsetThe offset to write the short to.
NullPointerExceptionIf the buffer is null.
IndexOutOfBoundsExceptionIf the offset index, and the next 2 bytes are outside of the array.