private void readObject ( java . io . ObjectInputStream s ) throws IOException , ClassNotFoundException { // Read in the length, threshold, and loadfactor s . defaultReadObject ( ) ; // Read the original length of the array and number of elements int origlength = s . readInt ( ) ; int elements = s . readInt ( ) ; // Compute new size with a bit of room 5% to grow but // No larger than the original size. Make the length // odd if it's large enough, this helps distribute the entries. // Guard against the length ending up zero, that's not valid. int length = ( int ) ( elements * loadFactor ) + ( elements / 20 ) + 3 ; if ( length > elements && ( length & 1 ) == 0 ) length -- ; if ( origlength > 0 && length > origlength ) length = origlength ; table = new FastHashtableEntry [ length ] ; count = 0 ; // Read the number of elements and then all the key/value objects for ( ; elements > 0 ; elements -- ) { Object key = s . readObject ( ) ; Object value = s . readObject ( ) ; put ( key , value ) ; } }
readObject is called to restore the state of the hashtable from a stream . Only the keys and values are serialized since the hash values may be different when the contents are restored . Read count elements and insert into the hashtable .