protected void writeClassDescriptor(ObjectStreamClass desc) throws IOException {
   Class cl = desc.forClass();
   if (ProxyFactory.isProxyClass(cl)) {
     writeBoolean(true);
     Class superClass = cl.getSuperclass();
     Class[] interfaces = cl.getInterfaces();
     byte[] signature = ProxyFactory.getFilterSignature(cl);
     String name = superClass.getName();
     writeObject(name);
     // we don't write the marker interface ProxyObject
     writeInt(interfaces.length - 1);
     for (int i = 0; i < interfaces.length; i++) {
       Class interfaze = interfaces[i];
       if (interfaze != ProxyObject.class && interfaze != Proxy.class) {
         name = interfaces[i].getName();
         writeObject(name);
       }
     }
     writeInt(signature.length);
     write(signature);
   } else {
     writeBoolean(false);
     super.writeClassDescriptor(desc);
   }
 }
  /**
   * Converts a proxy object to an object that is writable to an object stream. This method is
   * called by <code>writeReplace()</code> in a proxy class.
   *
   * @since 3.4
   */
  public static SerializedProxy makeSerializedProxy(Object proxy)
      throws java.io.InvalidClassException {
    Class clazz = proxy.getClass();

    MethodHandler methodHandler = null;
    if (proxy instanceof ProxyObject) methodHandler = ((ProxyObject) proxy).getHandler();
    else if (proxy instanceof Proxy) methodHandler = ProxyFactory.getHandler((Proxy) proxy);

    return new SerializedProxy(clazz, ProxyFactory.getFilterSignature(clazz), methodHandler);
  }