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.list;
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  import java.util.List;
24  
25  /***
26   * Serializable subclass of <code>AbstractListDecorator</code>.
27   * 
28   * @author Stephen Colebourne
29   * @author Mauro Franceschini
30   * 
31   * @since Commons Collections 3.1
32   */
33  public abstract class AbstractSerializableListDecorator<E>
34          extends AbstractListDecorator<E>
35          implements Serializable {
36  
37  	// Constants
38  	// -------------------------------------------------------------------------
39  	
40      /*** Serialization version */
41      private static final long serialVersionUID = 2684959196747496299L;
42  
43      // Constructors
44      // -------------------------------------------------------------------------
45      
46      /***
47       * Constructor.
48       */
49      protected AbstractSerializableListDecorator(final List<E> list) {
50          super(list);
51      }
52  
53      // Serialization methods
54      //-----------------------------------------------------------------------
55      
56      /***
57       * Write the list out using a custom routine.
58       * 
59       * @param out the output stream
60       * @throws IOException
61       */
62      private void writeObject(ObjectOutputStream out) throws IOException {
63          out.defaultWriteObject();
64          out.writeObject(collection);
65      }
66  
67      /***
68       * Read the list in using a custom routine.
69       * 
70       * @param in  the input stream
71       * @throws IOException
72       * @throws ClassNotFoundException
73       */
74      private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
75          in.defaultReadObject();
76          collection = (Collection<E>)in.readObject();
77      }
78  
79  }