Code example for ObjectOutputStream

Methods: defaultWriteObject, writeObject

0
 
        /** 
         * @serialData the factory and the backing map 
         */ 
        private void writeObject(ObjectOutputStream stream) throws IOException {
            stream.defaultWriteObject();
            stream.writeObject(factory);
            stream.writeObject(backingMap());
        } 
 
        @SuppressWarnings("unchecked") 
        // reading data stored by writeObject 
        private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
            stream.defaultReadObject();
            factory = (Supplier<? extends Set<V>>) stream.readObject();
            Map<K, Collection<V>> map = (Map<K, Collection<V>>) stream.readObject();
            setMap(map);
        } 
 
        private static final long serialVersionUID = 0;
    }