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 org.apache.commons.collections.set;
  17. import java.io.IOException;
  18. import java.io.ObjectInputStream;
  19. import java.io.ObjectOutputStream;
  20. import java.io.Serializable;
  21. import java.util.Collection;
  22. import java.util.Set;
  23. /**
  24. * Serializable subclass of AbstractSetDecorator.
  25. *
  26. * @author Stephen Colebourne
  27. * @since Commons Collections 3.1
  28. */
  29. public abstract class AbstractSerializableSetDecorator
  30. extends AbstractSetDecorator
  31. implements Serializable {
  32. /** Serialization version */
  33. private static final long serialVersionUID = 1229469966212206107L;
  34. /**
  35. * Constructor.
  36. */
  37. protected AbstractSerializableSetDecorator(Set set) {
  38. super(set);
  39. }
  40. //-----------------------------------------------------------------------
  41. /**
  42. * Write the set out using a custom routine.
  43. *
  44. * @param out the output stream
  45. * @throws IOException
  46. */
  47. private void writeObject(ObjectOutputStream out) throws IOException {
  48. out.defaultWriteObject();
  49. out.writeObject(collection);
  50. }
  51. /**
  52. * Read the set in using a custom routine.
  53. *
  54. * @param in the input stream
  55. * @throws IOException
  56. * @throws ClassNotFoundException
  57. */
  58. private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
  59. in.defaultReadObject();
  60. collection = (Collection) in.readObject();
  61. }
  62. }