Ignore:
Timestamp:
Apr 27, 2004, 8:39:34 PM (22 years ago)
Author:
bird
Message:

GCC v3.3.3 sources.

Location:
branches/GNU/src/gcc
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/GNU/src/gcc

    • Property svn:ignore
      •  

        old new  
        2626configure.vr
        2727configure.vrs
         28
        2829Makefile
        29 dir.info
        3030lost+found
        3131update.out
  • branches/GNU/src/gcc/libjava/java/io/ObjectInputStream.java

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r1390 r1391  
    11/* ObjectInputStream.java -- Class used to read serialized objects
    2    Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
     2   Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
    33
    44This file is part of GNU Classpath.
     
    88the Free Software Foundation; either version 2, or (at your option)
    99any later version.
    10  
     10
    1111GNU Classpath is distributed in the hope that it will be useful, but
    1212WITHOUT ANY WARRANTY; without even the implied warranty of
     
    3939package java.io;
    4040
    41 import gnu.classpath.Configuration;
    42 
    4341import java.lang.reflect.Array;
    4442import java.lang.reflect.Modifier;
     43
    4544import java.util.Arrays;
    4645import java.util.Hashtable;
     
    5352import java.lang.reflect.InvocationTargetException;
    5453
    55 
     54import gnu.classpath.Configuration;
    5655
    5756public class ObjectInputStream extends InputStream
     
    130129    was_deserializing = this.isDeserializing;
    131130
    132     if (! was_deserializing)
    133       setBlockDataMode (false);
     131   
     132    setBlockDataMode (false);
    134133
    135134    this.isDeserializing = true;
     
    138137    dumpElement ("MARKER: 0x" + Integer.toHexString(marker) + " ");
    139138
    140     switch (marker)
    141     {
    142       case TC_BLOCKDATA:
    143       case TC_BLOCKDATALONG:
    144         if (marker == TC_BLOCKDATALONG)
    145           dumpElementln ("BLOCKDATALONG");
    146         else
    147           dumpElementln ("BLOCKDATA");
    148         readNextBlock (marker);
    149         throw new StreamCorruptedException ("Unexpected blockData");
    150 
    151       case TC_NULL:
    152         dumpElementln ("NULL");
    153         ret_val = null;
    154         break;
    155 
    156       case TC_REFERENCE:
    157       {
    158         dumpElement ("REFERENCE ");
    159         Integer oid = new Integer (this.realInputStream.readInt ());
    160         dumpElementln (Integer.toHexString(oid.intValue()));
    161         ret_val = ((ObjectIdentityWrapper)
    162                    this.objectLookupTable.get (oid)).object;
    163         break;
    164       }
    165 
    166       case TC_CLASS:
    167       {
    168         dumpElementln ("CLASS");
    169         ObjectStreamClass osc = (ObjectStreamClass)readObject ();
    170         Class clazz = osc.forClass ();
    171         assignNewHandle (clazz);
    172         ret_val = clazz;
    173         break;
    174       }
    175 
    176       case TC_CLASSDESC:
    177       {
    178         dumpElement ("CLASSDESC NAME=");
    179         String name = this.realInputStream.readUTF ();
    180         dumpElement (name + "; UID=");
    181         long uid = this.realInputStream.readLong ();
    182         dumpElement (Long.toHexString(uid) + "; FLAGS=");
    183         byte flags = this.realInputStream.readByte ();
    184         dumpElement (Integer.toHexString(flags) + "; FIELD COUNT=");
    185         short field_count = this.realInputStream.readShort ();
    186         dumpElementln (Short.toString(field_count));
    187         ObjectStreamField[] fields = new ObjectStreamField[field_count];
    188 
    189         ObjectStreamClass osc = new ObjectStreamClass (name, uid,
    190                                                        flags, fields);
    191         assignNewHandle (osc);
    192 
    193         for (int i=0; i < field_count; i++)
    194         {
    195           dumpElement ("  TYPE CODE=");
    196           char type_code = (char)this.realInputStream.readByte ();
    197           dumpElement (type_code + "; FIELD NAME=");
    198           String field_name = this.realInputStream.readUTF ();
    199           dumpElementln (field_name);
    200           String class_name;
    201 
    202           if (type_code == 'L' || type_code == '[')
    203             class_name = (String)readObject ();
    204           else
    205             class_name = String.valueOf (type_code);
    206 
    207           fields[i] =
    208             new ObjectStreamField (field_name,
    209                                    TypeSignature.getClassForEncoding
    210                                    (class_name));
    211         }
    212 
    213         Class cl = resolveClass (osc);
    214         osc.setClass (cl);
    215         setBlockDataMode (false);
    216 
    217         if (this.realInputStream.readByte () != TC_ENDBLOCKDATA)
    218           throw new IOException ("Data annotated to class was not consumed.");
    219         dumpElementln ("ENDBLOCKDATA ");
    220 
    221         osc.setSuperclass ((ObjectStreamClass)readObject ());
    222         ret_val = osc;
    223         break;
    224       }
    225 
    226       case TC_STRING:
    227       {
    228         dumpElement ("STRING=");
    229         String s = this.realInputStream.readUTF ();
    230         dumpElementln (s);
    231         ret_val = processResolution (s, assignNewHandle (s));
    232         break;
    233       }
    234 
    235       case TC_ARRAY:
    236       {
    237         dumpElementln ("ARRAY");
    238         ObjectStreamClass osc = (ObjectStreamClass)readObject ();
    239         Class componentType = osc.forClass ().getComponentType ();
    240         dumpElement ("ARRAY LENGTH=");
    241         int length = this.realInputStream.readInt ();
    242         dumpElementln (length + "; COMPONENT TYPE=" + componentType);
    243         Object array = Array.newInstance (componentType, length);
    244         int handle = assignNewHandle (array);
    245         readArrayElements (array, componentType);
    246         for (int i=0, len=Array.getLength(array); i < len; i++)
    247           dumpElementln ("  ELEMENT[" + i + "]=" + Array.get(array, i).toString());
    248         ret_val = processResolution (array, handle);
    249         break;
    250       }
    251 
    252       case TC_OBJECT:
    253       {
    254         dumpElementln ("OBJECT");
    255         ObjectStreamClass osc = (ObjectStreamClass)readObject ();
    256         Class clazz = osc.forClass ();
    257 
    258         if (!Serializable.class.isAssignableFrom (clazz))
    259           throw new NotSerializableException (clazz + " is not Serializable, and thus cannot be deserialized.");
    260 
    261         if (Externalizable.class.isAssignableFrom (clazz))
    262         {
    263           Externalizable obj = null;
    264 
    265           try
    266           {
    267             obj = (Externalizable)clazz.newInstance ();
    268           }
    269           catch (InstantiationException e)
    270           {
    271             throw new ClassNotFoundException ("Instance of " + clazz
    272                                               + " could not be created");
    273           }
    274           catch (IllegalAccessException e)
    275           {
    276             throw new ClassNotFoundException ("Instance of " + clazz
    277                                               + " could not be created because class or zero-argument constructor is not accessible");
    278           }
    279           catch (NoSuchMethodError e)
    280           {
    281             throw new ClassNotFoundException ("Instance of " + clazz
    282                                               + " could not be created because zero-argument constructor is not defined");
    283           }
    284 
    285           int handle = assignNewHandle (obj);
    286 
    287           boolean read_from_blocks = ((osc.getFlags () & SC_BLOCK_DATA) != 0);
    288 
    289           if (read_from_blocks)
    290             setBlockDataMode (true);
    291 
    292           obj.readExternal (this);
    293 
    294           if (read_from_blocks)
    295             setBlockDataMode (false);
    296 
    297           ret_val = processResolution (obj, handle);
    298           break;
    299         } // end if (Externalizable.class.isAssignableFrom (clazz))
    300 
    301         // find the first non-serializable, non-abstract
    302         // class in clazz's inheritance hierarchy
    303         Class first_nonserial = clazz.getSuperclass ();
    304         while (Serializable.class.isAssignableFrom (first_nonserial)
    305                || Modifier.isAbstract (first_nonserial.getModifiers ()))
    306           first_nonserial = first_nonserial.getSuperclass ();
    307 
    308 //      DEBUGln ("Using " + first_nonserial
    309 //               + " as starting point for constructing " + clazz);
    310 
    311         Object obj = null;
    312         obj = newObject (clazz, first_nonserial);
    313 
    314         if (obj == null)
    315           throw new ClassNotFoundException ("Instance of " + clazz +
    316                                             " could not be created");
    317 
    318         int handle = assignNewHandle (obj);
    319         this.currentObject = obj;
    320         ObjectStreamClass[] hierarchy =
    321           ObjectStreamClass.getObjectStreamClasses (clazz);
    322 
    323 //      DEBUGln ("Got class hierarchy of depth " + hierarchy.length);
    324 
    325         boolean has_read;
    326         for (int i=0; i < hierarchy.length; i++)
    327         {
    328           this.currentObjectStreamClass = hierarchy[i];
    329 
    330           dumpElementln ("Reading fields of "
    331                    + this.currentObjectStreamClass.getName ());
    332 
    333           has_read = true;
    334 
    335           try
    336           {
    337             this.currentObjectStreamClass.forClass ().
    338               getDeclaredMethod ("readObject", readObjectParams);
    339           }
    340           catch (NoSuchMethodException e)
    341           {
    342             has_read = false;
    343           }
    344 
    345           // XXX: should initialize fields in classes in the hierarchy
    346           // that aren't in the stream
    347           // should skip over classes in the stream that aren't in the
    348           // real classes hierarchy
    349           readFields (obj, this.currentObjectStreamClass.fields,
    350                       has_read, this.currentObjectStreamClass);
    351 
    352           if (has_read)
    353           {
    354             dumpElement ("ENDBLOCKDATA? ");
    355             try
    356               {
    357                 // FIXME: XXX: This try block is to catch EOF which is
    358                 // thrown for some objects.  That indicates a bug in the logic.
    359                 if (this.realInputStream.readByte () != TC_ENDBLOCKDATA)
    360                   throw new IOException ("No end of block data seen for class with readObject (ObjectInputStream) method.");
    361                 dumpElementln ("yes");
    362               }
    363             catch (EOFException e)
    364               {
    365                 dumpElementln ("no, got EOFException");
    366               }
    367             catch (IOException e)
    368               {
    369                 dumpElementln ("no, got IOException");
    370               }
    371           }
    372         }
    373 
    374         this.currentObject = null;
    375         this.currentObjectStreamClass = null;
    376         ret_val = processResolution (obj, handle);
    377         break;
    378       }
    379 
    380       case TC_RESET:
    381         dumpElementln ("RESET");
    382         clearHandles ();
    383         ret_val = readObject ();
    384         break;
    385 
    386       case TC_EXCEPTION:
    387       {
    388         dumpElement ("EXCEPTION=");
    389         Exception e = (Exception)readObject ();
    390         dumpElementln (e.toString());
    391         clearHandles ();
    392         throw new WriteAbortedException ("Exception thrown during writing of stream", e);
    393       }
    394 
    395       default:
    396         throw new IOException ("Unknown marker on stream");
    397     }
    398 
    399     this.isDeserializing = was_deserializing;
    400 
    401     if (! was_deserializing)
    402     {
    403       setBlockDataMode (true);
    404 
    405       if (validators.size () > 0)
    406         invokeValidators ();
    407     }
    408 
     139    try
     140      {
     141        switch (marker)
     142          {
     143          case TC_ENDBLOCKDATA:
     144            {
     145              ret_val = null;
     146              is_consumed = true;
     147              break;
     148            }
     149
     150          case TC_BLOCKDATA:
     151          case TC_BLOCKDATALONG:
     152            {
     153              if (marker == TC_BLOCKDATALONG)
     154                dumpElementln ("BLOCKDATALONG");
     155              else
     156                dumpElementln ("BLOCKDATA");
     157              readNextBlock (marker);
     158              throw new StreamCorruptedException ("Unexpected blockData");
     159            }
     160
     161          case TC_NULL:
     162            {
     163              dumpElementln ("NULL");
     164              ret_val = null;
     165              break;
     166            }
     167
     168          case TC_REFERENCE:
     169            {
     170              dumpElement ("REFERENCE ");
     171              Integer oid = new Integer (this.realInputStream.readInt ());
     172              dumpElementln (Integer.toHexString(oid.intValue()));
     173              ret_val = ((ObjectIdentityWrapper)
     174                         this.objectLookupTable.get (oid)).object;
     175              break;
     176            }
     177
     178          case TC_CLASS:
     179            {
     180              dumpElementln ("CLASS");
     181              ObjectStreamClass osc = (ObjectStreamClass)readObject ();
     182              Class clazz = osc.forClass ();
     183              assignNewHandle (clazz);
     184              ret_val = clazz;
     185              break;
     186            }
     187
     188          case TC_PROXYCLASSDESC:
     189            {
     190              dumpElementln ("PROXYCLASS");
     191              int n_intf = this.realInputStream.readInt();
     192              String[] intfs = new String[n_intf];
     193              for (int i = 0; i < n_intf; i++)
     194                {
     195                  intfs[i] = this.realInputStream.readUTF();
     196                  System.out.println(intfs[i]);
     197                }
     198             
     199              boolean oldmode = setBlockDataMode (true);
     200              Class cl = resolveProxyClass(intfs);
     201              setBlockDataMode(oldmode);
     202             
     203              ObjectStreamClass osc = ObjectStreamClass.lookup(cl);
     204              assignNewHandle (osc);
     205             
     206              if (!is_consumed)
     207                {
     208                  byte b = this.realInputStream.readByte ();
     209                  if (b != TC_ENDBLOCKDATA)
     210                    throw new IOException ("Data annotated to class was not consumed." + b);
     211                }
     212              else
     213                is_consumed = false;
     214              ObjectStreamClass superosc = (ObjectStreamClass)readObject ();
     215              osc.setSuperclass (superosc);
     216              ret_val = osc;
     217              break;
     218            }
     219
     220          case TC_CLASSDESC:
     221            {
     222              dumpElement ("CLASSDESC NAME=");
     223              String name = this.realInputStream.readUTF ();
     224              dumpElement (name + "; UID=");
     225              long uid = this.realInputStream.readLong ();
     226              dumpElement (Long.toHexString(uid) + "; FLAGS=");
     227              byte flags = this.realInputStream.readByte ();
     228              dumpElement (Integer.toHexString(flags) + "; FIELD COUNT=");
     229              short field_count = this.realInputStream.readShort ();
     230              dumpElementln (Short.toString(field_count));
     231              ObjectStreamField[] fields = new ObjectStreamField[field_count];
     232              ObjectStreamClass osc = new ObjectStreamClass (name, uid,
     233                                                             flags, fields);
     234              assignNewHandle (osc);
     235             
     236              for (int i=0; i < field_count; i++)
     237                {
     238                  dumpElement ("  TYPE CODE=");
     239                  char type_code = (char)this.realInputStream.readByte ();
     240                  dumpElement (type_code + "; FIELD NAME=");
     241                  String field_name = this.realInputStream.readUTF ();
     242                  dumpElementln (field_name);
     243                  String class_name;
     244                 
     245                  if (type_code == 'L' || type_code == '[')
     246                    class_name = (String)readObject ();
     247                  else
     248                    class_name = String.valueOf (type_code);
     249                 
     250                  // There're many cases you can't get java.lang.Class from
     251                  // typename if your context class loader can't load it,
     252                  // then use typename to construct the field
     253                  fields[i] =
     254                    new ObjectStreamField (field_name, class_name);
     255                }
     256             
     257              boolean oldmode = setBlockDataMode (true);
     258              osc.setClass (resolveClass (osc));
     259              setBlockDataMode (oldmode);
     260             
     261              if (!is_consumed)
     262                {
     263                  byte b = this.realInputStream.readByte ();
     264                  if (b != TC_ENDBLOCKDATA)
     265                    throw new IOException ("Data annotated to class was not consumed." + b);
     266                }
     267              else
     268                is_consumed = false;
     269             
     270              osc.setSuperclass ((ObjectStreamClass)readObject ());
     271              ret_val = osc;
     272              break;
     273            }
     274
     275          case TC_STRING:
     276          case TC_LONGSTRING:
     277            {
     278              dumpElement ("STRING=");
     279              String s = this.realInputStream.readUTF ();
     280              dumpElementln (s);
     281              ret_val = processResolution (s, assignNewHandle (s));
     282              break;
     283            }
     284
     285          case TC_ARRAY:
     286            {
     287              dumpElementln ("ARRAY");
     288              ObjectStreamClass osc = (ObjectStreamClass)readObject ();
     289              Class componentType = osc.forClass ().getComponentType ();
     290              dumpElement ("ARRAY LENGTH=");
     291              int length = this.realInputStream.readInt ();
     292              dumpElementln (length + "; COMPONENT TYPE=" + componentType);
     293              Object array = Array.newInstance (componentType, length);
     294              int handle = assignNewHandle (array);
     295              readArrayElements (array, componentType);
     296              for (int i=0, len=Array.getLength(array); i < len; i++)
     297                dumpElementln ("  ELEMENT[" + i + "]=" + Array.get(array, i));
     298              ret_val = processResolution (array, handle);
     299              break;
     300            }
     301
     302          case TC_OBJECT:
     303            {
     304              dumpElementln ("OBJECT");
     305              ObjectStreamClass osc = (ObjectStreamClass)readObject ();
     306              Class clazz = osc.forClass ();
     307             
     308              if (!Serializable.class.isAssignableFrom (clazz))
     309                throw new NotSerializableException (clazz + " is not Serializable, and thus cannot be deserialized.");
     310             
     311              if (Externalizable.class.isAssignableFrom (clazz))
     312                {
     313                  Externalizable obj = null;
     314                 
     315                  try
     316                    {
     317                      obj = (Externalizable)clazz.newInstance ();
     318                    }
     319                  catch (InstantiationException e)
     320                    {
     321                      throw new ClassNotFoundException ("Instance of " + clazz
     322                                                        + " could not be created");
     323                    }
     324                  catch (IllegalAccessException e)
     325                    {
     326                      throw new ClassNotFoundException ("Instance of " + clazz
     327                                                        + " could not be created because class or zero-argument constructor is not accessible");
     328                    }
     329                  catch (NoSuchMethodError e)
     330                    {
     331                      throw new ClassNotFoundException ("Instance of " + clazz
     332                                                        + " could not be created because zero-argument constructor is not defined");
     333                    }
     334                 
     335                  int handle = assignNewHandle (obj);
     336                 
     337                  boolean read_from_blocks = ((osc.getFlags () & SC_BLOCK_DATA) != 0);
     338                 
     339                  boolean oldmode = this.readDataFromBlock;
     340                  if (read_from_blocks)
     341                    setBlockDataMode (true);
     342                 
     343                  obj.readExternal (this);
     344                 
     345                  if (read_from_blocks)
     346                    setBlockDataMode (oldmode);
     347                 
     348                  ret_val = processResolution (obj, handle);
     349                  break;
     350                } // end if (Externalizable.class.isAssignableFrom (clazz))
     351             
     352              // find the first non-serializable, non-abstract
     353              // class in clazz's inheritance hierarchy
     354              Class first_nonserial = clazz.getSuperclass ();
     355              while (Serializable.class.isAssignableFrom (first_nonserial)
     356                     || Modifier.isAbstract (first_nonserial.getModifiers ()))
     357                first_nonserial = first_nonserial.getSuperclass ();
     358             
     359              Object obj = null;
     360              obj = newObject (clazz, first_nonserial);
     361             
     362              if (obj == null)
     363                throw new ClassNotFoundException ("Instance of " + clazz +
     364                                                  " could not be created");
     365             
     366              int handle = assignNewHandle (obj);
     367              this.currentObject = obj;
     368              ObjectStreamClass[] hierarchy =
     369                ObjectStreamClass.getObjectStreamClasses (clazz);
     370             
     371              for (int i=0; i < hierarchy.length; i++)
     372                {
     373                  this.currentObjectStreamClass = hierarchy[i];
     374                 
     375                  dumpElementln ("Reading fields of "
     376                                 + this.currentObjectStreamClass.getName ());
     377
     378                  // XXX: should initialize fields in classes in the hierarchy
     379                  // that aren't in the stream
     380                  // should skip over classes in the stream that aren't in the
     381                  // real classes hierarchy
     382                 
     383                  if (this.currentObjectStreamClass.hasReadMethod())
     384                    {
     385                      fieldsAlreadyRead = false;
     386                      boolean oldmode = setBlockDataMode (true);
     387                      callReadMethod (obj, this.currentObjectStreamClass);
     388                      setBlockDataMode (oldmode);
     389                      dumpElement ("ENDBLOCKDATA? ");
     390                      try
     391                        {
     392                          // FIXME: XXX: This try block is to catch EOF which is
     393                          // thrown for some objects.  That indicates a bug in the logic.
     394                          if (this.realInputStream.readByte () != TC_ENDBLOCKDATA)
     395                            throw new IOException ("No end of block data seen for class with readObject (ObjectInputStream) method.");
     396                          dumpElementln ("yes");
     397                        }
     398                      catch (EOFException e)
     399                        {
     400                          dumpElementln ("no, got EOFException");
     401                        }
     402                      catch (IOException e)
     403                        {
     404                          dumpElementln ("no, got IOException");
     405                        }
     406                    }
     407                  else
     408                    {
     409                      readFields (obj, currentObjectStreamClass);
     410                    }
     411                }
     412
     413              this.currentObject = null;
     414              this.currentObjectStreamClass = null;
     415              ret_val = processResolution (obj, handle);
     416              break;
     417            }
     418
     419          case TC_RESET:
     420            dumpElementln ("RESET");
     421            clearHandles ();
     422            ret_val = readObject ();
     423            break;
     424
     425          case TC_EXCEPTION:
     426            {
     427              dumpElement ("EXCEPTION=");
     428              Exception e = (Exception)readObject ();
     429              dumpElementln (e.toString());
     430              clearHandles ();
     431              throw new WriteAbortedException ("Exception thrown during writing of stream", e);
     432            }
     433
     434          default:
     435            throw new IOException ("Unknown marker on stream: " + marker);
     436          }
     437      }
     438    finally
     439      {
     440        setBlockDataMode (old_mode);
     441       
     442        this.isDeserializing = was_deserializing;
     443       
     444        if (! was_deserializing)
     445          {
     446            if (validators.size () > 0)
     447              invokeValidators ();
     448          }
     449      }
     450   
    409451    return ret_val;
    410452  }
    411 
    412453
    413454  /**
     
    439480      throw new NotActiveException ("defaultReadObject called but fields already read from stream (by defaultReadObject or readFields)");
    440481
    441     readFields (this.currentObject,
    442                 this.currentObjectStreamClass.fields,
    443                 false, this.currentObjectStreamClass);
     482   
     483    readFields (this.currentObject, this.currentObjectStreamClass);
     484);
    444485
    445486    fieldsAlreadyRead = true;
     
    500541  {
    501542    SecurityManager sm = System.getSecurityManager ();
     543
     544
    502545
    503546    // FIXME: currentClassLoader doesn't yet do anything useful. We need
     
    506549    ClassLoader cl = currentClassLoader (sm);
    507550
    508     return Class.forName (osc.getName (), true, cl);
     551    if (cl == null)
     552      return Class.forName (osc.getName ());
     553    else
     554      return cl.loadClass (osc.getName ());
    509555  }
    510556
     
    528574
    529575
     576
     577
     578
     579
     580
     581
     582
     583
     584
     585
     586
     587
     588
     589
     590
     591
     592
     593
     594
     595
     596
     597
     598
     599
     600
     601
    530602  /**
    531603     If <code>enable</code> is <code>true</code> and this object is
     
    543615        SecurityManager sm = System.getSecurityManager ();
    544616        if (sm != null)
    545           sm.checkPermission (new SerializablePermission ("enableSubtitution"));
     617          sm.checkPermission (new SerializablePermission ("enableSubtitution"));
    546618      }
    547619
     
    577649  {
    578650    if (this.readDataFromBlock)
    579     {
    580       if (this.blockDataPosition >= this.blockDataBytes)
    581         readNextBlock ();
    582       return (this.blockData[this.blockDataPosition++] & 0xff);
    583     }
     651    {
     652if (this.blockDataPosition >= this.blockDataBytes)
     653        readNextBlock ();
     654return (this.blockData[this.blockDataPosition++] & 0xff);
     655    }
    584656    else
    585657      return this.realInputStream.read ();
     
    589661  {
    590662    if (this.readDataFromBlock)
    591     {
    592       if (this.blockDataPosition + length > this.blockDataBytes)
    593         readNextBlock ();
    594 
    595       System.arraycopy (this.blockData, this.blockDataPosition,
    596                         data, offset, length);
    597       blockDataPosition += length;     
    598 
    599       return length;
    600     }
     663      {
     664        if (this.blockDataPosition + length > this.blockDataBytes)
     665          {
     666            int remain = this.blockDataBytes - this.blockDataPosition;
     667            if (remain != 0)
     668              {
     669                System.arraycopy (this.blockData, this.blockDataPosition,
     670                                  data, offset, remain);
     671                offset += remain;
     672                length -= remain;
     673              }
     674            readNextBlock ();
     675          }
     676
     677        System.arraycopy (this.blockData, this.blockDataPosition,
     678                          data, offset, length);
     679        this.blockDataPosition += length;
     680
     681        return length;
     682      }
    601683    else
    602684      return this.realInputStream.read (data, offset, length);
     
    606688  {
    607689    if (this.readDataFromBlock)
    608     {
    609       if (this.blockDataPosition >= this.blockDataBytes)
    610         readNextBlock ();
    611 
    612       return this.blockDataBytes - this.blockDataPosition;
    613     }
     690    {
     691if (this.blockDataPosition >= this.blockDataBytes)
     692        readNextBlock ();
     693
     694return this.blockDataBytes - this.blockDataPosition;
     695    }
    614696    else
    615697      return this.realInputStream.available ();
     
    759841    // empirical evidence against JDK 1.2.  Also see Mauve test
    760842    // java.io.ObjectInputOutput.Test.GetPutField.
    761     setBlockDataMode (false);
     843    setBlockDataMode (false);
    762844    readFully (prim_field_data);
    763845    for (int i = 0; i < objs.length; ++ i)
    764846      objs[i] = readObject ();
    765     setBlockDataMode (true);
     847    setBlockDataMode (e);
    766848
    767849    return new GetField ()
    768     {
    769       public ObjectStreamClass getObjectStreamClass ()
    770       {
    771         return clazz;
    772       }
    773 
    774       public boolean defaulted (String name)
    775         throws IOException, IllegalArgumentException
    776       {
    777         return clazz.getField (name) == null;
    778       }
    779 
    780       public boolean get (String name, boolean defvalue)
    781         throws IOException, IllegalArgumentException
    782       {
    783         ObjectStreamField field = getField (name, Boolean.TYPE);
    784 
    785         if (field == null)
    786           return defvalue;
    787 
    788         return prim_field_data[field.getOffset ()] == 0 ? false : true;
    789       }
    790 
    791       public char get (String name, char defvalue)
    792         throws IOException, IllegalArgumentException
    793       {
    794         ObjectStreamField field = getField (name, Character.TYPE);
    795 
    796         if (field == null)
    797           return defvalue;
    798 
    799         int off = field.getOffset ();
    800 
    801         return (char)(((prim_field_data[off++] & 0xFF) << 8)
    802                       | (prim_field_data[off] & 0xFF));
    803       }
    804 
    805       public byte get (String name, byte defvalue)
    806         throws IOException, IllegalArgumentException
    807       {
    808         ObjectStreamField field = getField (name, Byte.TYPE);
    809 
    810         if (field == null)
    811           return defvalue;
    812 
    813         return prim_field_data[field.getOffset ()];
    814       }
    815 
    816       public short get (String name, short defvalue)
    817         throws IOException, IllegalArgumentException
    818       {
    819         ObjectStreamField field = getField (name, Short.TYPE);
    820 
    821         if (field == null)
    822           return defvalue;
    823 
    824         int off = field.getOffset ();
    825 
    826         return (short)(((prim_field_data[off++] & 0xFF) << 8)
    827                        | (prim_field_data[off] & 0xFF));
    828       }
    829 
    830       public int get (String name, int defvalue)
    831         throws IOException, IllegalArgumentException
    832       {
    833         ObjectStreamField field = getField (name, Integer.TYPE);
    834 
    835         if (field == null)
    836           return defvalue;
    837 
    838         int off = field.getOffset ();
    839 
    840         return ((prim_field_data[off++] & 0xFF) << 24)
    841           | ((prim_field_data[off++] & 0xFF) << 16)
    842           | ((prim_field_data[off++] & 0xFF) << 8)
    843           | (prim_field_data[off] & 0xFF);
    844       }
    845 
    846       public long get (String name, long defvalue)
    847         throws IOException, IllegalArgumentException
    848       {
    849         ObjectStreamField field = getField (name, Long.TYPE);
    850 
    851         if (field == null)
    852           return defvalue;
    853 
    854         int off = field.getOffset ();
    855 
    856         return (long)(((prim_field_data[off++] & 0xFF) << 56)
     850      {
     851        public ObjectStreamClass getObjectStreamClass ()
     852        {
     853          return clazz;
     854        }
     855
     856        public boolean defaulted (String name)
     857          throws IOException, IllegalArgumentException
     858        {
     859          return clazz.getField (name) == null;
     860        }
     861
     862        public boolean get (String name, boolean defvalue)
     863          throws IOException, IllegalArgumentException
     864        {
     865          ObjectStreamField field = getField (name, Boolean.TYPE);
     866
     867          if (field == null)
     868            return defvalue;
     869
     870          return prim_field_data[field.getOffset ()] == 0 ? false : true;
     871        }
     872
     873        public char get (String name, char defvalue)
     874          throws IOException, IllegalArgumentException
     875        {
     876          ObjectStreamField field = getField (name, Character.TYPE);
     877
     878          if (field == null)
     879            return defvalue;
     880
     881          int off = field.getOffset ();
     882
     883          return (char)(((prim_field_data[off++] & 0xFF) << 8)
     884                        | (prim_field_data[off] & 0xFF));
     885        }
     886
     887        public byte get (String name, byte defvalue)
     888          throws IOException, IllegalArgumentException
     889        {
     890          ObjectStreamField field = getField (name, Byte.TYPE);
     891
     892          if (field == null)
     893            return defvalue;
     894
     895          return prim_field_data[field.getOffset ()];
     896        }
     897
     898        public short get (String name, short defvalue)
     899          throws IOException, IllegalArgumentException
     900        {
     901          ObjectStreamField field = getField (name, Short.TYPE);
     902
     903          if (field == null)
     904            return defvalue;
     905
     906          int off = field.getOffset ();
     907
     908          return (short)(((prim_field_data[off++] & 0xFF) << 8)
     909                         | (prim_field_data[off] & 0xFF));
     910        }
     911
     912        public int get (String name, int defvalue)
     913          throws IOException, IllegalArgumentException
     914        {
     915          ObjectStreamField field = getField (name, Integer.TYPE);
     916
     917          if (field == null)
     918            return defvalue;
     919
     920          int off = field.getOffset ();
     921
     922          return ((prim_field_data[off++] & 0xFF) << 24)
     923            | ((prim_field_data[off++] & 0xFF) << 16)
     924            | ((prim_field_data[off++] & 0xFF) << 8)
     925            | (prim_field_data[off] & 0xFF);
     926        }
     927
     928        public long get (String name, long defvalue)
     929          throws IOException, IllegalArgumentException
     930        {
     931          ObjectStreamField field = getField (name, Long.TYPE);
     932
     933          if (field == null)
     934            return defvalue;
     935
     936          int off = field.getOffset ();
     937
     938          return (long)(((prim_field_data[off++] & 0xFF) << 56)
     939                        | ((prim_field_data[off++] & 0xFF) << 48)
     940                        | ((prim_field_data[off++] & 0xFF) << 40)
     941                        | ((prim_field_data[off++] & 0xFF) << 32)
     942                        | ((prim_field_data[off++] & 0xFF) << 24)
     943                        | ((prim_field_data[off++] & 0xFF) << 16)
     944                        | ((prim_field_data[off++] & 0xFF) << 8)
     945                        | (prim_field_data[off] & 0xFF));
     946        }
     947
     948        public float get (String name, float defvalue)
     949          throws IOException, IllegalArgumentException
     950        {
     951          ObjectStreamField field = getField (name, Float.TYPE);
     952
     953          if (field == null)
     954            return defvalue;
     955
     956          int off = field.getOffset ();
     957
     958          return Float.intBitsToFloat (((prim_field_data[off++] & 0xFF) << 24)
     959                                       | ((prim_field_data[off++] & 0xFF) << 16)
     960                                       | ((prim_field_data[off++] & 0xFF) << 8)
     961                                       | (prim_field_data[off] & 0xFF));
     962        }
     963
     964        public double get (String name, double defvalue)
     965          throws IOException, IllegalArgumentException
     966        {
     967          ObjectStreamField field = getField (name, Double.TYPE);
     968
     969          if (field == null)
     970            return defvalue;
     971
     972          int off = field.getOffset ();
     973
     974          return Double.longBitsToDouble
     975            ( (long) (((prim_field_data[off++] & 0xFF) << 56)
    857976                      | ((prim_field_data[off++] & 0xFF) << 48)
    858977                      | ((prim_field_data[off++] & 0xFF) << 40)
     
    861980                      | ((prim_field_data[off++] & 0xFF) << 16)
    862981                      | ((prim_field_data[off++] & 0xFF) << 8)
    863                       | (prim_field_data[off] & 0xFF));
    864       }
    865 
    866       public float get (String name, float defvalue)
    867         throws IOException, IllegalArgumentException
    868       {
    869         ObjectStreamField field = getField (name, Float.TYPE);
    870 
    871         if (field == null)
    872           return defvalue;
    873 
    874         int off = field.getOffset ();
    875 
    876         return Float.intBitsToFloat (((prim_field_data[off++] & 0xFF) << 24)
    877                                     | ((prim_field_data[off++] & 0xFF) << 16)
    878                                     | ((prim_field_data[off++] & 0xFF) << 8)
    879                                     | (prim_field_data[off] & 0xFF));
    880       }
    881 
    882       public double get (String name, double defvalue)
    883         throws IOException, IllegalArgumentException
    884       {
    885         ObjectStreamField field = getField (name, Double.TYPE);
    886 
    887         if (field == null)
    888           return defvalue;
    889 
    890         int off = field.getOffset ();
    891 
    892         return Double.longBitsToDouble (
    893           (long)(((prim_field_data[off++] & 0xFF) << 56)
    894                  | ((prim_field_data[off++] & 0xFF) << 48)
    895                  | ((prim_field_data[off++] & 0xFF) << 40)
    896                  | ((prim_field_data[off++] & 0xFF) << 32)
    897                  | ((prim_field_data[off++] & 0xFF) << 24)
    898                  | ((prim_field_data[off++] & 0xFF) << 16)
    899                  | ((prim_field_data[off++] & 0xFF) << 8)
    900                  | (prim_field_data[off] & 0xFF)));
    901       }
    902 
    903       public Object get (String name, Object defvalue)
    904         throws IOException, IllegalArgumentException
    905       {
    906         ObjectStreamField field =
    907           getField (name, defvalue == null ? null : defvalue.getClass ());
    908 
    909         if (field == null)
    910           return defvalue;
    911 
    912         return objs[field.getOffset ()];
    913       }
    914 
    915       private ObjectStreamField getField (String name, Class type)
    916         throws IllegalArgumentException
    917       {
    918         ObjectStreamField field = clazz.getField (name);
    919 
    920         if (field == null)
    921           return null;
    922 
    923         Class field_type = field.getType ();
    924 
    925         if (type == field_type ||
    926             (type == null && ! field_type.isPrimitive ()))
    927           return field;
    928 
    929         throw new IllegalArgumentException ("Field requested is of type "
    930                                             + field_type.getName ()
    931                                             + ", but requested type was "
    932                                             + (type == null ?
    933                                                "Object" : type.getName ()));
    934       }
    935     };
     982                      | (prim_field_data[off] & 0xFF)));
     983        }
     984
     985        public Object get (String name, Object defvalue)
     986          throws IOException, IllegalArgumentException
     987        {
     988          ObjectStreamField field =
     989            getField (name, defvalue == null ? null : defvalue.getClass ());
     990
     991          if (field == null)
     992            return defvalue;
     993
     994          return objs[field.getOffset ()];
     995        }
     996
     997        private ObjectStreamField getField (String name, Class type)
     998          throws IllegalArgumentException
     999        {
     1000          ObjectStreamField field = clazz.getField (name);
     1001
     1002          if (field == null)
     1003            return null;
     1004
     1005          Class field_type = field.getType ();
     1006
     1007          if (type == field_type ||
     1008              (type == null && ! field_type.isPrimitive ()))
     1009            return field;
     1010
     1011          throw new IllegalArgumentException ("Field requested is of type "
     1012                                              + field_type.getName ()
     1013                                              + ", but requested type was "
     1014                                              + (type == null ?
     1015                                                 "Object" : type.getName ()));
     1016        }
     1017      };
    9361018
    9371019  }
     
    9641046     <code>ObjectInputStream</code>.  To make this method be used for
    9651047     writing objects, subclasses must invoke the 0-argument
    966      constructor on this class from there constructor.
     1048     constructor on this class from the constructor.
    9671049
    9681050     @see ObjectInputStream ()
     
    9791061  {
    9801062    this.objectLookupTable.put (new Integer (this.nextOID),
    981                              new ObjectIdentityWrapper (obj));
    982 
    983 //    try
    984 //    {
    985 //      DEBUG ("Assigning handle " + this.nextOID);
    986 //      DEBUGln (" to " + obj);
    987 //    }
    988 //    catch (Throwable t) {}
    989 
     1063                                new ObjectIdentityWrapper (obj));
    9901064    return this.nextOID++;
    9911065  }
     
    9991073        Method m = null;
    10001074        try
    1001         {
    1002           Class classArgs[] = {};
    1003           m = obj.getClass ().getDeclaredMethod ("readResolve", classArgs);
    1004           // m can't be null by definition since an exception would
    1005           // have been thrown so a check for null is not needed.
    1006           obj = m.invoke (obj, new Object[] {});       
    1007         }
     1075        {
     1076          Class classArgs[] = {};
     1077          m = obj.getClass ().getDeclaredMethod ("readResolve", classArgs);
     1078          // m can't be null by definition since an exception would
     1079          // have been thrown so a check for null is not needed.
     1080          obj = m.invoke (obj, new Object[] {});     
     1081        }
    10081082        catch (NoSuchMethodException ignore)
    1009         {
    1010         }
     1083        {
     1084        }
    10111085        catch (IllegalAccessException ignore)
    1012         {
    1013         }
     1086        {
     1087        }
    10141088        catch (InvocationTargetException ignore)
    1015         {
    1016         }
     1089        {
     1090        }
    10171091      }
    10181092
     
    10361110  private void readNextBlock () throws IOException
    10371111  {
    1038 //  DEBUGln ("In readNextBlock ");
    10391112    readNextBlock (this.realInputStream.readByte ());
    10401113  }
     
    10441117  {
    10451118    if (marker == TC_BLOCKDATA)
    1046     {
    1047       dumpElement ("BLOCK DATA SIZE=");
    1048       this.blockDataBytes = this.realInputStream.readUnsignedByte ();
    1049       dumpElementln (Integer.toString(this.blockDataBytes));
    1050     }
     1119    {
     1120dumpElement ("BLOCK DATA SIZE=");
     1121this.blockDataBytes = this.realInputStream.readUnsignedByte ();
     1122dumpElementln (Integer.toString(this.blockDataBytes));
     1123    }
    10511124    else if (marker == TC_BLOCKDATALONG)
    1052     {
    1053       dumpElement ("BLOCK DATA LONG SIZE=");
    1054       this.blockDataBytes = this.realInputStream.readInt ();
    1055       dumpElementln (Integer.toString(this.blockDataBytes));
    1056     }
     1125    {
     1126dumpElement ("BLOCK DATA LONG SIZE=");
     1127this.blockDataBytes = this.realInputStream.readInt ();
     1128dumpElementln (Integer.toString(this.blockDataBytes));
     1129    }
    10571130    else
    1058     {
    1059       throw new EOFException ("Attempt to read primitive data, but no data block is active.");
    1060     }
     1131    {
     1132throw new EOFException ("Attempt to read primitive data, but no data block is active.");
     1133    }
    10611134
    10621135    if (this.blockData.length < this.blockDataBytes)
     
    10721145  {
    10731146    if (clazz.isPrimitive ())
    1074     {
    1075       if (clazz == Boolean.TYPE)
    1076       {
    1077         boolean[] cast_array = (boolean[])array;
     1147      {
     1148        if (clazz == Boolean.TYPE)
     1149          {
     1150            boolean[] cast_array = (boolean[])array;
     1151            for (int i=0; i < cast_array.length; i++)
     1152              cast_array[i] = this.realInputStream.readBoolean ();
     1153            return;
     1154          }
     1155        if (clazz == Byte.TYPE)
     1156          {
     1157            byte[] cast_array = (byte[])array;
     1158            for (int i=0; i < cast_array.length; i++)
     1159              cast_array[i] = this.realInputStream.readByte ();
     1160            return;
     1161          }
     1162        if (clazz == Character.TYPE)
     1163          {
     1164            char[] cast_array = (char[])array;
     1165            for (int i=0; i < cast_array.length; i++)
     1166              cast_array[i] = this.realInputStream.readChar ();
     1167            return;
     1168          }
     1169        if (clazz == Double.TYPE)
     1170          {
     1171            double[] cast_array = (double[])array;
     1172            for (int i=0; i < cast_array.length; i++)
     1173              cast_array[i] = this.realInputStream.readDouble ();
     1174            return;
     1175          }
     1176        if (clazz == Float.TYPE)
     1177          {
     1178            float[] cast_array = (float[])array;
     1179            for (int i=0; i < cast_array.length; i++)
     1180              cast_array[i] = this.realInputStream.readFloat ();
     1181            return;
     1182          }
     1183        if (clazz == Integer.TYPE)
     1184          {
     1185            int[] cast_array = (int[])array;
     1186            for (int i=0; i < cast_array.length; i++)
     1187              cast_array[i] = this.realInputStream.readInt ();
     1188            return;
     1189          }
     1190        if (clazz == Long.TYPE)
     1191          {
     1192            long[] cast_array = (long[])array;
     1193            for (int i=0; i < cast_array.length; i++)
     1194              cast_array[i] = this.realInputStream.readLong ();
     1195            return;
     1196          }
     1197        if (clazz == Short.TYPE)
     1198          {
     1199            short[] cast_array = (short[])array;
     1200            for (int i=0; i < cast_array.length; i++)
     1201              cast_array[i] = this.realInputStream.readShort ();
     1202            return;
     1203          }
     1204      }
     1205    else
     1206      {
     1207        Object[] cast_array = (Object[])array;
    10781208        for (int i=0; i < cast_array.length; i++)
    1079           cast_array[i] = this.realInputStream.readBoolean ();
    1080         return;
    1081       }
    1082       if (clazz == Byte.TYPE)
    1083       {
    1084         byte[] cast_array = (byte[])array;
    1085         for (int i=0; i < cast_array.length; i++)
    1086           cast_array[i] = this.realInputStream.readByte ();
    1087         return;
    1088       }
    1089       if (clazz == Character.TYPE)
    1090       {
    1091         char[] cast_array = (char[])array;
    1092         for (int i=0; i < cast_array.length; i++)
    1093           cast_array[i] = this.realInputStream.readChar ();
    1094         return;
    1095       }
    1096       if (clazz == Double.TYPE)
    1097       {
    1098         double[] cast_array = (double[])array;
    1099         for (int i=0; i < cast_array.length; i++)
    1100           cast_array[i] = this.realInputStream.readDouble ();
    1101         return;
    1102       }
    1103       if (clazz == Float.TYPE)
    1104       {
    1105         float[] cast_array = (float[])array;
    1106         for (int i=0; i < cast_array.length; i++)
    1107           cast_array[i] = this.realInputStream.readFloat ();
    1108         return;
    1109       }
    1110       if (clazz == Integer.TYPE)
    1111       {
    1112         int[] cast_array = (int[])array;
    1113         for (int i=0; i < cast_array.length; i++)
    1114           cast_array[i] = this.realInputStream.readInt ();
    1115         return;
    1116       }
    1117       if (clazz == Long.TYPE)
    1118       {
    1119         long[] cast_array = (long[])array;
    1120         for (int i=0; i < cast_array.length; i++)
    1121           cast_array[i] = this.realInputStream.readLong ();
    1122         return;
    1123       }
    1124       if (clazz == Short.TYPE)
    1125       {
    1126         short[] cast_array = (short[])array;
    1127         for (int i=0; i < cast_array.length; i++)
    1128           cast_array[i] = this.realInputStream.readShort ();
    1129         return;
    1130       }
    1131     }
    1132     else
    1133     {
    1134       Object[] cast_array = (Object[])array;
    1135       for (int i=0; i < cast_array.length; i++)
    11361209          cast_array[i] = readObject ();
    1137     }
    1138   }
    1139 
    1140 
    1141   private void readFields (Object obj, ObjectStreamField[] stream_fields,
    1142                            boolean call_read_method,
    1143                            ObjectStreamClass stream_osc)
     1210      }
     1211  }
     1212
     1213
     1214  private void readFields (Object obj, ObjectStreamClass stream_osc)
    11441215    throws ClassNotFoundException, IOException
    11451216  {
    1146 //  DEBUGln ("In readFields");
    1147     if (call_read_method)
    1148     {
    1149 //    DEBUGln ("  call_read_method is true");
    1150       fieldsAlreadyRead = false;
    1151       setBlockDataMode (true);
    1152       callReadMethod (obj, stream_osc.forClass ());
    1153       setBlockDataMode (false);
    1154       return;
    1155     }
    1156 
     1217    ObjectStreamField[] stream_fields = stream_osc.fields;
    11571218    ObjectStreamField[] real_fields =
    11581219      ObjectStreamClass.lookup (stream_osc.forClass ()).fields;
     
    11681229    while (stream_idx < stream_fields.length
    11691230           && real_idx < real_fields.length)
    1170     {
    1171       default_initialize = false;
    1172       set_value = true;
    1173 
    1174       if (stream_idx == stream_fields.length)
    1175         default_initialize = true;
    1176       else
    1177       {
    1178         stream_field = stream_fields[stream_idx];
    1179         type = stream_field.getType ();
    1180       }
    1181 
    1182       if (real_idx == real_fields.length)
    1183         set_value = false;
    1184       else
    1185       {
    1186         real_field = real_fields[real_idx];
    1187         type = real_field.getType ();
    1188         field_name = real_field.getName ();
    1189       }
    1190 
    1191       if (set_value && !default_initialize)
    1192       {
    1193         int comp_val =
    1194           real_field.compareTo (stream_field);
    1195 
    1196         if (comp_val < 0)
    1197         {
     1231      {
     1232        default_initialize = false;
     1233        set_value = true;
     1234
     1235        if (stream_idx == stream_fields.length)
    11981236          default_initialize = true;
    1199           real_idx++;
    1200         }
    1201         else if (comp_val > 0)
    1202         {
     1237        else
     1238          {
     1239            stream_field = stream_fields[stream_idx];
     1240            type = stream_field.getType ();
     1241          }
     1242
     1243        if (real_idx == real_fields.length)
    12031244          set_value = false;
    1204           stream_idx++;
    1205         }
    12061245        else
    1207         {
    1208           real_idx++;
    1209           stream_idx++;
    1210         }
    1211       }
    1212 
    1213       if (type == Boolean.TYPE)
    1214       {
    1215         boolean value =
    1216           default_initialize ? false : this.realInputStream.readBoolean ();
    1217         if (!default_initialize && set_value)
    1218           dumpElementln ("  " + field_name + ": " + value);
    1219         if (set_value)
    1220           setBooleanField (obj, field_name, value);
    1221       }
    1222       else if (type == Byte.TYPE)
    1223       {
    1224         byte value =
    1225           default_initialize ? 0 : this.realInputStream.readByte ();
    1226         if (!default_initialize && set_value)
    1227           dumpElementln ("  " + field_name + ": " + value);
    1228         if (set_value)
    1229           setByteField (obj, field_name, value);
    1230       }
    1231       else if (type == Character.TYPE)
    1232       {
    1233         char value =
    1234           default_initialize ? (char)0 : this.realInputStream.readChar ();
    1235         if (!default_initialize && set_value)
    1236           dumpElementln ("  " + field_name + ": " + value);
    1237         if (set_value)
    1238           setCharField (obj, field_name, value);
    1239       }
    1240       else if (type == Double.TYPE)
    1241       {
    1242         double value =
    1243           default_initialize ? 0 : this.realInputStream.readDouble ();
    1244         if (!default_initialize && set_value)
    1245           dumpElementln ("  " + field_name + ": " + value);
    1246         if (set_value)
    1247           setDoubleField (obj, field_name, value);
    1248       }
    1249       else if (type == Float.TYPE)
    1250       {
    1251         float value =
    1252           default_initialize ? 0 : this.realInputStream.readFloat ();
    1253         if (!default_initialize && set_value)
    1254           dumpElementln ("  " + field_name + ": " + value);
    1255         if (set_value)
    1256           setFloatField (obj, field_name, value);
    1257       }
    1258       else if (type == Integer.TYPE)
    1259       {
    1260         int value =
    1261           default_initialize ? 0 : this.realInputStream.readInt ();
    1262         if (!default_initialize && set_value)
    1263           dumpElementln ("  " + field_name + ": " + value);
    1264         if (set_value)
    1265           setIntField (obj, field_name, value);
    1266       }
    1267       else if (type == Long.TYPE)
    1268       {
    1269         long value =
    1270           default_initialize ? 0 : this.realInputStream.readLong ();
    1271         if (!default_initialize && set_value)
    1272           dumpElementln ("  " + field_name + ": " + value);
    1273         if (set_value)
    1274           setLongField (obj, field_name, value);
    1275       }
    1276       else if (type == Short.TYPE)
    1277       {
    1278         short value =
    1279           default_initialize ? (short)0 : this.realInputStream.readShort ();
    1280         if (!default_initialize && set_value)
    1281           dumpElementln ("  " + field_name + ": " + value);
    1282         if (set_value)
    1283           setShortField (obj, field_name, value);
    1284       }
    1285       else
    1286       {
    1287         Object value =
    1288           default_initialize ? null : readObject ();
    1289         if (set_value)
    1290           setObjectField (obj, field_name,
    1291                           real_field.getTypeString (), value);
    1292       }
    1293     }
    1294   }
    1295 
     1246          {
     1247            real_field = real_fields[real_idx];
     1248            type = real_field.getType ();
     1249            field_name = real_field.getName ();
     1250          }
     1251
     1252        if (set_value && !default_initialize)
     1253          {
     1254            int comp_val =
     1255              real_field.compareTo (stream_field);
     1256
     1257            if (comp_val < 0)
     1258              {
     1259                default_initialize = true;
     1260                real_idx++;
     1261              }
     1262            else if (comp_val > 0)
     1263              {
     1264                set_value = false;
     1265                stream_idx++;
     1266              }
     1267            else
     1268              {
     1269                real_idx++;
     1270                stream_idx++;
     1271              }
     1272          }
     1273
     1274        try
     1275          {
     1276            if (type == Boolean.TYPE)
     1277              {
     1278                boolean value =
     1279                  default_initialize ? false : this.realInputStream.readBoolean ();
     1280                if (!default_initialize && set_value)
     1281                  dumpElementln ("  " + field_name + ": " + value);
     1282                if (set_value)
     1283                  setBooleanField (obj, stream_osc.forClass (), field_name, value);
     1284              }
     1285            else if (type == Byte.TYPE)
     1286              {
     1287                byte value =
     1288                  default_initialize ? 0 : this.realInputStream.readByte ();
     1289                if (!default_initialize && set_value)
     1290                  dumpElementln ("  " + field_name + ": " + value);
     1291                if (set_value)
     1292                  setByteField (obj, stream_osc.forClass (), field_name, value);
     1293              }
     1294            else if (type == Character.TYPE)
     1295              {
     1296                char value =
     1297                  default_initialize ? (char)0 : this.realInputStream.readChar ();
     1298                if (!default_initialize && set_value)
     1299                  dumpElementln ("  " + field_name + ": " + value);
     1300                if (set_value)
     1301                  setCharField (obj, stream_osc.forClass (), field_name, value);
     1302              }
     1303            else if (type == Double.TYPE)
     1304              {
     1305                double value =
     1306                  default_initialize ? 0 : this.realInputStream.readDouble ();
     1307                if (!default_initialize && set_value)
     1308                  dumpElementln ("  " + field_name + ": " + value);
     1309                if (set_value)
     1310                  setDoubleField (obj, stream_osc.forClass (), field_name, value);
     1311              }
     1312            else if (type == Float.TYPE)
     1313              {
     1314                float value =
     1315                  default_initialize ? 0 : this.realInputStream.readFloat ();
     1316                if (!default_initialize && set_value)
     1317                  dumpElementln ("  " + field_name + ": " + value);
     1318                if (set_value)
     1319                  setFloatField (obj, stream_osc.forClass (), field_name, value);
     1320              }
     1321            else if (type == Integer.TYPE)
     1322              {
     1323                int value =
     1324                  default_initialize ? 0 : this.realInputStream.readInt ();
     1325                if (!default_initialize && set_value)
     1326                  dumpElementln ("  " + field_name + ": " + value);
     1327                if (set_value)
     1328                  setIntField (obj, stream_osc.forClass (), field_name, value);
     1329              }
     1330            else if (type == Long.TYPE)
     1331              {
     1332                long value =
     1333                  default_initialize ? 0 : this.realInputStream.readLong ();
     1334                if (!default_initialize && set_value)
     1335                  dumpElementln ("  " + field_name + ": " + value);
     1336                if (set_value)
     1337                  setLongField (obj, stream_osc.forClass (), field_name, value);
     1338              }
     1339            else if (type == Short.TYPE)
     1340              {
     1341                short value =
     1342                  default_initialize ? (short)0 : this.realInputStream.readShort ();
     1343                if (!default_initialize && set_value)
     1344                  dumpElementln ("  " + field_name + ": " + value);
     1345                if (set_value)
     1346                  setShortField (obj, stream_osc.forClass (), field_name, value);
     1347              }
     1348            else
     1349              {
     1350                Object value =
     1351                  default_initialize ? null : readObject ();
     1352                if (set_value)
     1353                  setObjectField (obj, stream_osc.forClass (), field_name,
     1354                                  real_field.getTypeString (), value);
     1355              }
     1356          }
     1357        catch (NoSuchFieldError e)
     1358          {
     1359            dumpElementln("XXXX " + field_name + " does not exist.");
     1360          }
     1361      }
     1362  }
    12961363
    12971364  // Toggles writing primitive data to block-data buffer.
    1298   private void setBlockDataMode (boolean on)
    1299   {
    1300 //    DEBUGln ("Setting block data mode to " + on);
    1301 
     1365  private boolean setBlockDataMode (boolean on)
     1366  {
     1367    boolean oldmode = this.readDataFromBlock;
    13021368    this.readDataFromBlock = on;
    13031369
     
    13061372    else
    13071373      this.dataInputStream = this.realInputStream;
     1374
    13081375  }
    13091376
     
    13141381  {
    13151382    try
    1316     {
    1317       Object obj = allocateObject (real_class);
    1318       callConstructor (constructor_class, obj);
    1319       return obj;
    1320     }
     1383    {
     1384Object obj = allocateObject (real_class);
     1385callConstructor (constructor_class, obj);
     1386return obj;
     1387    }
    13211388    catch (InstantiationException e)
    1322     {
    1323       return null;
    1324     }
     1389    {
     1390return null;
     1391    }
    13251392  }
    13261393
     
    13351402
    13361403    try
    1337     {
    1338       for (int i=0; i < validators.length; i++)
    1339         ((ObjectInputValidation)validators[i]).validateObject ();
    1340     }
     1404    {
     1405for (int i=0; i < validators.length; i++)
     1406        ((ObjectInputValidation)validators[i]).validateObject ();
     1407    }
    13411408    finally
    1342     {
    1343       this.validators.removeAllElements ();
    1344     }
     1409    {
     1410this.validators.removeAllElements ();
     1411    }
    13451412  }
    13461413
     
    13541421  }
    13551422
    1356   private static native Field getField (Class klass, String name)
    1357     throws java.lang.NoSuchFieldException;
    1358 
    1359   private static native Method getMethod (Class klass, String name, Class args[])
    1360     throws java.lang.NoSuchMethodException;
    1361 
    1362   private void callReadMethod (Object obj, Class klass) throws IOException
    1363   {
     1423  private static Field getField (Class klass, String name)
     1424    throws java.lang.NoSuchFieldException
     1425  {
     1426    return klass.getDeclaredField(name);
     1427  }
     1428
     1429  private static Method getMethod (Class klass, String name, Class args[])
     1430    throws java.lang.NoSuchMethodException
     1431  {
     1432    return klass.getDeclaredMethod(name, args);
     1433  }
     1434
     1435  private void callReadMethod (Object obj, ObjectStreamClass osc) throws IOException
     1436  {
     1437    Class klass = osc.forClass();
    13641438    try
    13651439      {
     
    13951469  private native void callConstructor (Class clazz, Object obj);
    13961470
    1397   private void setBooleanField (Object obj, String field_name,
     1471  private void setBooleanField (Object obj, String field_name,
    13981472                                boolean val)
    13991473  {
    14001474    try
    14011475      {
    1402         Class klass = obj.getClass ();
    14031476        Field f = getField (klass, field_name);
     1477
    14041478        f.setBoolean (obj, val);
    14051479      }
     
    14091483  }
    14101484
    1411   private void setByteField (Object obj, String field_name,
    1412                                 byte val)
     1485  private void setByteField (Object obj, String field_name,
     1486                        byte val)
    14131487  {
    14141488    try
    14151489      {
    1416         Class klass = obj.getClass ();
    14171490        Field f = getField (klass, field_name);
     1491
    14181492        f.setByte (obj, val);
    14191493      }
     
    14231497  }
    14241498
    1425   private void setCharField (Object obj, String field_name,
     1499  private void setCharField (Object obj, String field_name,
    14261500                             char val)
    14271501  {
    14281502    try
    14291503      {
    1430         Class klass = obj.getClass ();
    14311504        Field f = getField (klass, field_name);
     1505
    14321506        f.setChar (obj, val);
    14331507      }
     
    14371511  }
    14381512
    1439   private void setDoubleField (Object obj, String field_name,
     1513  private void setDoubleField (Object obj, String field_name,
    14401514                               double val)
    14411515  {
    14421516    try
    14431517      {
    1444         Class klass = obj.getClass ();
    14451518        Field f = getField (klass, field_name);
     1519
    14461520        f.setDouble (obj, val);
    14471521      }
     
    14511525  }
    14521526
    1453   private void setFloatField (Object obj, String field_name,
     1527  private void setFloatField (Object obj, String field_name,
    14541528                              float val)
    14551529  {
    14561530    try
    14571531      {
    1458         Class klass = obj.getClass ();
    14591532        Field f = getField (klass, field_name);
     1533
    14601534        f.setFloat (obj, val);
    14611535      }
     
    14651539  }
    14661540
    1467   private void setIntField (Object obj, String field_name,
    1468                               int val)
     1541  private void setIntField (Object obj, String field_name,
     1542                            int val)
    14691543  {
    14701544    try
    14711545      {
    1472         Class klass = obj.getClass ();
    14731546        Field f = getField (klass, field_name);
     1547
    14741548        f.setInt (obj, val);
    14751549      }
     
    14801554
    14811555
    1482   private void setLongField (Object obj, String field_name,
    1483                               long val)
     1556  private void setLongField (Object obj, String field_name,
     1557                             long val)
    14841558  {
    14851559    try
    14861560      {
    1487         Class klass = obj.getClass ();
    14881561        Field f = getField (klass, field_name);
     1562
    14891563        f.setLong (obj, val);
    14901564      }
     
    14951569
    14961570
    1497   private void setShortField (Object obj, String field_name,
     1571  private void setShortField (Object obj, String field_name,
    14981572                              short val)
    14991573  {
    15001574    try
    15011575      {
    1502         Class klass = obj.getClass ();
    15031576        Field f = getField (klass, field_name);
     1577
    15041578        f.setShort (obj, val);
    15051579      }
     
    15101584
    15111585
    1512   private void setObjectField (Object obj, String field_name, String type_code,
     1586  private void setObjectField (Object obj, String field_name, String type_code,
    15131587                               Object val)
    15141588  {
    15151589    try
    15161590      {
    1517         Class klass = obj.getClass ();
    15181591        Field f = getField (klass, field_name);
     1592
    15191593        // FIXME: We should check the type_code here
    15201594        f.set (obj, val);
     
    15451619  private Vector validators;
    15461620
    1547   private static boolean dump; 
     1621  private static boolean dump;
    15481622
    15491623  private void dumpElement (String msg)
     
    15571631    if (Configuration.DEBUG && dump)
    15581632      System.out.println(msg);
     1633
     1634
     1635
     1636
     1637
     1638
     1639
     1640
    15591641  }
    15601642}
Note: See TracChangeset for help on using the changeset viewer.