View Javadoc

1   /*
2    *  Copyright 2004 The Apache Software Foundation
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   */
16  package net.sf.collections15.collection;
17  
18  import java.io.IOException;
19  import java.io.ObjectInputStream;
20  import java.io.ObjectOutputStream;
21  import java.io.Serializable;
22  import java.util.Collection;
23  
24  /***
25   * Serializable subclass of AbstractCollectionDecorator.
26   * 
27   * @author Stephen Colebourne
28   * @since Commons Collections 3.1
29   */
30  public abstract class AbstractSerializableCollectionDecorator<E>
31          extends AbstractCollectionDecorator<E>
32          implements Serializable {
33  
34      /*** Serialization version */
35  	private static final long serialVersionUID = 3257565113925187897L;
36  
37  	/***
38       * Constructor.
39       */
40      protected AbstractSerializableCollectionDecorator(Collection<E> coll) {
41          super(coll);
42      }
43  
44      //-----------------------------------------------------------------------
45      /***
46       * Write the collection out using a custom routine.
47       * 
48       * @param out  the output stream
49       * @throws IOException
50       */
51      private void writeObject(ObjectOutputStream out) throws IOException {
52          out.defaultWriteObject();
53          out.writeObject(collection);
54      }
55  
56      /***
57       * Read the collection in using a custom routine.
58       * 
59       * @param in  the input stream
60       * @throws IOException
61       * @throws ClassNotFoundException
62       */
63      private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
64          in.defaultReadObject();
65          collection = (Collection<E>) in.readObject();
66      }
67  
68  }