jdk/src/share/classes/java/util/Hashtable.java
changeset 8394 49215a09f282
parent 7816 55a18147b4bf
child 9035 1255eb81cc2f
equal deleted inserted replaced
8393:582bd30ef587 8394:49215a09f282
   843      *             <i>size</i> of the Hashtable (the number of key-value
   843      *             <i>size</i> of the Hashtable (the number of key-value
   844      *             mappings), followed by the key (Object) and value (Object)
   844      *             mappings), followed by the key (Object) and value (Object)
   845      *             for each key-value mapping represented by the Hashtable
   845      *             for each key-value mapping represented by the Hashtable
   846      *             The key-value mappings are emitted in no particular order.
   846      *             The key-value mappings are emitted in no particular order.
   847      */
   847      */
   848     private synchronized void writeObject(java.io.ObjectOutputStream s)
   848     private void writeObject(java.io.ObjectOutputStream s)
   849         throws IOException
   849             throws IOException {
   850     {
   850         Entry<Object, Object> entryStack = null;
   851         // Write out the length, threshold, loadfactor
   851 
   852         s.defaultWriteObject();
   852         synchronized (this) {
   853 
   853             // Write out the length, threshold, loadfactor
   854         // Write out length, count of elements and then the key/value objects
   854             s.defaultWriteObject();
   855         s.writeInt(table.length);
   855 
   856         s.writeInt(count);
   856             // Write out length, count of elements
   857         for (int index = table.length-1; index >= 0; index--) {
   857             s.writeInt(table.length);
   858             Entry entry = table[index];
   858             s.writeInt(count);
   859 
   859 
   860             while (entry != null) {
   860             // Stack copies of the entries in the table
   861                 s.writeObject(entry.key);
   861             for (int index = 0; index < table.length; index++) {
   862                 s.writeObject(entry.value);
   862                 Entry entry = table[index];
   863                 entry = entry.next;
   863 
   864             }
   864                 while (entry != null) {
       
   865                     entryStack =
       
   866                         new Entry<>(0, entry.key, entry.value, entryStack);
       
   867                     entry = entry.next;
       
   868                 }
       
   869             }
       
   870         }
       
   871 
       
   872         // Write out the key/value objects from the stacked entries
       
   873         while (entryStack != null) {
       
   874             s.writeObject(entryStack.key);
       
   875             s.writeObject(entryStack.value);
       
   876             entryStack = entryStack.next;
   865         }
   877         }
   866     }
   878     }
   867 
   879 
   868     /**
   880     /**
   869      * Reconstitute the Hashtable from a stream (i.e., deserialize it).
   881      * Reconstitute the Hashtable from a stream (i.e., deserialize it).