Guest User

Ian

a guest
Apr 16th, 2008
269
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class LargeSerializableConcurrentSkipListMap<K, V> extends
  2.         ConcurrentSkipListMap<K, V> {
  3.     private static final long serialVersionUID = -1525292268623732635L;
  4.  
  5.     private void writeObject(ObjectOutputStream stream) throws IOException {
  6.         for (Map.Entry<K, V> e : this.entrySet()) {
  7.             stream.writeObject(e.getKey());
  8.             stream.writeObject(e.getValue());
  9.         }
  10.         // We do it like this because items can be added and removed
  11.         // during serialization and an "end of object" indicator is more
  12.         // robust given this
  13.         stream.writeObject(new EndObject());
  14.         stream.writeObject(new EndObject());
  15.     }
  16.  
  17.     @SuppressWarnings("unchecked")
  18.     private void readObject(ObjectInputStream stream) throws IOException,
  19.             ClassNotFoundException {
  20.         while (true) {
  21.             Object k = stream.readObject();
  22.             Object v = stream.readObject();
  23.             if ((k instanceof EndObject) && (v instanceof EndObject)) {
  24.                 break;
  25.             }
  26.             this.put((K) k, (V) v);
  27.         }
  28.     }
  29.    
  30.     private static class EndObject implements Serializable {
  31.         private static final long serialVersionUID = -5347717251973679220L;
  32.     }
  33. }
RAW Paste Data