/[classpath]/classpath/java/io/ObjectOutputStream.java
ViewVC logotype

Diff of /classpath/java/io/ObjectOutputStream.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.46.2.4 by gnu_andrew, Sun Jan 16 02:14:48 2005 UTC revision 1.46.2.5 by gnu_andrew, Sun Jan 16 15:15:11 2005 UTC
# Line 256  public class ObjectOutputStream extends Line 256  public class ObjectOutputStream extends
256                  break;                  break;
257                }                }
258    
259                Class clazz = obj.getClass();
260                ObjectStreamClass osc = ObjectStreamClass.lookupForClassObject(clazz);
261                if (osc == null)
262                  throw new NotSerializableException(clazz.getName());
263                
264              if ((replacementEnabled || obj instanceof Serializable)              if ((replacementEnabled || obj instanceof Serializable)
265                  && ! replaceDone)                  && ! replaceDone)
266                {                {
# Line 263  public class ObjectOutputStream extends Line 268  public class ObjectOutputStream extends
268                                    
269                  if (obj instanceof Serializable)                  if (obj instanceof Serializable)
270                    {                    {
                     Method m = null;  
271                      try                      try
272                        {                        {
273                          Class classArgs[] = {};                          Method m = osc.writeReplaceMethod;
274                          m = getMethod(obj.getClass(), "writeReplace",                          if (m != null)
275                                        classArgs);                              obj = m.invoke(obj, new Object[0]);
                         // m can't be null by definition since an  
                         // exception would have been thrown so a check  
                         // for null is not needed.  
                         obj = m.invoke(obj, new Object[] {});  
                       }  
                     catch (NoSuchMethodException ignore)  
                       {  
276                        }                        }
277                      catch (IllegalAccessException ignore)                      catch (IllegalAccessException ignore)
278                        {                        {
# Line 300  public class ObjectOutputStream extends Line 297  public class ObjectOutputStream extends
297                  break;                  break;
298                }                }
299    
             Class clazz = obj.getClass();  
             ObjectStreamClass osc = ObjectStreamClass.lookupForClassObject(clazz);  
             if (osc == null)  
               throw new NotSerializableException(clazz.getName());  
               
300              if (clazz.isArray ())              if (clazz.isArray ())
301                {                {
302                  realOutput.writeByte(TC_ARRAY);                  realOutput.writeByte(TC_ARRAY);
# Line 1267  public class ObjectOutputStream extends Line 1259  public class ObjectOutputStream extends
1259    private void callWriteMethod(Object obj, ObjectStreamClass osc)    private void callWriteMethod(Object obj, ObjectStreamClass osc)
1260      throws IOException      throws IOException
1261    {    {
     Class klass = osc.forClass();  
1262      currentPutField = null;      currentPutField = null;
1263      try      try
1264        {        {
1265          Class classArgs[] = {ObjectOutputStream.class};          Object args[] = {this};
1266          Method m = getMethod(klass, "writeObject", classArgs);          osc.writeObjectMethod.invoke(obj, args);
         Object args[] = {this};  
         m.invoke(obj, args);      
       }  
     catch (NoSuchMethodException nsme)  
       {  
         // Nothing.  
1267        }        }
1268      catch (InvocationTargetException x)      catch (InvocationTargetException x)
1269        {        {
# Line 1289  public class ObjectOutputStream extends Line 1274  public class ObjectOutputStream extends
1274          if (exception instanceof IOException)          if (exception instanceof IOException)
1275            throw (IOException) exception;            throw (IOException) exception;
1276    
1277          IOException ioe          IOException ioe
1278            = new IOException("Exception thrown from writeObject() on " +            = new IOException("Exception thrown from writeObject() on " +
1279                              klass + ": " + exception.getClass().getName());                              osc.forClass().getName() + ": " +
1280                                exception.getClass().getName());
1281          ioe.initCause(exception);          ioe.initCause(exception);
1282          throw ioe;          throw ioe;
1283        }        }
# Line 1299  public class ObjectOutputStream extends Line 1285  public class ObjectOutputStream extends
1285        {        {
1286          IOException ioe          IOException ioe
1287            = new IOException("Failure invoking writeObject() on " +            = new IOException("Failure invoking writeObject() on " +
1288                              klass + ": " + x.getClass().getName());                              osc.forClass().getName() + ": " +
1289                                x.getClass().getName());
1290          ioe.initCause(x);          ioe.initCause(x);
1291          throw ioe;          throw ioe;
1292        }        }
# Line 1541  public class ObjectOutputStream extends Line 1528  public class ObjectOutputStream extends
1528        }        }
1529    }    }
1530    
   private Method getMethod (Class klass, String name, Class[] args)  
     throws java.lang.NoSuchMethodException  
   {  
     final Method m = klass.getDeclaredMethod(name, args);  
     setAccessible.setMember(m);  
     AccessController.doPrivileged(setAccessible);  
     return m;  
   }  
   
1531    private void dumpElementln (String msg)    private void dumpElementln (String msg)
1532    {    {
1533      for (int i = 0; i < depth; i++)      for (int i = 0; i < depth; i++)

Legend:
Removed from v.1.46.2.4  
changed lines
  Added in v.1.46.2.5

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26