Package com.google.common.collect
Class Serialization
java.lang.Object
com.google.common.collect.Serialization
Provides static methods for serializing collection classes.
This class assists the implementation of collection classes. Do not use this class to serialize collections that are defined elsewhere.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static final class
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static <T> Serialization.FieldSetter
<T> getFieldSetter
(Class<T> clazz, String fieldName) (package private) static <K,
V> void populateMap
(Map<K, V> map, ObjectInputStream stream) Populates a map by reading an input stream, as part of deserialization.(package private) static <K,
V> void populateMap
(Map<K, V> map, ObjectInputStream stream, int size) Populates a map by reading an input stream, as part of deserialization.(package private) static <K,
V> void populateMultimap
(Multimap<K, V> multimap, ObjectInputStream stream) Populates a multimap by reading an input stream, as part of deserialization.(package private) static <K,
V> void populateMultimap
(Multimap<K, V> multimap, ObjectInputStream stream, int distinctKeys) Populates a multimap by reading an input stream, as part of deserialization.(package private) static <E> void
populateMultiset
(Multiset<E> multiset, ObjectInputStream stream) Populates a multiset by reading an input stream, as part of deserialization.(package private) static <E> void
populateMultiset
(Multiset<E> multiset, ObjectInputStream stream, int distinctElements) Populates a multiset by reading an input stream, as part of deserialization.(package private) static int
readCount
(ObjectInputStream stream) Reads a count corresponding to a serialized map, multiset, or multimap.(package private) static <K,
V> void writeMap
(Map<K, V> map, ObjectOutputStream stream) Stores the contents of a map in an output stream, as part of serialization.(package private) static <K,
V> void writeMultimap
(Multimap<K, V> multimap, ObjectOutputStream stream) Stores the contents of a multimap in an output stream, as part of serialization.(package private) static <E> void
writeMultiset
(Multiset<E> multiset, ObjectOutputStream stream) Stores the contents of a multiset in an output stream, as part of serialization.
-
Constructor Details
-
Serialization
private Serialization()
-
-
Method Details
-
readCount
Reads a count corresponding to a serialized map, multiset, or multimap. It returns the size of a map serialized bywriteMap(Map, ObjectOutputStream)
, the number of distinct elements in a multiset serialized bywriteMultiset(Multiset, ObjectOutputStream)
, or the number of distinct keys in a multimap serialized bywriteMultimap(Multimap, ObjectOutputStream)
.- Throws:
IOException
-
writeMap
Stores the contents of a map in an output stream, as part of serialization. It does not support concurrent maps whose content may change while the method is running.The serialized output consists of the number of entries, first key, first value, second key, second value, and so on.
- Throws:
IOException
-
populateMap
static <K,V> void populateMap(Map<K, V> map, ObjectInputStream stream) throws IOException, ClassNotFoundExceptionPopulates a map by reading an input stream, as part of deserialization. SeewriteMap(java.util.Map<K, V>, java.io.ObjectOutputStream)
for the data format.- Throws:
IOException
ClassNotFoundException
-
populateMap
static <K,V> void populateMap(Map<K, V> map, ObjectInputStream stream, int size) throws IOException, ClassNotFoundExceptionPopulates a map by reading an input stream, as part of deserialization. SeewriteMap(java.util.Map<K, V>, java.io.ObjectOutputStream)
for the data format. The size is determined by a prior call toreadCount(java.io.ObjectInputStream)
.- Throws:
IOException
ClassNotFoundException
-
writeMultiset
Stores the contents of a multiset in an output stream, as part of serialization. It does not support concurrent multisets whose content may change while the method is running.The serialized output consists of the number of distinct elements, the first element, its count, the second element, its count, and so on.
- Throws:
IOException
-
populateMultiset
static <E> void populateMultiset(Multiset<E> multiset, ObjectInputStream stream) throws IOException, ClassNotFoundException Populates a multiset by reading an input stream, as part of deserialization. SeewriteMultiset(com.google.common.collect.Multiset<E>, java.io.ObjectOutputStream)
for the data format.- Throws:
IOException
ClassNotFoundException
-
populateMultiset
static <E> void populateMultiset(Multiset<E> multiset, ObjectInputStream stream, int distinctElements) throws IOException, ClassNotFoundException Populates a multiset by reading an input stream, as part of deserialization. SeewriteMultiset(com.google.common.collect.Multiset<E>, java.io.ObjectOutputStream)
for the data format. The number of distinct elements is determined by a prior call toreadCount(java.io.ObjectInputStream)
.- Throws:
IOException
ClassNotFoundException
-
writeMultimap
static <K,V> void writeMultimap(Multimap<K, V> multimap, ObjectOutputStream stream) throws IOExceptionStores the contents of a multimap in an output stream, as part of serialization. It does not support concurrent multimaps whose content may change while the method is running. TheMultimap.asMap()
view determines the ordering in which data is written to the stream.The serialized output consists of the number of distinct keys, and then for each distinct key: the key, the number of values for that key, and the key's values.
- Throws:
IOException
-
populateMultimap
static <K,V> void populateMultimap(Multimap<K, V> multimap, ObjectInputStream stream) throws IOException, ClassNotFoundExceptionPopulates a multimap by reading an input stream, as part of deserialization. SeewriteMultimap(com.google.common.collect.Multimap<K, V>, java.io.ObjectOutputStream)
for the data format.- Throws:
IOException
ClassNotFoundException
-
populateMultimap
static <K,V> void populateMultimap(Multimap<K, V> multimap, ObjectInputStream stream, int distinctKeys) throws IOException, ClassNotFoundExceptionPopulates a multimap by reading an input stream, as part of deserialization. SeewriteMultimap(com.google.common.collect.Multimap<K, V>, java.io.ObjectOutputStream)
for the data format. The number of distinct keys is determined by a prior call toreadCount(java.io.ObjectInputStream)
.- Throws:
IOException
ClassNotFoundException
-
getFieldSetter
-