home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &n…he Search for Life DVD 2 / DVD-ROM.iso / install / jre1_3 / lib / rt.jar / java / io / ObjectOutputStream.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  15.2 KB  |  1,024 lines

  1. package java.io;
  2.  
  3. import java.lang.reflect.InvocationTargetException;
  4.  
  5. public class ObjectOutputStream extends OutputStream implements ObjectOutput, ObjectStreamConstants {
  6.    private boolean blockDataMode;
  7.    private byte[] buf;
  8.    private int count;
  9.    private OutputStream out;
  10.    private DataOutputStream dos;
  11.    private IOException abortIOException = null;
  12.    private HandleTable handleTable;
  13.    private Object currentObject;
  14.    private ObjectStreamClass currentClassDesc;
  15.    private Stack classDescStack;
  16.    private PutField currentPutFields;
  17.    private Object[] writeObjectArglist = new Object[]{this};
  18.    private static final int INITIAL_BUFFER_SIZE = 64;
  19.    private byte[] data;
  20.    private static final int CDATA_MAX_LEN = 1024;
  21.    private char[] cdata;
  22.    boolean enableReplace;
  23.    private Object[] replaceObjects;
  24.    private int nextReplaceOffset;
  25.    private static final boolean REPLACEABLE = true;
  26.    private static final boolean NOT_REPLACEABLE = false;
  27.    private int recursionDepth = 0;
  28.    boolean useDeprecatedExternalizableFormat = false;
  29.    private boolean enableSubclassImplementation;
  30.    // $FF: synthetic field
  31.    static Class class$java$lang$String;
  32.  
  33.    public ObjectOutputStream(OutputStream var1) throws IOException {
  34.       this.enableSubclassImplementation = false;
  35.       this.out = var1;
  36.       this.dos = new DataOutputStream(this);
  37.       this.buf = new byte[1024];
  38.       this.writeStreamHeader();
  39.       this.resetStream();
  40.    }
  41.  
  42.    protected ObjectOutputStream() throws IOException, SecurityException {
  43.       SecurityManager var1 = System.getSecurityManager();
  44.       if (var1 != null) {
  45.          var1.checkPermission(ObjectStreamConstants.SUBCLASS_IMPLEMENTATION_PERMISSION);
  46.       }
  47.  
  48.       this.enableSubclassImplementation = true;
  49.    }
  50.  
  51.    protected void writeObjectOverride(Object var1) throws IOException {
  52.    }
  53.  
  54.    public void useProtocolVersion(int var1) throws IOException {
  55.       if (this.handleTable.size() != 0) {
  56.          throw new IllegalStateException("Must call useProtocolVersion before writing any objects to the stream");
  57.       } else {
  58.          switch (var1) {
  59.             case 1:
  60.                this.useDeprecatedExternalizableFormat = true;
  61.             case 2:
  62.                return;
  63.             default:
  64.                throw new IllegalArgumentException("unknown version:" + var1);
  65.          }
  66.       }
  67.    }
  68.  
  69.    public final void writeObject(Object var1) throws IOException {
  70.       if (this.enableSubclassImplementation) {
  71.          this.writeObjectOverride(var1);
  72.       } else {
  73.          Object var2 = this.currentObject;
  74.          ObjectStreamClass var3 = this.currentClassDesc;
  75.          boolean var4 = this.setBlockData(false);
  76.          ++this.recursionDepth;
  77.  
  78.          try {
  79.             if (this.serializeNullAndRepeat(var1, true)) {
  80.                return;
  81.             }
  82.  
  83.             if (this.checkSpecialClasses(var1)) {
  84.                return;
  85.             }
  86.  
  87.             Class var17 = var1.getClass();
  88.             Class var6 = null;
  89.             Object var7 = var1;
  90.             this.currentClassDesc = ObjectStreamClass.lookupInternal(var17);
  91.  
  92.             while(this.currentClassDesc != null && this.currentClassDesc.isReplaceable() && var17 != var6) {
  93.                var7 = ObjectStreamClass.invokeMethod(this.currentClassDesc.writeReplaceMethod, var7, (Object[])null);
  94.                var6 = var17;
  95.                if (var7 != null) {
  96.                   var17 = var7.getClass();
  97.                   this.currentClassDesc = ObjectStreamClass.lookupInternal(var17);
  98.                } else {
  99.                   var17 = null;
  100.                   this.currentClassDesc = null;
  101.                }
  102.             }
  103.  
  104.             if (this.enableReplace) {
  105.                var7 = this.replaceObject(var7);
  106.                this.currentClassDesc = var7 != null ? ObjectStreamClass.lookupInternal(var7.getClass()) : null;
  107.             }
  108.  
  109.             if (var1 != var7) {
  110.                if (var7 != null && !(var7 instanceof Serializable)) {
  111.                   String var8 = var7.getClass().getName();
  112.                   throw new NotSerializableException(var8);
  113.                }
  114.  
  115.                if (this.serializeNullAndRepeat(var7, true)) {
  116.                   this.addReplacement(var1, var7);
  117.                   return;
  118.                }
  119.  
  120.                this.addReplacement(var1, var7);
  121.                if (this.checkSpecialClasses(var7)) {
  122.                   return;
  123.                }
  124.  
  125.                var1 = var7;
  126.             }
  127.  
  128.             if (this.checkSubstitutableSpecialClasses(var1, this.currentClassDesc.forClass())) {
  129.                return;
  130.             }
  131.  
  132.             this.outputObject(var1);
  133.          } catch (IOException var15) {
  134.             IOException var5 = var15;
  135.             if (this.abortIOException == null) {
  136.                try {
  137.                   this.setBlockData(false);
  138.                   this.writeCode(123);
  139.                   this.resetStream();
  140.                   this.setBlockData(false);
  141.                   this.currentClassDesc = ObjectStreamClass.lookupInternal(var5.getClass());
  142.                   this.outputObject(var5);
  143.                   this.resetStream();
  144.                   this.abortIOException = var5;
  145.                } catch (IOException var14) {
  146.                   this.abortIOException = new StreamCorruptedException(((Throwable)var14).getMessage());
  147.                }
  148.             }
  149.          } finally {
  150.             --this.recursionDepth;
  151.             this.currentObject = var2;
  152.             this.currentClassDesc = var3;
  153.             this.setBlockData(var4);
  154.          }
  155.  
  156.          IOException var18 = this.abortIOException;
  157.          if (this.recursionDepth == 0) {
  158.             this.abortIOException = null;
  159.          }
  160.  
  161.          if (var18 != null) {
  162.             throw var18;
  163.          }
  164.       }
  165.    }
  166.  
  167.    private boolean checkSpecialClasses(Object var1) throws IOException {
  168.       if (var1 instanceof Class) {
  169.          this.outputClass((Class)var1);
  170.          return true;
  171.       } else if (var1 instanceof ObjectStreamClass) {
  172.          this.outputClassDescriptor((ObjectStreamClass)var1);
  173.          return true;
  174.       } else {
  175.          return false;
  176.       }
  177.    }
  178.  
  179.    private boolean checkSubstitutableSpecialClasses(Object var1, Class var2) throws IOException {
  180.       if (var2 == (class$java$lang$String == null ? (class$java$lang$String = class$("java.lang.String")) : class$java$lang$String)) {
  181.          this.outputString((String)var1);
  182.          return true;
  183.       } else if (var2.isArray()) {
  184.          this.outputArray(var1);
  185.          return true;
  186.       } else {
  187.          return false;
  188.       }
  189.    }
  190.  
  191.    public void defaultWriteObject() throws IOException {
  192.       if (this.currentObject != null && this.currentClassDesc != null) {
  193.          ObjectStreamField[] var1 = this.currentClassDesc.getFieldsNoCopy();
  194.          if (var1.length > 0) {
  195.             boolean var2 = this.setBlockData(false);
  196.             this.outputClassFields(this.currentObject, this.currentClassDesc.forClass(), var1);
  197.             this.setBlockData(var2);
  198.          }
  199.  
  200.       } else {
  201.          throw new NotActiveException("defaultWriteObject");
  202.       }
  203.    }
  204.  
  205.    public PutField putFields() throws IOException {
  206.       if (this.currentObject != null && this.currentClassDesc != null) {
  207.          this.currentPutFields = new PutFieldImpl(this.currentClassDesc);
  208.          return this.currentPutFields;
  209.       } else {
  210.          throw new NotActiveException("putFields");
  211.       }
  212.    }
  213.  
  214.    public void writeFields() throws IOException {
  215.       if (this.currentObject != null && this.currentClassDesc != null && this.currentPutFields != null) {
  216.          boolean var1 = this.setBlockData(false);
  217.          this.currentPutFields.write(this);
  218.          this.setBlockData(var1);
  219.       } else {
  220.          throw new NotActiveException("writeFields");
  221.       }
  222.    }
  223.  
  224.    public void reset() throws IOException {
  225.       if (this.currentObject == null && this.currentClassDesc == null) {
  226.          this.setBlockData(false);
  227.          this.writeCode(121);
  228.          this.resetStream();
  229.          this.abortIOException = null;
  230.       } else {
  231.          throw new IOException("Illegal call to reset");
  232.       }
  233.    }
  234.  
  235.    private void resetStream() throws IOException {
  236.       if (this.handleTable == null) {
  237.          this.handleTable = new HandleTable();
  238.       } else {
  239.          this.handleTable.clear();
  240.       }
  241.  
  242.       if (this.classDescStack == null) {
  243.          this.classDescStack = new Stack((1)null);
  244.       } else {
  245.          this.classDescStack.setSize(0);
  246.       }
  247.  
  248.       for(int var1 = 0; var1 < this.nextReplaceOffset; ++var1) {
  249.          this.replaceObjects[var1] = null;
  250.       }
  251.  
  252.       this.nextReplaceOffset = 0;
  253.       this.setBlockData(true);
  254.    }
  255.  
  256.    protected void annotateClass(Class var1) throws IOException {
  257.    }
  258.  
  259.    protected void annotateProxyClass(Class var1) throws IOException {
  260.    }
  261.  
  262.    protected Object replaceObject(Object var1) throws IOException {
  263.       return var1;
  264.    }
  265.  
  266.    protected boolean enableReplaceObject(boolean var1) throws SecurityException {
  267.       boolean var2 = this.enableReplace;
  268.       if (var1) {
  269.          SecurityManager var3 = System.getSecurityManager();
  270.          if (var3 != null) {
  271.             var3.checkPermission(ObjectStreamConstants.SUBSTITUTION_PERMISSION);
  272.          }
  273.  
  274.          this.enableReplace = true;
  275.       } else {
  276.          this.enableReplace = false;
  277.       }
  278.  
  279.       return var2;
  280.    }
  281.  
  282.    protected void writeStreamHeader() throws IOException {
  283.       this.writeShort(-21267);
  284.       this.writeShort(5);
  285.    }
  286.  
  287.    private void outputString(String var1) throws IOException {
  288.       int var4 = var1.length();
  289.       this.handleTable.assignWireOffset(var1);
  290.       if (this.cdata != null && this.cdata.length >= var4) {
  291.          var1.getChars(0, var4, this.cdata, 0);
  292.       } else {
  293.          this.cdata = var1.toCharArray();
  294.       }
  295.  
  296.       long var2 = getUTFLength(this.cdata, var4);
  297.       if (var2 <= 65535L) {
  298.          this.writeCode(116);
  299.          this.writeShort((int)var2);
  300.       } else {
  301.          this.writeCode(124);
  302.          this.writeLong(var2);
  303.       }
  304.  
  305.       this.writeUTFBody(this.cdata, var4);
  306.       if (var4 > 1024) {
  307.          this.cdata = null;
  308.       }
  309.  
  310.    }
  311.  
  312.    private static long getUTFLength(char[] var0, int var1) {
  313.       long var2 = 0L;
  314.  
  315.       for(int var4 = 0; var4 < var1; ++var4) {
  316.          char var5 = var0[var4];
  317.          if (var5 >= 1 && var5 <= 127) {
  318.             ++var2;
  319.          } else if (var5 > 2047) {
  320.             var2 += 3L;
  321.          } else {
  322.             var2 += 2L;
  323.          }
  324.       }
  325.  
  326.       return var2;
  327.    }
  328.  
  329.    private void writeUTFBody(char[] var1, int var2) throws IOException {
  330.       int var4 = this.buf.length - 2;
  331.  
  332.       for(int var6 = 0; var6 < var2; ++var6) {
  333.          char var5 = var1[var6];
  334.          if (this.count >= var4) {
  335.             if (this.blockDataMode) {
  336.                if (var5 >= 1 && var5 <= 127) {
  337.                   this.write(var5);
  338.                } else if (var5 > 2047) {
  339.                   this.write(224 | var5 >> 12 & 15);
  340.                   this.write(128 | var5 >> 6 & 63);
  341.                   this.write(128 | var5 >> 0 & 63);
  342.                } else {
  343.                   this.write(192 | var5 >> 6 & 31);
  344.                   this.write(128 | var5 >> 0 & 63);
  345.                }
  346.                continue;
  347.             }
  348.  
  349.             this.drain();
  350.          }
  351.  
  352.          if (var5 >= 1 && var5 <= 127) {
  353.             this.buf[this.count++] = (byte)var5;
  354.          } else if (var5 > 2047) {
  355.             this.buf[this.count++] = (byte)(224 | var5 >> 12 & 15);
  356.             this.buf[this.count++] = (byte)(128 | var5 >> 6 & 63);
  357.             this.buf[this.count++] = (byte)(128 | var5 >> 0 & 63);
  358.          } else {
  359.             this.buf[this.count++] = (byte)(192 | var5 >> 6 & 31);
  360.             this.buf[this.count++] = (byte)(128 | var5 >> 0 & 63);
  361.          }
  362.       }
  363.  
  364.    }
  365.  
  366.    private void outputClass(Class var1) throws IOException {
  367.       this.writeCode(118);
  368.       ObjectStreamClass var2 = ObjectStreamClass.lookupInternal(var1);
  369.       if (var2 == null) {
  370.          throw new NotSerializableException(var1.getName());
  371.       } else {
  372.          this.outputClassDescriptor(var2);
  373.          this.handleTable.assignWireOffset(var1);
  374.       }
  375.    }
  376.  
  377.    private void writeClassDescriptor0(ObjectStreamClass var1) throws IOException {
  378.       this.writeUTF(var1.getName());
  379.       this.writeLong(var1.getSerialVersionUID());
  380.       var1.write(this);
  381.    }
  382.  
  383.    protected void writeClassDescriptor(ObjectStreamClass var1) throws IOException {
  384.       this.writeClassDescriptor0(var1);
  385.    }
  386.  
  387.    private void outputClassDescriptor(ObjectStreamClass var1) throws IOException {
  388.       if (!this.serializeNullAndRepeat(var1, false)) {
  389.          Class var2 = var1.forClass();
  390.          if (!var1.forProxyClass) {
  391.             this.writeCode(114);
  392.             this.handleTable.assignWireOffset(var1);
  393.             if (this.useDeprecatedExternalizableFormat) {
  394.                this.writeClassDescriptor0(var1);
  395.             } else {
  396.                this.writeClassDescriptor(var1);
  397.             }
  398.  
  399.             boolean var3 = this.setBlockData(true);
  400.             this.annotateClass(var2);
  401.             this.setBlockData(var3);
  402.             this.writeCode(120);
  403.             ObjectStreamClass var4 = var1.getSuperclass();
  404.             this.outputClassDescriptor(var4);
  405.          } else {
  406.             this.writeCode(125);
  407.             this.handleTable.assignWireOffset(var1);
  408.             Class[] var6 = var2.getInterfaces();
  409.             this.writeInt(var6.length);
  410.  
  411.             for(int var7 = 0; var7 < var6.length; ++var7) {
  412.                this.writeUTF(var6[var7].getName());
  413.             }
  414.  
  415.             boolean var5 = this.setBlockData(true);
  416.             this.annotateProxyClass(var2);
  417.             this.setBlockData(var5);
  418.             this.writeCode(120);
  419.             this.outputClassDescriptor(var1.getSuperclass());
  420.          }
  421.  
  422.       }
  423.    }
  424.  
  425.    private void outputArray(Object var1) throws IOException {
  426.       Class var2 = this.currentClassDesc.forClass();
  427.       this.writeCode(117);
  428.       this.outputClassDescriptor(this.currentClassDesc);
  429.       this.handleTable.assignWireOffset(var1);
  430.       Class var6 = var2.getComponentType();
  431.       if (var6.isPrimitive()) {
  432.          if (var6 == Integer.TYPE) {
  433.             int[] var7 = (int[])var1;
  434.             int var4 = var7.length;
  435.             int var5 = this.buf.length - 4;
  436.             this.writeInt(var4);
  437.  
  438.             for(int var3 = 0; var3 < var4; ++var3) {
  439.                if (this.count > var5) {
  440.                   this.drain();
  441.                }
  442.  
  443.                int var8 = var7[var3];
  444.                this.buf[this.count++] = (byte)(var8 >>> 24);
  445.                this.buf[this.count++] = (byte)(var8 >>> 16);
  446.                this.buf[this.count++] = (byte)(var8 >>> 8);
  447.                this.buf[this.count++] = (byte)(var8 >>> 0);
  448.             }
  449.          } else if (var6 == Byte.TYPE) {
  450.             byte[] var28 = (byte[])var1;
  451.             int var16 = var28.length;
  452.             this.writeInt(var16);
  453.             this.writeInternal(var28, 0, var16, true);
  454.          } else if (var6 == Long.TYPE) {
  455.             long[] var29 = (long[])var1;
  456.             int var17 = var29.length;
  457.             int var24 = this.buf.length - 8;
  458.             this.writeInt(var17);
  459.  
  460.             for(int var11 = 0; var11 < var17; ++var11) {
  461.                if (this.count > var24) {
  462.                   this.drain();
  463.                }
  464.  
  465.                long var36 = var29[var11];
  466.                this.buf[this.count++] = (byte)((int)(var36 >>> 56));
  467.                this.buf[this.count++] = (byte)((int)(var36 >>> 48));
  468.                this.buf[this.count++] = (byte)((int)(var36 >>> 40));
  469.                this.buf[this.count++] = (byte)((int)(var36 >>> 32));
  470.                this.buf[this.count++] = (byte)((int)(var36 >>> 24));
  471.                this.buf[this.count++] = (byte)((int)(var36 >>> 16));
  472.                this.buf[this.count++] = (byte)((int)(var36 >>> 8));
  473.                this.buf[this.count++] = (byte)((int)(var36 >>> 0));
  474.             }
  475.          } else if (var6 == Float.TYPE) {
  476.             float[] var30 = (float[])var1;
  477.             int var18 = var30.length;
  478.             this.writeInt(var18);
  479.             int var37 = 0;
  480.  
  481.             while(var18 > 0) {
  482.                int var9 = this.buf.length - this.count >> 2;
  483.                if (var9 > 0) {
  484.                   int var10 = var18 < var9 ? var18 : var9;
  485.                   floatsToBytes(var30, var37, this.buf, this.count, var10);
  486.                   var37 += var10;
  487.                   var18 -= var10;
  488.                   this.count += var10 << 2;
  489.                } else {
  490.                   this.drain();
  491.                }
  492.             }
  493.          } else if (var6 == Double.TYPE) {
  494.             double[] var31 = (double[])var1;
  495.             int var19 = var31.length;
  496.             this.writeInt(var19);
  497.             int var38 = 0;
  498.  
  499.             while(var19 > 0) {
  500.                int var41 = this.buf.length - this.count >> 3;
  501.                if (var41 > 0) {
  502.                   int var42 = var19 < var41 ? var19 : var41;
  503.                   doublesToBytes(var31, var38, this.buf, this.count, var42);
  504.                   var38 += var42;
  505.                   var19 -= var42;
  506.                   this.count += var42 << 3;
  507.                } else {
  508.                   this.drain();
  509.                }
  510.             }
  511.          } else if (var6 == Short.TYPE) {
  512.             short[] var32 = (short[])var1;
  513.             int var20 = var32.length;
  514.             int var25 = this.buf.length - 2;
  515.             this.writeInt(var20);
  516.  
  517.             for(int var12 = 0; var12 < var20; ++var12) {
  518.                if (this.count > var25) {
  519.                   this.drain();
  520.                }
  521.  
  522.                short var39 = var32[var12];
  523.                this.buf[this.count++] = (byte)(var39 >>> 8);
  524.                this.buf[this.count++] = (byte)(var39 >>> 0);
  525.             }
  526.          } else if (var6 == Character.TYPE) {
  527.             char[] var33 = (char[])var1;
  528.             int var21 = var33.length;
  529.             int var26 = this.buf.length - 2;
  530.             this.writeInt(var21);
  531.  
  532.             for(int var13 = 0; var13 < var21; ++var13) {
  533.                if (this.count > var26) {
  534.                   this.drain();
  535.                }
  536.  
  537.                char var40 = var33[var13];
  538.                this.buf[this.count++] = (byte)(var40 >>> 8);
  539.                this.buf[this.count++] = (byte)(var40 >>> 0);
  540.             }
  541.          } else {
  542.             if (var6 != Boolean.TYPE) {
  543.                throw new InvalidClassException(var2.getName());
  544.             }
  545.  
  546.             boolean[] var34 = (boolean[])var1;
  547.             int var22 = var34.length;
  548.             int var27 = this.buf.length - 1;
  549.             this.writeInt(var22);
  550.  
  551.             for(int var14 = 0; var14 < var22; ++var14) {
  552.                if (this.count > var27) {
  553.                   this.drain();
  554.                }
  555.  
  556.                this.buf[this.count++] = (byte)(var34[var14] ? 1 : 0);
  557.             }
  558.          }
  559.       } else {
  560.          Object[] var35 = var1;
  561.          int var23 = var35.length;
  562.          this.writeInt(var23);
  563.  
  564.          for(int var15 = 0; var15 < var23; ++var15) {
  565.             this.writeObject(var35[var15]);
  566.          }
  567.       }
  568.  
  569.    }
  570.  
  571.    private static native void floatsToBytes(float[] var0, int var1, byte[] var2, int var3, int var4);
  572.  
  573.    private static native void doublesToBytes(double[] var0, int var1, byte[] var2, int var3, int var4);
  574.  
  575.    void writeTypeString(String var1) throws IOException {
  576.       int var2 = this.handleTable.findWireOffset(var1);
  577.       if (var2 >= 0) {
  578.          this.writeCode(113);
  579.          this.writeInt(var2 + 8257536);
  580.       } else {
  581.          this.handleTable.assignWireOffset(var1);
  582.          this.writeCode(116);
  583.          this.writeUTF(var1);
  584.       }
  585.  
  586.    }
  587.  
  588.    private void outputObject(Object var1) throws IOException {
  589.       this.currentObject = var1;
  590.       if (this.currentClassDesc.isNonSerializable()) {
  591.          throw new NotSerializableException(this.currentClassDesc.getName());
  592.       } else {
  593.          this.writeCode(115);
  594.          this.outputClassDescriptor(this.currentClassDesc);
  595.          this.handleTable.assignWireOffset(var1);
  596.          if (this.currentClassDesc.isExternalizable()) {
  597.             Externalizable var2 = (Externalizable)var1;
  598.             if (this.useDeprecatedExternalizableFormat) {
  599.                var2.writeExternal(this);
  600.             } else {
  601.                this.setBlockData(true);
  602.  
  603.                try {
  604.                   var2.writeExternal(this);
  605.                } finally {
  606.                   this.setBlockData(false);
  607.                   this.writeCode(120);
  608.                }
  609.             }
  610.          } else {
  611.             int var13 = this.classDescStack.size();
  612.  
  613.             try {
  614.                ObjectStreamClass var3;
  615.                while((var3 = this.currentClassDesc.getSuperclass()) != null) {
  616.                   this.classDescStack.push(this.currentClassDesc);
  617.                   this.currentClassDesc = var3;
  618.                }
  619.  
  620.                do {
  621.                   if (this.currentClassDesc.hasWriteObject()) {
  622.                      this.setBlockData(true);
  623.                      this.invokeObjectWriter(var1);
  624.                      this.setBlockData(false);
  625.                      this.writeCode(120);
  626.                   } else {
  627.                      this.defaultWriteObject();
  628.                   }
  629.                } while(this.classDescStack.size() > var13 && (this.currentClassDesc = (ObjectStreamClass)this.classDescStack.pop()) != null);
  630.             } finally {
  631.                this.classDescStack.setSize(var13);
  632.             }
  633.          }
  634.  
  635.       }
  636.    }
  637.  
  638.    private Object lookupReplace(Object var1) {
  639.       for(int var2 = 0; var2 < this.nextReplaceOffset; var2 += 2) {
  640.          if (this.replaceObjects[var2] == var1) {
  641.             return this.replaceObjects[var2 + 1];
  642.          }
  643.       }
  644.  
  645.       return var1;
  646.    }
  647.  
  648.    private boolean serializeNullAndRepeat(Object var1, boolean var2) throws IOException {
  649.       if (var1 == null) {
  650.          this.writeCode(112);
  651.          return true;
  652.       } else {
  653.          if (var2 && this.replaceObjects != null) {
  654.             var1 = this.lookupReplace(var1);
  655.          }
  656.  
  657.          int var3 = this.handleTable.findWireOffset(var1);
  658.          if (var3 >= 0) {
  659.             this.writeCode(113);
  660.             this.writeInt(var3 + 8257536);
  661.             return true;
  662.          } else {
  663.             return false;
  664.          }
  665.       }
  666.    }
  667.  
  668.    private void addReplacement(Object var1, Object var2) {
  669.       if (this.replaceObjects == null) {
  670.          this.replaceObjects = new Object[10];
  671.       }
  672.  
  673.       if (this.nextReplaceOffset == this.replaceObjects.length) {
  674.          Object[] var3 = this.replaceObjects;
  675.          this.replaceObjects = new Object[2 + this.nextReplaceOffset * 2];
  676.          System.arraycopy(var3, 0, this.replaceObjects, 0, this.nextReplaceOffset);
  677.       }
  678.  
  679.       this.replaceObjects[this.nextReplaceOffset++] = var1;
  680.       this.replaceObjects[this.nextReplaceOffset++] = var2;
  681.    }
  682.  
  683.    private void writeCode(int var1) throws IOException {
  684.       this.writeByte(var1);
  685.    }
  686.  
  687.    public void write(int var1) throws IOException {
  688.       if (this.count >= this.buf.length) {
  689.          this.drain();
  690.       }
  691.  
  692.       this.buf[this.count++] = (byte)var1;
  693.    }
  694.  
  695.    public void write(byte[] var1) throws IOException {
  696.       this.write(var1, 0, var1.length);
  697.    }
  698.  
  699.    private void writeInternal(byte[] var1, int var2, int var3, boolean var4) throws IOException {
  700.       if (var3 >= 0 && var2 >= 0 && var2 + var3 <= var1.length) {
  701.          if (var3 != 0) {
  702.             if (this.blockDataMode) {
  703.                this.writeCanonical(var1, var2, var3);
  704.             } else {
  705.                int var5 = this.buf.length - this.count;
  706.                if (var3 <= var5) {
  707.                   System.arraycopy(var1, var2, this.buf, this.count, var3);
  708.                   this.count += var3;
  709.                } else if (var4) {
  710.                   this.bufferedWrite(var1, var2, var3);
  711.                } else {
  712.                   this.drain();
  713.                   this.out.write(var1, var2, var3);
  714.                }
  715.             }
  716.  
  717.          }
  718.       } else {
  719.          throw new IndexOutOfBoundsException();
  720.       }
  721.    }
  722.  
  723.    public void write(byte[] var1, int var2, int var3) throws IOException {
  724.       this.writeInternal(var1, var2, var3, false);
  725.    }
  726.  
  727.    private void bufferedWrite(byte[] var1, int var2, int var3) throws IOException {
  728.       int var4 = this.buf.length - this.count;
  729.       int var5 = var3;
  730.       if (var3 > var4) {
  731.          System.arraycopy(var1, var2, this.buf, this.count, var4);
  732.          var2 += var4;
  733.          var5 = var3 - var4;
  734.          this.out.write(this.buf, 0, this.buf.length);
  735.  
  736.          for(this.count = 0; var5 >= this.buf.length; var5 -= this.buf.length) {
  737.             System.arraycopy(var1, var2, this.buf, 0, this.buf.length);
  738.             this.out.write(this.buf, 0, this.buf.length);
  739.             var2 += this.buf.length;
  740.          }
  741.       }
  742.  
  743.       if (var5 != 0) {
  744.          System.arraycopy(var1, var2, this.buf, this.count, var5);
  745.          this.count += var5;
  746.       }
  747.  
  748.    }
  749.  
  750.    public void flush() throws IOException {
  751.       this.drain();
  752.       this.out.flush();
  753.    }
  754.  
  755.    protected void drain() throws IOException {
  756.       if (this.count != 0) {
  757.          if (this.blockDataMode) {
  758.             this.writeBlockDataHeader(this.count);
  759.          }
  760.  
  761.          this.out.write(this.buf, 0, this.count);
  762.          this.count = 0;
  763.       }
  764.    }
  765.  
  766.    public void close() throws IOException {
  767.       this.flush();
  768.       this.out.close();
  769.    }
  770.  
  771.    private boolean setBlockData(boolean var1) throws IOException {
  772.       if (this.blockDataMode == var1) {
  773.          return var1;
  774.       } else {
  775.          this.drain();
  776.          this.blockDataMode = var1;
  777.          return !var1;
  778.       }
  779.    }
  780.  
  781.    private void writeBlockDataHeader(int var1) throws IOException {
  782.       if (var1 <= 255) {
  783.          this.out.write(119);
  784.          this.out.write((byte)var1);
  785.       } else {
  786.          this.out.write(122);
  787.          this.out.write((byte)(var1 >> 24 & 255));
  788.          this.out.write((byte)(var1 >> 16 & 255));
  789.          this.out.write((byte)(var1 >> 8 & 255));
  790.          this.out.write((byte)(var1 & 255));
  791.       }
  792.  
  793.    }
  794.  
  795.    private void writeCanonical(byte[] var1, int var2, int var3) throws IOException {
  796.       int var4 = this.buf.length - this.count;
  797.       int var5 = var3;
  798.       if (var3 > var4) {
  799.          this.writeBlockDataHeader(this.buf.length);
  800.          this.out.write(this.buf, 0, this.count);
  801.          this.out.write(var1, var2, var4);
  802.          this.count = 0;
  803.          var2 += var4;
  804.  
  805.          for(var5 = var3 - var4; var5 >= this.buf.length; var5 -= this.buf.length) {
  806.             if (this.blockDataMode) {
  807.                this.writeBlockDataHeader(this.buf.length);
  808.             }
  809.  
  810.             this.out.write(var1, var2, this.buf.length);
  811.             var2 += this.buf.length;
  812.          }
  813.       }
  814.  
  815.       if (var5 != 0) {
  816.          System.arraycopy(var1, var2, this.buf, this.count, var5);
  817.          this.count += var5;
  818.       }
  819.  
  820.    }
  821.  
  822.    public void writeBoolean(boolean var1) throws IOException {
  823.       if (this.count >= this.buf.length) {
  824.          this.dos.writeBoolean(var1);
  825.       } else {
  826.          this.buf[this.count++] = (byte)(var1 ? 1 : 0);
  827.       }
  828.    }
  829.  
  830.    public void writeByte(int var1) throws IOException {
  831.       if (this.count >= this.buf.length) {
  832.          this.dos.writeByte(var1);
  833.       } else {
  834.          this.buf[this.count++] = (byte)var1;
  835.       }
  836.    }
  837.  
  838.    public void writeShort(int var1) throws IOException {
  839.       if (this.count + 2 > this.buf.length) {
  840.          this.dos.writeShort(var1);
  841.       } else {
  842.          this.buf[this.count++] = (byte)(var1 >>> 8);
  843.          this.buf[this.count++] = (byte)(var1 >>> 0);
  844.       }
  845.    }
  846.  
  847.    public void writeChar(int var1) throws IOException {
  848.       if (this.count + 2 > this.buf.length) {
  849.          this.dos.writeChar(var1);
  850.       } else {
  851.          this.buf[this.count++] = (byte)(var1 >>> 8);
  852.          this.buf[this.count++] = (byte)(var1 >>> 0);
  853.       }
  854.    }
  855.  
  856.    public void writeInt(int var1) throws IOException {
  857.       if (this.count + 4 > this.buf.length) {
  858.          this.dos.writeInt(var1);
  859.       } else {
  860.          this.buf[this.count++] = (byte)(var1 >>> 24);
  861.          this.buf[this.count++] = (byte)(var1 >>> 16);
  862.          this.buf[this.count++] = (byte)(var1 >>> 8);
  863.          this.buf[this.count++] = (byte)(var1 >>> 0);
  864.       }
  865.    }
  866.  
  867.    public void writeLong(long var1) throws IOException {
  868.       if (this.count + 8 > this.buf.length) {
  869.          this.dos.writeLong(var1);
  870.       } else {
  871.          this.buf[this.count++] = (byte)((int)(var1 >>> 56));
  872.          this.buf[this.count++] = (byte)((int)(var1 >>> 48));
  873.          this.buf[this.count++] = (byte)((int)(var1 >>> 40));
  874.          this.buf[this.count++] = (byte)((int)(var1 >>> 32));
  875.          this.buf[this.count++] = (byte)((int)(var1 >>> 24));
  876.          this.buf[this.count++] = (byte)((int)(var1 >>> 16));
  877.          this.buf[this.count++] = (byte)((int)(var1 >>> 8));
  878.          this.buf[this.count++] = (byte)((int)(var1 >>> 0));
  879.       }
  880.    }
  881.  
  882.    public void writeFloat(float var1) throws IOException {
  883.       int var2 = Float.floatToIntBits(var1);
  884.       if (this.count + 4 > this.buf.length) {
  885.          this.dos.writeFloat(var1);
  886.       } else {
  887.          this.buf[this.count++] = (byte)(var2 >>> 24);
  888.          this.buf[this.count++] = (byte)(var2 >>> 16);
  889.          this.buf[this.count++] = (byte)(var2 >>> 8);
  890.          this.buf[this.count++] = (byte)(var2 >>> 0);
  891.       }
  892.    }
  893.  
  894.    public void writeDouble(double var1) throws IOException {
  895.       long var3 = Double.doubleToLongBits(var1);
  896.       if (this.count + 8 > this.buf.length) {
  897.          this.dos.writeDouble(var1);
  898.       } else {
  899.          this.buf[this.count++] = (byte)((int)(var3 >>> 56));
  900.          this.buf[this.count++] = (byte)((int)(var3 >>> 48));
  901.          this.buf[this.count++] = (byte)((int)(var3 >>> 40));
  902.          this.buf[this.count++] = (byte)((int)(var3 >>> 32));
  903.          this.buf[this.count++] = (byte)((int)(var3 >>> 24));
  904.          this.buf[this.count++] = (byte)((int)(var3 >>> 16));
  905.          this.buf[this.count++] = (byte)((int)(var3 >>> 8));
  906.          this.buf[this.count++] = (byte)((int)(var3 >>> 0));
  907.       }
  908.    }
  909.  
  910.    public void writeBytes(String var1) throws IOException {
  911.       char[] var2 = var1.toCharArray();
  912.       int var3 = var2.length;
  913.       int var4 = this.buf.length;
  914.  
  915.       for(int var5 = 0; var5 < var3; ++var5) {
  916.          if (this.count >= var4) {
  917.             this.drain();
  918.          }
  919.  
  920.          this.buf[this.count++] = (byte)var2[var5];
  921.       }
  922.  
  923.    }
  924.  
  925.    public void writeChars(String var1) throws IOException {
  926.       char[] var2 = var1.toCharArray();
  927.       int var3 = var2.length;
  928.       int var4 = this.buf.length - 2;
  929.  
  930.       for(int var6 = 0; var6 < var3; ++var6) {
  931.          char var5 = var2[var6];
  932.          if (this.count > var4) {
  933.             this.dos.writeChar(var5);
  934.          } else {
  935.             this.buf[this.count++] = (byte)(var5 >>> 8);
  936.             this.buf[this.count++] = (byte)(var5 >>> 0);
  937.          }
  938.       }
  939.  
  940.    }
  941.  
  942.    public void writeUTF(String var1) throws IOException {
  943.       int var4 = var1.length();
  944.       if (this.cdata != null && this.cdata.length >= var4) {
  945.          var1.getChars(0, var4, this.cdata, 0);
  946.       } else {
  947.          this.cdata = var1.toCharArray();
  948.       }
  949.  
  950.       long var2 = getUTFLength(this.cdata, var4);
  951.       if (var2 > 65535L) {
  952.          throw new UTFDataFormatException();
  953.       } else {
  954.          this.writeShort((int)var2);
  955.          this.writeUTFBody(this.cdata, var4);
  956.          if (var4 > 1024) {
  957.             this.cdata = null;
  958.          }
  959.  
  960.       }
  961.    }
  962.  
  963.    private void outputClassFields(Object var1, Class var2, ObjectStreamField[] var3) throws IOException, InvalidClassException {
  964.       int var4 = this.currentClassDesc.numPrimBytes;
  965.       if (var4 > 0) {
  966.          if (this.data == null) {
  967.             this.data = new byte[Math.max(var4, 64)];
  968.          } else if (this.data.length < var4) {
  969.             this.data = new byte[var4];
  970.          }
  971.  
  972.          getPrimitiveFieldValues(var1, this.currentClassDesc.primFieldIDs, this.currentClassDesc.primFieldTypecodes, this.data);
  973.          this.writeInternal(this.data, 0, var4, false);
  974.       }
  975.  
  976.       int var5 = var3.length - this.currentClassDesc.numObjFields;
  977.       long[] var6 = this.currentClassDesc.objFieldIDs;
  978.  
  979.       for(int var7 = 0; var7 < this.currentClassDesc.numObjFields; ++var7) {
  980.          Object var8;
  981.          try {
  982.             var8 = getObjectFieldValue(var1, var6[var7]);
  983.          } catch (Exception var10) {
  984.             throw new InvalidClassException(var2.getName(), "Invalid field " + var3[var5 + var7].getName());
  985.          }
  986.  
  987.          this.writeObject(var8);
  988.       }
  989.  
  990.    }
  991.  
  992.    private static native void getPrimitiveFieldValues(Object var0, long[] var1, char[] var2, byte[] var3);
  993.  
  994.    private static native Object getObjectFieldValue(Object var0, long var1);
  995.  
  996.    private void invokeObjectWriter(Object var1) throws IOException {
  997.       try {
  998.          this.currentClassDesc.writeObjectMethod.invoke(var1, this.writeObjectArglist);
  999.       } catch (InvocationTargetException var4) {
  1000.          Throwable var3 = var4.getTargetException();
  1001.          if (var3 instanceof IOException) {
  1002.             throw (IOException)var3;
  1003.          } else if (var3 instanceof RuntimeException) {
  1004.             throw (RuntimeException)var3;
  1005.          } else if (var3 instanceof Error) {
  1006.             throw (Error)var3;
  1007.          } else {
  1008.             throw new Error("internal error");
  1009.          }
  1010.       } catch (IllegalAccessException var5) {
  1011.          throw new InternalError("Unable to access writeObject method");
  1012.       }
  1013.    }
  1014.  
  1015.    // $FF: synthetic method
  1016.    static Class class$(String var0) {
  1017.       try {
  1018.          return Class.forName(var0);
  1019.       } catch (ClassNotFoundException var2) {
  1020.          throw new NoClassDefFoundError(((Throwable)var2).getMessage());
  1021.       }
  1022.    }
  1023. }
  1024.