if (osc.isEnum()) {  realOutput.writeByte(TC_ENUM); writeObject(osc); assignNewHandle(obj); writeObject(((Enum) obj).name()); break; }
  public final void writeObject(Object obj) throws IOException  {    if (useSubclassMethod)      {	if (dump)	  dumpElementln ("WRITE OVERRIDE: " + obj);	  	writeObjectOverride(obj);	return;      }    if (dump)      dumpElementln ("WRITE: " + obj);        depth += 2;        boolean was_serializing = isSerializing;    boolean old_mode = setBlockDataMode(false);    try      {	isSerializing = true;	boolean replaceDone = false;	Object replacedObject = null;		while (true)	  {	    if (obj == null)	      {		realOutput.writeByte(TC_NULL);		break;	      }	    Integer handle = findHandle(obj);	    if (handle != null)	      {		realOutput.writeByte(TC_REFERENCE);		realOutput.writeInt(handle.intValue());		break;	      }	    if (obj instanceof Class)	      {		Class cl = (Class)obj;		ObjectStreamClass osc = ObjectStreamClass.lookupForClassObject(cl);		realOutput.writeByte(TC_CLASS);		if (!osc.isProxyClass)		  {		    writeObject (osc);		  }		else		  {		    realOutput.writeByte(TC_PROXYCLASSDESC);		    Class[] intfs = cl.getInterfaces();		    realOutput.writeInt(intfs.length);		    for (int i = 0; i < intfs.length; i++)		      realOutput.writeUTF(intfs[i].getName());		    		    boolean oldmode = setBlockDataMode(true);		    annotateProxyClass(cl);		    setBlockDataMode(oldmode);		    realOutput.writeByte(TC_ENDBLOCKDATA);		    		    writeObject(osc.getSuper());		  }		assignNewHandle(obj);		break;	      }	    if (obj instanceof ObjectStreamClass)	      {		writeClassDescriptor((ObjectStreamClass) obj);		break;	      }	    Class clazz = obj.getClass();	    ObjectStreamClass osc = ObjectStreamClass.lookupForClassObject(clazz);	    if (osc == null)	      throw new NotSerializableException(clazz.getName());	    	    if ((replacementEnabled || obj instanceof Serializable)		&& ! replaceDone)	      {		replacedObject = obj;				if (obj instanceof Serializable)		  {		    try		      {                        Method m = osc.writeReplaceMethod;                        if (m != null)                            obj = m.invoke(obj, new Object[0]);		      }		    catch (IllegalAccessException ignore)		      {		      }		    catch (InvocationTargetException ignore)		      {		      }		  }				if (replacementEnabled)		  obj = replaceObject(obj);				replaceDone = true;		continue;	      }	    if (obj instanceof String)	      {		realOutput.writeByte(TC_STRING);		assignNewHandle(obj);		realOutput.writeUTF((String)obj);		break;	      }	    if (clazz.isArray ())	      {		realOutput.writeByte(TC_ARRAY);		writeObject(osc);		assignNewHandle(obj);		writeArraySizeAndElements(obj, clazz.getComponentType());		break;	      }	    	    realOutput.writeByte(TC_OBJECT);	    writeObject(osc);	    if (replaceDone)	      assignNewHandle(replacedObject);	    else	      assignNewHandle(obj);	    if (obj instanceof Externalizable)	      {		if (protocolVersion == PROTOCOL_VERSION_2)		  setBlockDataMode(true);				((Externalizable)obj).writeExternal(this);				if (protocolVersion == PROTOCOL_VERSION_2)		  {		    setBlockDataMode(false);		    realOutput.writeByte(TC_ENDBLOCKDATA);		  }		break;	      }	    if (obj instanceof Serializable)	      {		Object prevObject = this.currentObject;		ObjectStreamClass prevObjectStreamClass = this.currentObjectStreamClass;		currentObject = obj;		ObjectStreamClass[] hierarchy =		  ObjectStreamClass.getObjectStreamClasses(clazz);				for (int i = 0; i < hierarchy.length; i++)		  {		    currentObjectStreamClass = hierarchy[i];		    		    fieldsAlreadyWritten = false;		    if (currentObjectStreamClass.hasWriteMethod())		      {			if (dump)			  dumpElementln ("WRITE METHOD CALLED FOR: " + obj);			setBlockDataMode(true);			callWriteMethod(obj, currentObjectStreamClass);			setBlockDataMode(false);			realOutput.writeByte(TC_ENDBLOCKDATA);			if (dump)			  dumpElementln ("WRITE ENDBLOCKDATA FOR: " + obj);		      }		    else		      {			if (dump)			  dumpElementln ("WRITE FIELDS CALLED FOR: " + obj);			writeFields(obj, currentObjectStreamClass);		      }		  }		this.currentObject = prevObject;		this.currentObjectStreamClass = prevObjectStreamClass;		currentPutField = null;		break;	      }	    throw new NotSerializableException(clazz.getName()					       + " in "					       + obj.getClass());	  } // end pseudo-loop      }    catch (ObjectStreamException ose)      {	// Rethrow these are fatal.	throw ose;      }    catch (IOException e)      {	realOutput.writeByte(TC_EXCEPTION);	reset(true);	setBlockDataMode(false);	try	  {	    if (DEBUG)	      {		e.printStackTrace(System.out);	      }	    writeObject(e);	  }	catch (IOException ioe)	  {	    StreamCorruptedException ex = 	      new StreamCorruptedException	      (ioe + " thrown while exception was being written to stream.");	    if (DEBUG)	      {		ex.printStackTrace(System.out);	      }	    throw ex;	  }	reset (true);	      }    finally      {	isSerializing = was_serializing;	setBlockDataMode(old_mode);	depth -= 2;	if (dump)	  dumpElementln ("END: " + obj);      }  }