001    /*
002     *  Licensed to the Apache Software Foundation (ASF) under one or more
003     *  contributor license agreements.  See the NOTICE file distributed with
004     *  this work for additional information regarding copyright ownership.
005     *  The ASF licenses this file to You under the Apache License, Version 2.0
006     *  (the "License"); you may not use this file except in compliance with
007     *  the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     *  Unless required by applicable law or agreed to in writing, software
012     *  distributed under the License is distributed on an "AS IS" BASIS,
013     *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     *  See the License for the specific language governing permissions and
015     *  limitations under the License.
016     */
017    package org.apache.commons.collections.collection;
018    
019    import java.io.IOException;
020    import java.io.ObjectInputStream;
021    import java.io.ObjectOutputStream;
022    import java.io.Serializable;
023    import java.util.Collection;
024    
025    /**
026     * Serializable subclass of AbstractCollectionDecorator.
027     * 
028     * @author Stephen Colebourne
029     * @since Commons Collections 3.1
030     */
031    public abstract class AbstractSerializableCollectionDecorator
032            extends AbstractCollectionDecorator
033            implements Serializable {
034    
035        /** Serialization version */
036        private static final long serialVersionUID = 6249888059822088500L;
037    
038        /**
039         * Constructor.
040         */
041        protected AbstractSerializableCollectionDecorator(Collection coll) {
042            super(coll);
043        }
044    
045        //-----------------------------------------------------------------------
046        /**
047         * Write the collection out using a custom routine.
048         * 
049         * @param out  the output stream
050         * @throws IOException
051         */
052        private void writeObject(ObjectOutputStream out) throws IOException {
053            out.defaultWriteObject();
054            out.writeObject(collection);
055        }
056    
057        /**
058         * Read the collection in using a custom routine.
059         * 
060         * @param in  the input stream
061         * @throws IOException
062         * @throws ClassNotFoundException
063         */
064        private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
065            in.defaultReadObject();
066            collection = (Collection) in.readObject();
067        }
068    
069    }