diff options
author | Michael Koch <konqueror@gmx.de> | 2003-12-30 15:51:15 +0000 |
---|---|---|
committer | Michael Koch <mkoch@gcc.gnu.org> | 2003-12-30 15:51:15 +0000 |
commit | 34998d6bb655f3270bc54656aa9519360100c2d8 (patch) | |
tree | 3d9504271f8d663874288d9f51dc992e98266033 | |
parent | 31775d3113a0c28019d16931f12c83bd3c9df845 (diff) | |
download | gcc-34998d6bb655f3270bc54656aa9519360100c2d8.zip gcc-34998d6bb655f3270bc54656aa9519360100c2d8.tar.gz gcc-34998d6bb655f3270bc54656aa9519360100c2d8.tar.bz2 |
ObjectInputStream.java, [...]: Reformated, no functional code changes.
2003-12-30 Michael Koch <konqueror@gmx.de>
* java/io/ObjectInputStream.java,
java/io/ObjectOutputStream.java,
java/io/ObjectStreamClass.java:
Reformated, no functional code changes.
From-SVN: r75236
-rw-r--r-- | libjava/ChangeLog | 7 | ||||
-rw-r--r-- | libjava/java/io/ObjectInputStream.java | 772 | ||||
-rw-r--r-- | libjava/java/io/ObjectOutputStream.java | 680 | ||||
-rw-r--r-- | libjava/java/io/ObjectStreamClass.java | 818 |
4 files changed, 1151 insertions, 1126 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 639b936..9211c7c 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,5 +1,12 @@ 2003-12-30 Michael Koch <konqueror@gmx.de> + * java/io/ObjectInputStream.java, + java/io/ObjectOutputStream.java, + java/io/ObjectStreamClass.java: + Reformated, no functional code changes. + +2003-12-30 Michael Koch <konqueror@gmx.de> + * gnu/java/net/protocol/http/Connection.java (outputStream): New field. (bufferedOutputStream): New field. diff --git a/libjava/java/io/ObjectInputStream.java b/libjava/java/io/ObjectInputStream.java index de13939..c2ddbe0 100644 --- a/libjava/java/io/ObjectInputStream.java +++ b/libjava/java/io/ObjectInputStream.java @@ -73,7 +73,7 @@ public class ObjectInputStream extends InputStream * * @see #readStreamHeader() */ - public ObjectInputStream (InputStream in) + public ObjectInputStream(InputStream in) throws IOException, StreamCorruptedException { if (Configuration.DEBUG) @@ -96,14 +96,14 @@ public class ObjectInputStream extends InputStream this.blockDataPosition = 0; this.blockDataBytes = 0; this.blockData = new byte[BUFFER_SIZE]; - this.blockDataInput = new DataInputStream (this); - this.realInputStream = new DataInputStream (in); + this.blockDataInput = new DataInputStream(this); + this.realInputStream = new DataInputStream(in); this.nextOID = baseWireHandle; - this.objectLookupTable = new Hashtable (); - this.validators = new Vector (); + this.objectLookupTable = new Hashtable(); + this.validators = new Vector(); this.classLookupTable = new Hashtable(); - setBlockDataMode (true); - readStreamHeader (); + setBlockDataMode(true); + readStreamHeader(); } @@ -122,10 +122,10 @@ public class ObjectInputStream extends InputStream * @exception IOException Exception from underlying * <code>InputStream</code>. */ - public final Object readObject () throws ClassNotFoundException, IOException + public final Object readObject() throws ClassNotFoundException, IOException { if (this.useSubclassMethod) - return readObjectOverride (); + return readObjectOverride(); boolean was_deserializing; @@ -133,12 +133,12 @@ public class ObjectInputStream extends InputStream was_deserializing = this.isDeserializing; boolean is_consumed = false; - boolean old_mode = setBlockDataMode (false); + boolean old_mode = setBlockDataMode(false); this.isDeserializing = true; - byte marker = this.realInputStream.readByte (); - dumpElement ("MARKER: 0x" + Integer.toHexString(marker) + " "); + byte marker = this.realInputStream.readByte(); + dumpElement("MARKER: 0x" + Integer.toHexString(marker) + " "); try { @@ -155,43 +155,43 @@ public class ObjectInputStream extends InputStream case TC_BLOCKDATALONG: { if (marker == TC_BLOCKDATALONG) - dumpElementln ("BLOCKDATALONG"); + dumpElementln("BLOCKDATALONG"); else - dumpElementln ("BLOCKDATA"); - readNextBlock (marker); - throw new StreamCorruptedException ("Unexpected blockData"); + dumpElementln("BLOCKDATA"); + readNextBlock(marker); + throw new StreamCorruptedException("Unexpected blockData"); } case TC_NULL: { - dumpElementln ("NULL"); + dumpElementln("NULL"); ret_val = null; break; } case TC_REFERENCE: { - dumpElement ("REFERENCE "); - Integer oid = new Integer (this.realInputStream.readInt ()); - dumpElementln (Integer.toHexString(oid.intValue())); + dumpElement("REFERENCE "); + Integer oid = new Integer(this.realInputStream.readInt()); + dumpElementln(Integer.toHexString(oid.intValue())); ret_val = ((ObjectIdentityWrapper) - this.objectLookupTable.get (oid)).object; + this.objectLookupTable.get(oid)).object; break; } case TC_CLASS: { - dumpElementln ("CLASS"); - ObjectStreamClass osc = (ObjectStreamClass)readObject (); - Class clazz = osc.forClass (); - assignNewHandle (clazz); + dumpElementln("CLASS"); + ObjectStreamClass osc = (ObjectStreamClass)readObject(); + Class clazz = osc.forClass(); + assignNewHandle(clazz); ret_val = clazz; break; } case TC_PROXYCLASSDESC: { - dumpElementln ("PROXYCLASS"); + dumpElementln("PROXYCLASS"); int n_intf = this.realInputStream.readInt(); String[] intfs = new String[n_intf]; for (int i = 0; i < n_intf; i++) @@ -200,41 +200,41 @@ public class ObjectInputStream extends InputStream System.out.println(intfs[i]); } - boolean oldmode = setBlockDataMode (true); + boolean oldmode = setBlockDataMode(true); Class cl = resolveProxyClass(intfs); setBlockDataMode(oldmode); ObjectStreamClass osc = lookupClass(cl); - assignNewHandle (osc); + assignNewHandle(osc); if (!is_consumed) { - byte b = this.realInputStream.readByte (); + byte b = this.realInputStream.readByte(); if (b != TC_ENDBLOCKDATA) - throw new IOException ("Data annotated to class was not consumed." + b); + throw new IOException("Data annotated to class was not consumed." + b); } else is_consumed = false; - ObjectStreamClass superosc = (ObjectStreamClass)readObject (); - osc.setSuperclass (superosc); + ObjectStreamClass superosc = (ObjectStreamClass)readObject(); + osc.setSuperclass(superosc); ret_val = osc; break; } case TC_CLASSDESC: { - ObjectStreamClass osc = readClassDescriptor (); + ObjectStreamClass osc = readClassDescriptor(); if (!is_consumed) { - byte b = this.realInputStream.readByte (); + byte b = this.realInputStream.readByte(); if (b != TC_ENDBLOCKDATA) - throw new IOException ("Data annotated to class was not consumed." + b); + throw new IOException("Data annotated to class was not consumed." + b); } else is_consumed = false; - osc.setSuperclass ((ObjectStreamClass)readObject ()); + osc.setSuperclass ((ObjectStreamClass)readObject()); ret_val = osc; break; } @@ -242,105 +242,107 @@ public class ObjectInputStream extends InputStream case TC_STRING: case TC_LONGSTRING: { - dumpElement ("STRING="); - String s = this.realInputStream.readUTF (); - dumpElementln (s); - ret_val = processResolution (s, assignNewHandle (s)); + dumpElement("STRING="); + String s = this.realInputStream.readUTF(); + dumpElementln(s); + ret_val = processResolution(s, assignNewHandle(s)); break; } case TC_ARRAY: { - dumpElementln ("ARRAY"); - ObjectStreamClass osc = (ObjectStreamClass)readObject (); - Class componentType = osc.forClass ().getComponentType (); - dumpElement ("ARRAY LENGTH="); - int length = this.realInputStream.readInt (); + dumpElementln("ARRAY"); + ObjectStreamClass osc = (ObjectStreamClass)readObject(); + Class componentType = osc.forClass().getComponentType(); + dumpElement("ARRAY LENGTH="); + int length = this.realInputStream.readInt(); dumpElementln (length + "; COMPONENT TYPE=" + componentType); - Object array = Array.newInstance (componentType, length); - int handle = assignNewHandle (array); - readArrayElements (array, componentType); - for (int i=0, len=Array.getLength(array); i < len; i++) - dumpElementln (" ELEMENT[" + i + "]=" + Array.get(array, i)); - ret_val = processResolution (array, handle); + Object array = Array.newInstance(componentType, length); + int handle = assignNewHandle(array); + readArrayElements(array, componentType); + for (int i = 0, len = Array.getLength(array); i < len; i++) + dumpElementln(" ELEMENT[" + i + "]=" + Array.get(array, i)); + ret_val = processResolution(array, handle); break; } case TC_OBJECT: { - dumpElementln ("OBJECT"); - ObjectStreamClass osc = (ObjectStreamClass)readObject (); - Class clazz = osc.forClass (); + dumpElementln("OBJECT"); + ObjectStreamClass osc = (ObjectStreamClass)readObject(); + Class clazz = osc.forClass(); - if (!Serializable.class.isAssignableFrom (clazz)) - throw new NotSerializableException (clazz + " is not Serializable, and thus cannot be deserialized."); + if (!Serializable.class.isAssignableFrom(clazz)) + throw new NotSerializableException + (clazz + " is not Serializable, and thus cannot be deserialized."); - if (Externalizable.class.isAssignableFrom (clazz)) + if (Externalizable.class.isAssignableFrom(clazz)) { Externalizable obj = null; try { - obj = (Externalizable)clazz.newInstance (); + obj = (Externalizable)clazz.newInstance(); } catch (InstantiationException e) { - throw new ClassNotFoundException ("Instance of " + clazz - + " could not be created"); + throw new ClassNotFoundException + ("Instance of " + clazz + " could not be created"); } catch (IllegalAccessException e) { - throw new ClassNotFoundException ("Instance of " + clazz - + " could not be created because class or zero-argument constructor is not accessible"); + throw new ClassNotFoundException + ("Instance of " + clazz + " could not be created because class or " + + "zero-argument constructor is not accessible"); } catch (NoSuchMethodError e) { - throw new ClassNotFoundException ("Instance of " + clazz - + " could not be created because zero-argument constructor is not defined"); + throw new ClassNotFoundException + ("Instance of " + clazz + + " could not be created because zero-argument constructor is not defined"); } - int handle = assignNewHandle (obj); + int handle = assignNewHandle(obj); - boolean read_from_blocks = ((osc.getFlags () & SC_BLOCK_DATA) != 0); + boolean read_from_blocks = ((osc.getFlags() & SC_BLOCK_DATA) != 0); boolean oldmode = this.readDataFromBlock; if (read_from_blocks) - setBlockDataMode (true); + setBlockDataMode(true); - obj.readExternal (this); + obj.readExternal(this); if (read_from_blocks) - setBlockDataMode (oldmode); + setBlockDataMode(oldmode); - ret_val = processResolution (obj, handle); + ret_val = processResolution(obj, handle); break; } // end if (Externalizable.class.isAssignableFrom (clazz)) // find the first non-serializable, non-abstract // class in clazz's inheritance hierarchy - Class first_nonserial = clazz.getSuperclass (); - while (Serializable.class.isAssignableFrom (first_nonserial) - || Modifier.isAbstract (first_nonserial.getModifiers ())) - first_nonserial = first_nonserial.getSuperclass (); + Class first_nonserial = clazz.getSuperclass(); + while (Serializable.class.isAssignableFrom(first_nonserial) + || Modifier.isAbstract(first_nonserial.getModifiers())) + first_nonserial = first_nonserial.getSuperclass(); Object obj = null; - obj = newObject (clazz, first_nonserial); + obj = newObject(clazz, first_nonserial); if (obj == null) - throw new ClassNotFoundException ("Instance of " + clazz + - " could not be created"); + throw new ClassNotFoundException + ("Instance of " + clazz + " could not be created"); - int handle = assignNewHandle (obj); + int handle = assignNewHandle(obj); this.currentObject = obj; ObjectStreamClass[] hierarchy = inputGetObjectStreamClasses(clazz); - for (int i=0; i < hierarchy.length; i++) + for (int i = 0; i < hierarchy.length; i++) { this.currentObjectStreamClass = hierarchy[i]; - dumpElementln ("Reading fields of " - + this.currentObjectStreamClass.getName ()); + dumpElementln("Reading fields of " + this.currentObjectStreamClass.getName ()); // XXX: should initialize fields in classes in the hierarchy // that aren't in the stream @@ -350,68 +352,69 @@ public class ObjectInputStream extends InputStream if (this.currentObjectStreamClass.hasReadMethod()) { fieldsAlreadyRead = false; - boolean oldmode = setBlockDataMode (true); - callReadMethod (obj, this.currentObjectStreamClass); - setBlockDataMode (oldmode); - dumpElement ("ENDBLOCKDATA? "); + boolean oldmode = setBlockDataMode(true); + callReadMethod(obj, this.currentObjectStreamClass); + setBlockDataMode(oldmode); + dumpElement("ENDBLOCKDATA? "); try { // FIXME: XXX: This try block is to catch EOF which is // thrown for some objects. That indicates a bug in the logic. - if (this.realInputStream.readByte () != TC_ENDBLOCKDATA) - throw new IOException ("No end of block data seen for class with readObject (ObjectInputStream) method."); - dumpElementln ("yes"); + if (this.realInputStream.readByte() != TC_ENDBLOCKDATA) + throw new IOException + ("No end of block data seen for class with readObject (ObjectInputStream) method."); + dumpElementln("yes"); } catch (EOFException e) { - dumpElementln ("no, got EOFException"); + dumpElementln("no, got EOFException"); } catch (IOException e) { - dumpElementln ("no, got IOException"); + dumpElementln("no, got IOException"); } } else { - readFields (obj, currentObjectStreamClass); + readFields(obj, currentObjectStreamClass); } } this.currentObject = null; this.currentObjectStreamClass = null; - ret_val = processResolution (obj, handle); + ret_val = processResolution(obj, handle); break; } case TC_RESET: - dumpElementln ("RESET"); - clearHandles (); - ret_val = readObject (); + dumpElementln("RESET"); + clearHandles(); + ret_val = readObject(); break; case TC_EXCEPTION: { - dumpElement ("EXCEPTION="); - Exception e = (Exception)readObject (); - dumpElementln (e.toString()); - clearHandles (); - throw new WriteAbortedException ("Exception thrown during writing of stream", e); + dumpElement("EXCEPTION="); + Exception e = (Exception)readObject(); + dumpElementln(e.toString()); + clearHandles(); + throw new WriteAbortedException("Exception thrown during writing of stream", e); } default: - throw new IOException ("Unknown marker on stream: " + marker); + throw new IOException("Unknown marker on stream: " + marker); } } finally { - setBlockDataMode (old_mode); + setBlockDataMode(old_mode); this.isDeserializing = was_deserializing; if (! was_deserializing) { - if (validators.size () > 0) - invokeValidators (); + if (validators.size() > 0) + invokeValidators(); } } @@ -434,30 +437,30 @@ public class ObjectInputStream extends InputStream * @throws InvalidClassException If there was a compatibility problem * between the class present in the system and the serialized class. */ - protected ObjectStreamClass readClassDescriptor () + protected ObjectStreamClass readClassDescriptor() throws ClassNotFoundException, IOException { - dumpElement ("CLASSDESC NAME="); - String name = this.realInputStream.readUTF (); - dumpElement (name + "; UID="); + dumpElement("CLASSDESC NAME="); + String name = this.realInputStream.readUTF(); + dumpElement(name + "; UID="); long uid = this.realInputStream.readLong (); - dumpElement (Long.toHexString(uid) + "; FLAGS="); + dumpElement(Long.toHexString(uid) + "; FLAGS="); byte flags = this.realInputStream.readByte (); - dumpElement (Integer.toHexString(flags) + "; FIELD COUNT="); - short field_count = this.realInputStream.readShort (); - dumpElementln (Short.toString(field_count)); + dumpElement(Integer.toHexString(flags) + "; FIELD COUNT="); + short field_count = this.realInputStream.readShort(); + dumpElementln(Short.toString(field_count)); ObjectStreamField[] fields = new ObjectStreamField[field_count]; - ObjectStreamClass osc = new ObjectStreamClass (name, uid, - flags, fields); - assignNewHandle (osc); + ObjectStreamClass osc = new ObjectStreamClass(name, uid, + flags, fields); + assignNewHandle(osc); - for (int i=0; i < field_count; i++) + for (int i = 0; i < field_count; i++) { - dumpElement (" TYPE CODE="); - char type_code = (char)this.realInputStream.readByte (); - dumpElement (type_code + "; FIELD NAME="); - String field_name = this.realInputStream.readUTF (); - dumpElementln (field_name); + dumpElement(" TYPE CODE="); + char type_code = (char)this.realInputStream.readByte(); + dumpElement(type_code + "; FIELD NAME="); + String field_name = this.realInputStream.readUTF(); + dumpElementln(field_name); String class_name; // If the type code is an array or an object we must @@ -465,9 +468,9 @@ public class ObjectInputStream extends InputStream // the type code and pass it to ObjectStreamField. // Type codes are decoded by gnu.java.lang.reflect.TypeSignature. if (type_code == 'L' || type_code == '[') - class_name = (String)readObject (); + class_name = (String)readObject(); else - class_name = String.valueOf (type_code); + class_name = String.valueOf(type_code); fields[i] = new ObjectStreamField(field_name, class_name, currentLoader()); @@ -495,11 +498,11 @@ public class ObjectInputStream extends InputStream } } - boolean oldmode = setBlockDataMode (true); - osc.setClass (clazz, lookupClass(clazz.getSuperclass())); + boolean oldmode = setBlockDataMode(true); + osc.setClass(clazz, lookupClass(clazz.getSuperclass())); classLookupTable.put(clazz, osc); - setBlockDataMode (oldmode); - + setBlockDataMode(oldmode); + return osc; } @@ -522,7 +525,7 @@ public class ObjectInputStream extends InputStream * @exception IOException Exception from underlying * <code>OutputStream</code>. */ - public void defaultReadObject () + public void defaultReadObject() throws ClassNotFoundException, IOException, NotActiveException { if (this.currentObject == null || this.currentObjectStreamClass == null) @@ -535,7 +538,7 @@ public class ObjectInputStream extends InputStream + "defaultReadObject or readFields)"); boolean oldmode = setBlockDataMode(false); - readFields (this.currentObject, this.currentObjectStreamClass); + readFields(this.currentObject, this.currentObjectStreamClass); setBlockDataMode(oldmode); fieldsAlreadyRead = true; @@ -560,20 +563,20 @@ public class ObjectInputStream extends InputStream * validator outside of the <code>readObject</code> method of the * object currently being deserialized */ - public void registerValidation (ObjectInputValidation validator, - int priority) + public void registerValidation(ObjectInputValidation validator, + int priority) throws InvalidObjectException, NotActiveException { if (this.currentObject == null || this.currentObjectStreamClass == null) - throw new NotActiveException ("registerValidation called by non-active " - +"class and/or object"); + throw new NotActiveException("registerValidation called by non-active " + + "class and/or object"); if (validator == null) - throw new InvalidObjectException ("attempt to add a null " - +"ObjectInputValidation object"); + throw new InvalidObjectException("attempt to add a null " + + "ObjectInputValidation object"); - this.validators.addElement (new ValidatorAndPriority (validator, - priority)); + this.validators.addElement(new ValidatorAndPriority (validator, + priority)); } @@ -593,7 +596,7 @@ public class ObjectInputStream extends InputStream * * @see java.io.ObjectOutputStream#annotateClass (java.lang.Class) */ - protected Class resolveClass (ObjectStreamClass osc) + protected Class resolveClass(ObjectStreamClass osc) throws ClassNotFoundException, IOException { return Class.forName(osc.getName(), true, currentLoader()); @@ -609,7 +612,7 @@ public class ObjectInputStream extends InputStream */ private ClassLoader currentLoader() { - SecurityManager sm = System.getSecurityManager (); + SecurityManager sm = System.getSecurityManager(); if (sm == null) sm = new SecurityManager () {}; @@ -627,13 +630,13 @@ public class ObjectInputStream extends InputStream * @return A valid instance of ObjectStreamClass corresponding * to the specified class. */ - private ObjectStreamClass lookupClass (Class clazz) + private ObjectStreamClass lookupClass(Class clazz) { ObjectStreamClass oclazz; - oclazz = (ObjectStreamClass) classLookupTable.get(clazz); + oclazz = (ObjectStreamClass)classLookupTable.get(clazz); if (oclazz == null) - return ObjectStreamClass.lookup (clazz); + return ObjectStreamClass.lookup(clazz); else return oclazz; } @@ -650,9 +653,9 @@ public class ObjectInputStream extends InputStream * @return An array of valid {@link java.io.ObjectStreamClass} instances which * represent the class hierarchy for clazz. */ - private ObjectStreamClass[] inputGetObjectStreamClasses (Class clazz) + private ObjectStreamClass[] inputGetObjectStreamClasses(Class clazz) { - ObjectStreamClass osc = lookupClass (clazz); + ObjectStreamClass osc = lookupClass(clazz); ObjectStreamClass[] ret_val; @@ -691,36 +694,40 @@ public class ObjectInputStream extends InputStream * * @see #enableResolveObject(boolean) */ - protected Object resolveObject (Object obj) throws IOException + protected Object resolveObject(Object obj) throws IOException { return obj; } - protected Class resolveProxyClass (String[] intfs) + protected Class resolveProxyClass(String[] intfs) throws IOException, ClassNotFoundException { - SecurityManager sm = System.getSecurityManager (); + SecurityManager sm = System.getSecurityManager(); if (sm == null) - sm = new SecurityManager () {}; + sm = new SecurityManager() {}; - ClassLoader cl = currentClassLoader (sm); + ClassLoader cl = currentClassLoader(sm); Class[] clss = new Class[intfs.length]; - if(cl == null){ - for (int i = 0; i < intfs.length; i++) - clss[i] = Class.forName(intfs[i]); - cl = ClassLoader.getSystemClassLoader(); - } + if(cl == null) + { + for (int i = 0; i < intfs.length; i++) + clss[i] = Class.forName(intfs[i]); + cl = ClassLoader.getSystemClassLoader(); + } else for (int i = 0; i < intfs.length; i++) clss[i] = cl.loadClass(intfs[i]); - try { - return Proxy.getProxyClass(cl, clss); - } catch (IllegalArgumentException e) { - throw new ClassNotFoundException(null, e); - } + try + { + return Proxy.getProxyClass(cl, clss); + } + catch (IllegalArgumentException e) + { + throw new ClassNotFoundException(null, e); + } } /** @@ -736,9 +743,9 @@ public class ObjectInputStream extends InputStream { if (enable) { - SecurityManager sm = System.getSecurityManager (); + SecurityManager sm = System.getSecurityManager(); if (sm != null) - sm.checkPermission (new SerializablePermission ("enableSubstitution")); + sm.checkPermission(new SerializablePermission("enableSubstitution")); } boolean old_val = this.resolveEnabled; @@ -755,31 +762,31 @@ public class ObjectInputStream extends InputStream * @exception StreamCorruptedException An invalid stream magic * number or stream version was read from the stream. */ - protected void readStreamHeader () + protected void readStreamHeader() throws IOException, StreamCorruptedException { - dumpElement ("STREAM MAGIC "); - if (this.realInputStream.readShort () != STREAM_MAGIC) - throw new StreamCorruptedException ("Invalid stream magic number"); + dumpElement("STREAM MAGIC "); + if (this.realInputStream.readShort() != STREAM_MAGIC) + throw new StreamCorruptedException("Invalid stream magic number"); - dumpElementln ("STREAM VERSION "); - if (this.realInputStream.readShort () != STREAM_VERSION) - throw new StreamCorruptedException ("Invalid stream version number"); + dumpElementln("STREAM VERSION "); + if (this.realInputStream.readShort() != STREAM_VERSION) + throw new StreamCorruptedException("Invalid stream version number"); } - public int read () throws IOException + public int read() throws IOException { if (this.readDataFromBlock) { if (this.blockDataPosition >= this.blockDataBytes) - readNextBlock (); + readNextBlock(); return (this.blockData[this.blockDataPosition++] & 0xff); } else - return this.realInputStream.read (); + return this.realInputStream.read(); } - public int read (byte[] data, int offset, int length) throws IOException + public int read(byte[] data, int offset, int length) throws IOException { if (this.readDataFromBlock) { @@ -788,25 +795,25 @@ public class ObjectInputStream extends InputStream int remain = this.blockDataBytes - this.blockDataPosition; if (remain != 0) { - System.arraycopy (this.blockData, this.blockDataPosition, - data, offset, remain); + System.arraycopy(this.blockData, this.blockDataPosition, + data, offset, remain); offset += remain; length -= remain; } readNextBlock (); } - System.arraycopy (this.blockData, this.blockDataPosition, - data, offset, length); + System.arraycopy(this.blockData, this.blockDataPosition, + data, offset, length); this.blockDataPosition += length; return length; } else - return this.realInputStream.read (data, offset, length); + return this.realInputStream.read(data, offset, length); } - public int available () throws IOException + public int available() throws IOException { if (this.readDataFromBlock) { @@ -816,15 +823,15 @@ public class ObjectInputStream extends InputStream return this.blockDataBytes - this.blockDataPosition; } else - return this.realInputStream.available (); + return this.realInputStream.available(); } - public void close () throws IOException + public void close() throws IOException { - this.realInputStream.close (); + this.realInputStream.close(); } - public boolean readBoolean () throws IOException + public boolean readBoolean() throws IOException { boolean switchmode = true; boolean oldmode = this.readDataFromBlock; @@ -838,160 +845,160 @@ public class ObjectInputStream extends InputStream return value; } - public byte readByte () throws IOException + public byte readByte() throws IOException { boolean switchmode = true; boolean oldmode = this.readDataFromBlock; if (!oldmode || this.blockDataBytes - this.blockDataPosition >= 1) switchmode = false; if (switchmode) - oldmode = setBlockDataMode (true); - byte value = this.dataInputStream.readByte (); + oldmode = setBlockDataMode(true); + byte value = this.dataInputStream.readByte(); if (switchmode) - setBlockDataMode (oldmode); + setBlockDataMode(oldmode); return value; } - public int readUnsignedByte () throws IOException + public int readUnsignedByte() throws IOException { boolean switchmode = true; boolean oldmode = this.readDataFromBlock; if (!oldmode || this.blockDataBytes - this.blockDataPosition >= 1) switchmode = false; if (switchmode) - oldmode = setBlockDataMode (true); - int value = this.dataInputStream.readUnsignedByte (); + oldmode = setBlockDataMode(true); + int value = this.dataInputStream.readUnsignedByte(); if (switchmode) - setBlockDataMode (oldmode); + setBlockDataMode(oldmode); return value; } - public short readShort () throws IOException + public short readShort() throws IOException { boolean switchmode = true; boolean oldmode = this.readDataFromBlock; if (!oldmode || this.blockDataBytes - this.blockDataPosition >= 2) switchmode = false; if (switchmode) - oldmode = setBlockDataMode (true); - short value = this.dataInputStream.readShort (); + oldmode = setBlockDataMode(true); + short value = this.dataInputStream.readShort(); if (switchmode) - setBlockDataMode (oldmode); + setBlockDataMode(oldmode); return value; } - public int readUnsignedShort () throws IOException + public int readUnsignedShort() throws IOException { boolean switchmode = true; boolean oldmode = this.readDataFromBlock; if (!oldmode || this.blockDataBytes - this.blockDataPosition >= 2) switchmode = false; if (switchmode) - oldmode = setBlockDataMode (true); - int value = this.dataInputStream.readUnsignedShort (); + oldmode = setBlockDataMode(true); + int value = this.dataInputStream.readUnsignedShort(); if (switchmode) - setBlockDataMode (oldmode); + setBlockDataMode(oldmode); return value; } - public char readChar () throws IOException + public char readChar() throws IOException { boolean switchmode = true; boolean oldmode = this.readDataFromBlock; if (!oldmode || this.blockDataBytes - this.blockDataPosition >= 2) switchmode = false; if (switchmode) - oldmode = setBlockDataMode (true); - char value = this.dataInputStream.readChar (); + oldmode = setBlockDataMode(true); + char value = this.dataInputStream.readChar(); if (switchmode) - setBlockDataMode (oldmode); + setBlockDataMode(oldmode); return value; } - public int readInt () throws IOException + public int readInt() throws IOException { boolean switchmode = true; boolean oldmode = this.readDataFromBlock; if (!oldmode || this.blockDataBytes - this.blockDataPosition >= 4) switchmode = false; if (switchmode) - oldmode = setBlockDataMode (true); - int value = this.dataInputStream.readInt (); + oldmode = setBlockDataMode(true); + int value = this.dataInputStream.readInt(); if (switchmode) - setBlockDataMode (oldmode); + setBlockDataMode(oldmode); return value; } - public long readLong () throws IOException + public long readLong() throws IOException { boolean switchmode = true; boolean oldmode = this.readDataFromBlock; if (!oldmode || this.blockDataBytes - this.blockDataPosition >= 8) switchmode = false; if (switchmode) - oldmode = setBlockDataMode (true); - long value = this.dataInputStream.readLong (); + oldmode = setBlockDataMode(true); + long value = this.dataInputStream.readLong(); if (switchmode) - setBlockDataMode (oldmode); + setBlockDataMode(oldmode); return value; } - public float readFloat () throws IOException + public float readFloat() throws IOException { boolean switchmode = true; boolean oldmode = this.readDataFromBlock; if (!oldmode || this.blockDataBytes - this.blockDataPosition >= 4) switchmode = false; if (switchmode) - oldmode = setBlockDataMode (true); - float value = this.dataInputStream.readFloat (); + oldmode = setBlockDataMode(true); + float value = this.dataInputStream.readFloat(); if (switchmode) - setBlockDataMode (oldmode); + setBlockDataMode(oldmode); return value; } - public double readDouble () throws IOException + public double readDouble() throws IOException { boolean switchmode = true; boolean oldmode = this.readDataFromBlock; if (!oldmode || this.blockDataBytes - this.blockDataPosition >= 8) switchmode = false; if (switchmode) - oldmode = setBlockDataMode (true); - double value = this.dataInputStream.readDouble (); + oldmode = setBlockDataMode(true); + double value = this.dataInputStream.readDouble(); if (switchmode) - setBlockDataMode (oldmode); + setBlockDataMode(oldmode); return value; } - public void readFully (byte data[]) throws IOException + public void readFully(byte data[]) throws IOException { - this.dataInputStream.readFully (data); + this.dataInputStream.readFully(data); } - public void readFully (byte data[], int offset, int size) + public void readFully(byte data[], int offset, int size) throws IOException { - this.dataInputStream.readFully (data, offset, size); + this.dataInputStream.readFully(data, offset, size); } - public int skipBytes (int len) throws IOException + public int skipBytes(int len) throws IOException { - return this.dataInputStream.skipBytes (len); + return this.dataInputStream.skipBytes(len); } /** * @deprecated * @see java.io.DataInputStream#readLine () */ - public String readLine () throws IOException + public String readLine() throws IOException { - return this.dataInputStream.readLine (); + return this.dataInputStream.readLine(); } - public String readUTF () throws IOException + public String readUTF() throws IOException { - return this.dataInputStream.readUTF (); + return this.dataInputStream.readUTF(); } /** @@ -1002,36 +1009,36 @@ public class ObjectInputStream extends InputStream */ public static abstract class GetField { - public abstract ObjectStreamClass getObjectStreamClass (); + public abstract ObjectStreamClass getObjectStreamClass(); - public abstract boolean defaulted (String name) + public abstract boolean defaulted(String name) throws IOException, IllegalArgumentException; - public abstract boolean get (String name, boolean defvalue) + public abstract boolean get(String name, boolean defvalue) throws IOException, IllegalArgumentException; - public abstract char get (String name, char defvalue) + public abstract char get(String name, char defvalue) throws IOException, IllegalArgumentException; - public abstract byte get (String name, byte defvalue) + public abstract byte get(String name, byte defvalue) throws IOException, IllegalArgumentException; - public abstract short get (String name, short defvalue) + public abstract short get(String name, short defvalue) throws IOException, IllegalArgumentException; - public abstract int get (String name, int defvalue) + public abstract int get(String name, int defvalue) throws IOException, IllegalArgumentException; - public abstract long get (String name, long defvalue) + public abstract long get(String name, long defvalue) throws IOException, IllegalArgumentException; - public abstract float get (String name, float defvalue) + public abstract float get(String name, float defvalue) throws IOException, IllegalArgumentException; - public abstract double get (String name, double defvalue) + public abstract double get(String name, double defvalue) throws IOException, IllegalArgumentException; - public abstract Object get (String name, Object defvalue) + public abstract Object get(String name, Object defvalue) throws IOException, IllegalArgumentException; } @@ -1048,18 +1055,18 @@ public class ObjectInputStream extends InputStream * @throws ClassNotFoundException * @throws NotActiveException */ - public GetField readFields () + public GetField readFields() throws IOException, ClassNotFoundException, NotActiveException { if (this.currentObject == null || this.currentObjectStreamClass == null) - throw new NotActiveException ("readFields called by non-active class and/or object"); + throw new NotActiveException("readFields called by non-active class and/or object"); if (prereadFields != null) return prereadFields; if (fieldsAlreadyRead) - throw new NotActiveException ("readFields called but fields already read from" - + " stream (by defaultReadObject or readFields)"); + throw new NotActiveException("readFields called but fields already read from" + + " stream (by defaultReadObject or readFields)"); final ObjectStreamClass clazz = this.currentObjectStreamClass; final byte[] prim_field_data = new byte[clazz.primFieldSize]; @@ -1068,20 +1075,20 @@ public class ObjectInputStream extends InputStream // Apparently Block data is not used with GetField as per // empirical evidence against JDK 1.2. Also see Mauve test // java.io.ObjectInputOutput.Test.GetPutField. - boolean oldmode = setBlockDataMode (false); - readFully (prim_field_data); + boolean oldmode = setBlockDataMode(false); + readFully(prim_field_data); for (int i = 0; i < objs.length; ++ i) - objs[i] = readObject (); - setBlockDataMode (oldmode); + objs[i] = readObject(); + setBlockDataMode(oldmode); prereadFields = new GetField() { - public ObjectStreamClass getObjectStreamClass () + public ObjectStreamClass getObjectStreamClass() { return clazz; } - public boolean defaulted (String name) + public boolean defaulted(String name) throws IOException, IllegalArgumentException { ObjectStreamField f = clazz.getField(name); @@ -1107,69 +1114,69 @@ public class ObjectInputStream extends InputStream } catch (NoSuchFieldException e) { - throw new IllegalArgumentException (e.getMessage()); + throw new IllegalArgumentException(e.getMessage()); } } - public boolean get (String name, boolean defvalue) + public boolean get(String name, boolean defvalue) throws IOException, IllegalArgumentException { - ObjectStreamField field = getField (name, Boolean.TYPE); + ObjectStreamField field = getField(name, Boolean.TYPE); if (field == null) return defvalue; - return prim_field_data[field.getOffset ()] == 0 ? false : true; + return prim_field_data[field.getOffset()] == 0 ? false : true; } - public char get (String name, char defvalue) + public char get(String name, char defvalue) throws IOException, IllegalArgumentException { - ObjectStreamField field = getField (name, Character.TYPE); + ObjectStreamField field = getField(name, Character.TYPE); if (field == null) return defvalue; - int off = field.getOffset (); + int off = field.getOffset(); return (char)(((prim_field_data[off++] & 0xFF) << 8) | (prim_field_data[off] & 0xFF)); } - public byte get (String name, byte defvalue) + public byte get(String name, byte defvalue) throws IOException, IllegalArgumentException { - ObjectStreamField field = getField (name, Byte.TYPE); + ObjectStreamField field = getField(name, Byte.TYPE); if (field == null) return defvalue; - return prim_field_data[field.getOffset ()]; + return prim_field_data[field.getOffset()]; } - public short get (String name, short defvalue) + public short get(String name, short defvalue) throws IOException, IllegalArgumentException { - ObjectStreamField field = getField (name, Short.TYPE); + ObjectStreamField field = getField(name, Short.TYPE); if (field == null) return defvalue; - int off = field.getOffset (); + int off = field.getOffset(); return (short)(((prim_field_data[off++] & 0xFF) << 8) | (prim_field_data[off] & 0xFF)); } - public int get (String name, int defvalue) + public int get(String name, int defvalue) throws IOException, IllegalArgumentException { - ObjectStreamField field = getField (name, Integer.TYPE); + ObjectStreamField field = getField(name, Integer.TYPE); if (field == null) return defvalue; - int off = field.getOffset (); + int off = field.getOffset(); return ((prim_field_data[off++] & 0xFF) << 24) | ((prim_field_data[off++] & 0xFF) << 16) @@ -1177,15 +1184,15 @@ public class ObjectInputStream extends InputStream | (prim_field_data[off] & 0xFF); } - public long get (String name, long defvalue) + public long get(String name, long defvalue) throws IOException, IllegalArgumentException { - ObjectStreamField field = getField (name, Long.TYPE); + ObjectStreamField field = getField(name, Long.TYPE); if (field == null) return defvalue; - int off = field.getOffset (); + int off = field.getOffset(); return (long)(((prim_field_data[off++] & 0xFF) << 56) | ((prim_field_data[off++] & 0xFF) << 48) @@ -1197,31 +1204,31 @@ public class ObjectInputStream extends InputStream | (prim_field_data[off] & 0xFF)); } - public float get (String name, float defvalue) + public float get(String name, float defvalue) throws IOException, IllegalArgumentException { - ObjectStreamField field = getField (name, Float.TYPE); + ObjectStreamField field = getField(name, Float.TYPE); if (field == null) return defvalue; - int off = field.getOffset (); + int off = field.getOffset(); - return Float.intBitsToFloat (((prim_field_data[off++] & 0xFF) << 24) - | ((prim_field_data[off++] & 0xFF) << 16) - | ((prim_field_data[off++] & 0xFF) << 8) - | (prim_field_data[off] & 0xFF)); + return Float.intBitsToFloat(((prim_field_data[off++] & 0xFF) << 24) + | ((prim_field_data[off++] & 0xFF) << 16) + | ((prim_field_data[off++] & 0xFF) << 8) + | (prim_field_data[off] & 0xFF)); } - public double get (String name, double defvalue) + public double get(String name, double defvalue) throws IOException, IllegalArgumentException { - ObjectStreamField field = getField (name, Double.TYPE); + ObjectStreamField field = getField(name, Double.TYPE); if (field == null) return defvalue; - int off = field.getOffset (); + int off = field.getOffset(); return Double.longBitsToDouble ( (long) (((prim_field_data[off++] & 0xFF) << 56) @@ -1234,22 +1241,22 @@ public class ObjectInputStream extends InputStream | (prim_field_data[off] & 0xFF))); } - public Object get (String name, Object defvalue) + public Object get(String name, Object defvalue) throws IOException, IllegalArgumentException { ObjectStreamField field = - getField (name, defvalue == null ? null : defvalue.getClass ()); + getField(name, defvalue == null ? null : defvalue.getClass ()); if (field == null) return defvalue; - return objs[field.getOffset ()]; + return objs[field.getOffset()]; } - private ObjectStreamField getField (String name, Class type) + private ObjectStreamField getField(String name, Class type) throws IllegalArgumentException { - ObjectStreamField field = clazz.getField (name); + ObjectStreamField field = clazz.getField(name); boolean illegal = false; try @@ -1300,7 +1307,7 @@ public class ObjectInputStream extends InputStream */ try { - Field f = clazz.forClass().getDeclaredField (name); + Field f = clazz.forClass().getDeclaredField(name); if (Modifier.isTransient(f.getModifiers())) throw new IllegalArgumentException ("no such field (non transient) " + name); @@ -1333,12 +1340,12 @@ public class ObjectInputStream extends InputStream * * @see #readObjectOverride() */ - protected ObjectInputStream () + protected ObjectInputStream() throws IOException, SecurityException { - SecurityManager sec_man = System.getSecurityManager (); + SecurityManager sec_man = System.getSecurityManager(); if (sec_man != null) - sec_man.checkPermission (SUBCLASS_IMPLEMENTATION_PERMISSION); + sec_man.checkPermission(SUBCLASS_IMPLEMENTATION_PERMISSION); this.useSubclassMethod = true; } @@ -1351,10 +1358,10 @@ public class ObjectInputStream extends InputStream * * @see #ObjectInputStream() */ - protected Object readObjectOverride () + protected Object readObjectOverride() throws ClassNotFoundException, IOException, OptionalDataException { - throw new IOException ("Subclass of ObjectInputStream must implement readObjectOverride"); + throw new IOException("Subclass of ObjectInputStream must implement readObjectOverride"); } /** @@ -1363,14 +1370,14 @@ public class ObjectInputStream extends InputStream * @param obj The object for which we want a new handle. * @return A valid handle for the specified object. */ - private int assignNewHandle (Object obj) + private int assignNewHandle(Object obj) { - this.objectLookupTable.put (new Integer (this.nextOID), - new ObjectIdentityWrapper (obj)); + this.objectLookupTable.put(new Integer(this.nextOID), + new ObjectIdentityWrapper(obj)); return this.nextOID++; } - private Object processResolution (Object obj, int handle) + private Object processResolution(Object obj, int handle) throws IOException { if (obj instanceof Serializable) @@ -1380,7 +1387,7 @@ public class ObjectInputStream extends InputStream { Class classArgs[] = {}; m = getMethod(obj.getClass(), "readResolve", classArgs); - obj = m.invoke (obj, new Object[] {}); + obj = m.invoke(obj, new Object[] {}); } catch (NoSuchMethodException ignore) { @@ -1394,42 +1401,42 @@ public class ObjectInputStream extends InputStream } if (this.resolveEnabled) - obj = resolveObject (obj); + obj = resolveObject(obj); - this.objectLookupTable.put (new Integer (handle), - new ObjectIdentityWrapper (obj)); + this.objectLookupTable.put(new Integer(handle), + new ObjectIdentityWrapper(obj)); return obj; } - private void clearHandles () + private void clearHandles() { - this.objectLookupTable.clear (); + this.objectLookupTable.clear(); this.nextOID = baseWireHandle; } - private void readNextBlock () throws IOException + private void readNextBlock() throws IOException { - readNextBlock (this.realInputStream.readByte ()); + readNextBlock(this.realInputStream.readByte()); } - private void readNextBlock (byte marker) throws IOException + private void readNextBlock(byte marker) throws IOException { if (marker == TC_BLOCKDATA) { - dumpElement ("BLOCK DATA SIZE="); - this.blockDataBytes = this.realInputStream.readUnsignedByte (); + dumpElement("BLOCK DATA SIZE="); + this.blockDataBytes = this.realInputStream.readUnsignedByte(); dumpElementln (Integer.toString(this.blockDataBytes)); } else if (marker == TC_BLOCKDATALONG) { - dumpElement ("BLOCK DATA LONG SIZE="); - this.blockDataBytes = this.realInputStream.readInt (); + dumpElement("BLOCK DATA LONG SIZE="); + this.blockDataBytes = this.realInputStream.readInt(); dumpElementln (Integer.toString(this.blockDataBytes)); } else { - throw new EOFException ("Attempt to read primitive data, but no data block is active."); + throw new EOFException("Attempt to read primitive data, but no data block is active."); } if (this.blockData.length < this.blockDataBytes) @@ -1442,62 +1449,62 @@ public class ObjectInputStream extends InputStream private void readArrayElements (Object array, Class clazz) throws ClassNotFoundException, IOException { - if (clazz.isPrimitive ()) + if (clazz.isPrimitive()) { if (clazz == Boolean.TYPE) { boolean[] cast_array = (boolean[])array; for (int i=0; i < cast_array.length; i++) - cast_array[i] = this.realInputStream.readBoolean (); + cast_array[i] = this.realInputStream.readBoolean(); return; } if (clazz == Byte.TYPE) { byte[] cast_array = (byte[])array; for (int i=0; i < cast_array.length; i++) - cast_array[i] = this.realInputStream.readByte (); + cast_array[i] = this.realInputStream.readByte(); return; } if (clazz == Character.TYPE) { char[] cast_array = (char[])array; for (int i=0; i < cast_array.length; i++) - cast_array[i] = this.realInputStream.readChar (); + cast_array[i] = this.realInputStream.readChar(); return; } if (clazz == Double.TYPE) { double[] cast_array = (double[])array; for (int i=0; i < cast_array.length; i++) - cast_array[i] = this.realInputStream.readDouble (); + cast_array[i] = this.realInputStream.readDouble(); return; } if (clazz == Float.TYPE) { float[] cast_array = (float[])array; for (int i=0; i < cast_array.length; i++) - cast_array[i] = this.realInputStream.readFloat (); + cast_array[i] = this.realInputStream.readFloat(); return; } if (clazz == Integer.TYPE) { int[] cast_array = (int[])array; for (int i=0; i < cast_array.length; i++) - cast_array[i] = this.realInputStream.readInt (); + cast_array[i] = this.realInputStream.readInt(); return; } if (clazz == Long.TYPE) { long[] cast_array = (long[])array; for (int i=0; i < cast_array.length; i++) - cast_array[i] = this.realInputStream.readLong (); + cast_array[i] = this.realInputStream.readLong(); return; } if (clazz == Short.TYPE) { short[] cast_array = (short[])array; for (int i=0; i < cast_array.length; i++) - cast_array[i] = this.realInputStream.readShort (); + cast_array[i] = this.realInputStream.readShort(); return; } } @@ -1505,7 +1512,7 @@ public class ObjectInputStream extends InputStream { Object[] cast_array = (Object[])array; for (int i=0; i < cast_array.length; i++) - cast_array[i] = readObject (); + cast_array[i] = readObject(); } } @@ -1535,7 +1542,7 @@ public class ObjectInputStream extends InputStream else { stream_field = stream_fields[stream_idx]; - type = stream_field.getType (); + type = stream_field.getType(); } if (real_idx == real_fields.length) @@ -1543,8 +1550,8 @@ public class ObjectInputStream extends InputStream else { real_field = real_fields[real_idx]; - type = real_field.getType (); - field_name = real_field.getName (); + type = real_field.getType(); + field_name = real_field.getName(); } if (set_value && !default_initialize) @@ -1583,82 +1590,82 @@ public class ObjectInputStream extends InputStream if (type == Boolean.TYPE) { boolean value = - default_initialize ? false : this.realInputStream.readBoolean (); + default_initialize ? false : this.realInputStream.readBoolean(); if (!default_initialize && set_value) - dumpElementln (" " + field_name + ": " + value); + dumpElementln(" " + field_name + ": " + value); if (set_value) - setBooleanField (obj, stream_osc.forClass (), field_name, value); + setBooleanField(obj, stream_osc.forClass(), field_name, value); } else if (type == Byte.TYPE) { byte value = - default_initialize ? 0 : this.realInputStream.readByte (); + default_initialize ? 0 : this.realInputStream.readByte(); if (!default_initialize && set_value) - dumpElementln (" " + field_name + ": " + value); + dumpElementln(" " + field_name + ": " + value); if (set_value) - setByteField (obj, stream_osc.forClass (), field_name, value); + setByteField(obj, stream_osc.forClass(), field_name, value); } else if (type == Character.TYPE) { char value = - default_initialize ? (char)0 : this.realInputStream.readChar (); + default_initialize ? (char)0 : this.realInputStream.readChar(); if (!default_initialize && set_value) - dumpElementln (" " + field_name + ": " + value); + dumpElementln(" " + field_name + ": " + value); if (set_value) - setCharField (obj, stream_osc.forClass (), field_name, value); + setCharField(obj, stream_osc.forClass(), field_name, value); } else if (type == Double.TYPE) { double value = - default_initialize ? 0 : this.realInputStream.readDouble (); + default_initialize ? 0 : this.realInputStream.readDouble(); if (!default_initialize && set_value) - dumpElementln (" " + field_name + ": " + value); + dumpElementln(" " + field_name + ": " + value); if (set_value) - setDoubleField (obj, stream_osc.forClass (), field_name, value); + setDoubleField(obj, stream_osc.forClass(), field_name, value); } else if (type == Float.TYPE) { float value = - default_initialize ? 0 : this.realInputStream.readFloat (); + default_initialize ? 0 : this.realInputStream.readFloat(); if (!default_initialize && set_value) - dumpElementln (" " + field_name + ": " + value); + dumpElementln(" " + field_name + ": " + value); if (set_value) - setFloatField (obj, stream_osc.forClass (), field_name, value); + setFloatField(obj, stream_osc.forClass(), field_name, value); } else if (type == Integer.TYPE) { int value = - default_initialize ? 0 : this.realInputStream.readInt (); + default_initialize ? 0 : this.realInputStream.readInt(); if (!default_initialize && set_value) - dumpElementln (" " + field_name + ": " + value); + dumpElementln(" " + field_name + ": " + value); if (set_value) - setIntField (obj, stream_osc.forClass (), field_name, value); + setIntField(obj, stream_osc.forClass(), field_name, value); } else if (type == Long.TYPE) { long value = - default_initialize ? 0 : this.realInputStream.readLong (); + default_initialize ? 0 : this.realInputStream.readLong(); if (!default_initialize && set_value) - dumpElementln (" " + field_name + ": " + value); + dumpElementln(" " + field_name + ": " + value); if (set_value) - setLongField (obj, stream_osc.forClass (), field_name, value); + setLongField(obj, stream_osc.forClass(), field_name, value); } else if (type == Short.TYPE) { short value = - default_initialize ? (short)0 : this.realInputStream.readShort (); + default_initialize ? (short)0 : this.realInputStream.readShort(); if (!default_initialize && set_value) - dumpElementln (" " + field_name + ": " + value); + dumpElementln(" " + field_name + ": " + value); if (set_value) - setShortField (obj, stream_osc.forClass (), field_name, value); + setShortField(obj, stream_osc.forClass(), field_name, value); } else { Object value = - default_initialize ? null : readObject (); + default_initialize ? null : readObject(); if (set_value) - setObjectField (obj, stream_osc.forClass (), field_name, - real_field.getTypeString (), value); + setObjectField(obj, stream_osc.forClass(), field_name, + real_field.getTypeString(), value); } } catch (NoSuchFieldError e) @@ -1699,20 +1706,20 @@ public class ObjectInputStream extends InputStream // runs all registered ObjectInputValidations in prioritized order // on OBJ - private void invokeValidators () throws InvalidObjectException + private void invokeValidators() throws InvalidObjectException { - Object[] validators = new Object[this.validators.size ()]; + Object[] validators = new Object[this.validators.size()]; this.validators.copyInto (validators); Arrays.sort (validators); try { for (int i=0; i < validators.length; i++) - ((ObjectInputValidation)validators[i]).validateObject (); + ((ObjectInputValidation)validators[i]).validateObject(); } finally { - this.validators.removeAllElements (); + this.validators.removeAllElements(); } } @@ -1789,7 +1796,7 @@ public class ObjectInputStream extends InputStream Class classArgs[] = {ObjectInputStream.class}; Method m = getMethod (klass, "readObject", classArgs); Object args[] = {this}; - m.invoke (obj, args); + m.invoke(obj, args); } catch (NoSuchMethodException nsme) { @@ -1804,12 +1811,12 @@ public class ObjectInputStream extends InputStream if (exception instanceof IOException) throw (IOException) exception; - throw new IOException ("Exception thrown from readObject() on " + + throw new IOException("Exception thrown from readObject() on " + klass + ": " + exception.getClass().getName()); } catch (Exception x) { - throw new IOException ("Failure invoking readObject() on " + + throw new IOException("Failure invoking readObject() on " + klass + ": " + x.getClass().getName()); } @@ -1833,13 +1840,13 @@ public class ObjectInputStream extends InputStream * @throws InvalidClassException if the specified field has not the required type. * @throws IOException if there is no field of that name in the specified class. */ - private void setBooleanField (Object obj, Class klass, String field_name, + private void setBooleanField(Object obj, Class klass, String field_name, boolean val) throws IOException, InvalidClassException { try { - Field f = getField (klass, field_name); - f.setBoolean (obj, val); + Field f = getField(klass, field_name); + f.setBoolean(obj, val); } catch (IllegalArgumentException _) { @@ -1861,13 +1868,13 @@ public class ObjectInputStream extends InputStream * @throws InvalidClassException if the specified field has not the required type. * @throws IOException if there is no field of that name in the specified class. */ - private void setByteField (Object obj, Class klass, String field_name, + private void setByteField(Object obj, Class klass, String field_name, byte val) throws IOException, InvalidClassException { try { - Field f = getField (klass, field_name); - f.setByte (obj, val); + Field f = getField(klass, field_name); + f.setByte(obj, val); } catch (IllegalArgumentException _) { @@ -1889,13 +1896,13 @@ public class ObjectInputStream extends InputStream * @throws InvalidClassException if the specified field has not the required type. * @throws IOException if there is no field of that name in the specified class. */ - private void setCharField (Object obj, Class klass, String field_name, + private void setCharField(Object obj, Class klass, String field_name, char val) throws IOException, InvalidClassException { try { - Field f = getField (klass, field_name); - f.setChar (obj, val); + Field f = getField(klass, field_name); + f.setChar(obj, val); } catch (IllegalArgumentException _) { @@ -1917,13 +1924,13 @@ public class ObjectInputStream extends InputStream * @throws InvalidClassException if the specified field has not the required type. * @throws IOException if there is no field of that name in the specified class. */ - private void setDoubleField (Object obj, Class klass, String field_name, + private void setDoubleField(Object obj, Class klass, String field_name, double val) throws IOException, InvalidClassException { try { - Field f = getField (klass, field_name); - f.setDouble (obj, val); + Field f = getField(klass, field_name); + f.setDouble(obj, val); } catch (IllegalArgumentException _) { @@ -1945,13 +1952,13 @@ public class ObjectInputStream extends InputStream * @throws InvalidClassException if the specified field has not the required type. * @throws IOException if there is no field of that name in the specified class. */ - private void setFloatField (Object obj, Class klass, String field_name, + private void setFloatField(Object obj, Class klass, String field_name, float val) throws IOException, InvalidClassException { try { - Field f = getField (klass, field_name); - f.setFloat (obj, val); + Field f = getField(klass, field_name); + f.setFloat(obj, val); } catch (IllegalArgumentException _) { @@ -1973,13 +1980,13 @@ public class ObjectInputStream extends InputStream * @throws InvalidClassException if the specified field has not the required type. * @throws IOException if there is no field of that name in the specified class. */ - private void setIntField (Object obj, Class klass, String field_name, + private void setIntField(Object obj, Class klass, String field_name, int val) throws IOException, InvalidClassException { try { - Field f = getField (klass, field_name); - f.setInt (obj, val); + Field f = getField(klass, field_name); + f.setInt(obj, val); } catch (IllegalArgumentException _) { @@ -2001,13 +2008,13 @@ public class ObjectInputStream extends InputStream * @throws InvalidClassException if the specified field has not the required type. * @throws IOException if there is no field of that name in the specified class. */ - private void setLongField (Object obj, Class klass, String field_name, + private void setLongField(Object obj, Class klass, String field_name, long val) throws IOException, InvalidClassException { try { - Field f = getField (klass, field_name); - f.setLong (obj, val); + Field f = getField(klass, field_name); + f.setLong(obj, val); } catch (IllegalArgumentException _) { @@ -2029,13 +2036,13 @@ public class ObjectInputStream extends InputStream * @throws InvalidClassException if the specified field has not the required type. * @throws IOException if there is no field of that name in the specified class. */ - private void setShortField (Object obj, Class klass, String field_name, + private void setShortField(Object obj, Class klass, String field_name, short val) throws IOException, InvalidClassException { try { - Field f = getField (klass, field_name); - f.setShort (obj, val); + Field f = getField(klass, field_name); + f.setShort(obj, val); } catch (IllegalArgumentException _) { @@ -2057,25 +2064,26 @@ public class ObjectInputStream extends InputStream * @throws InvalidClassException if the specified field has not the required type. * @throws IOException if there is no field of that name in the specified class. */ - private void setObjectField (Object obj, Class klass, String field_name, + private void setObjectField(Object obj, Class klass, String field_name, String type_code, Object val) throws IOException, InvalidClassException { try { - Field f = getField (klass, field_name); + Field f = getField(klass, field_name); ObjectStreamField of = new ObjectStreamField(field_name, f.getType()); if (of.getTypeString() == null || !of.getTypeString().equals(type_code)) throw new InvalidClassException("incompatible field type for " + klass.getName() + "." + field_name); - f.set (obj, val); + f.set(obj, val); } catch (InvalidClassException e) { throw e; } catch (Exception _) - {} + { + } } private static final int BUFFER_SIZE = 1024; diff --git a/libjava/java/io/ObjectOutputStream.java b/libjava/java/io/ObjectOutputStream.java index 0244e2d..8f991f0 100644 --- a/libjava/java/io/ObjectOutputStream.java +++ b/libjava/java/io/ObjectOutputStream.java @@ -132,18 +132,18 @@ public class ObjectOutputStream extends OutputStream */ public ObjectOutputStream (OutputStream out) throws IOException { - realOutput = new DataOutputStream (out); + realOutput = new DataOutputStream(out); blockData = new byte[ BUFFER_SIZE ]; blockDataCount = 0; - blockDataOutput = new DataOutputStream (this); - setBlockDataMode (true); + blockDataOutput = new DataOutputStream(this); + setBlockDataMode(true); replacementEnabled = false; isSerializing = false; nextOID = baseWireHandle; - OIDLookupTable = new Hashtable (); + OIDLookupTable = new Hashtable(); protocolVersion = defaultProtocolVersion; useSubclassMethod = false; - writeStreamHeader (); + writeStreamHeader(); } /** @@ -165,16 +165,16 @@ public class ObjectOutputStream extends OutputStream * @exception IOException Exception from underlying * <code>OutputStream</code>. */ - public final void writeObject (Object obj) throws IOException + public final void writeObject(Object obj) throws IOException { if (useSubclassMethod) { - writeObjectOverride (obj); + writeObjectOverride(obj); return; } boolean was_serializing = isSerializing; - boolean old_mode = setBlockDataMode (false); + boolean old_mode = setBlockDataMode(false); try { isSerializing = true; @@ -185,49 +185,49 @@ public class ObjectOutputStream extends OutputStream { if (obj == null) { - realOutput.writeByte (TC_NULL); + realOutput.writeByte(TC_NULL); break; } - Integer handle = findHandle (obj); + Integer handle = findHandle(obj); if (handle != null) { - realOutput.writeByte (TC_REFERENCE); - realOutput.writeInt (handle.intValue ()); + realOutput.writeByte(TC_REFERENCE); + realOutput.writeInt(handle.intValue()); break; } if (obj instanceof Class) { Class cl = (Class)obj; - ObjectStreamClass osc = ObjectStreamClass.lookupForClassObject (cl); - assignNewHandle (obj); - realOutput.writeByte (TC_CLASS); + ObjectStreamClass osc = ObjectStreamClass.lookupForClassObject(cl); + assignNewHandle(obj); + realOutput.writeByte(TC_CLASS); if (!osc.isProxyClass) { writeObject (osc); } else { - realOutput.writeByte (TC_PROXYCLASSDESC); + 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); + boolean oldmode = setBlockDataMode(true); annotateProxyClass(cl); - setBlockDataMode (oldmode); + setBlockDataMode(oldmode); realOutput.writeByte(TC_ENDBLOCKDATA); - writeObject (osc.getSuper()); + writeObject(osc.getSuper()); } break; } if (obj instanceof ObjectStreamClass) { - writeClassDescriptor ((ObjectStreamClass) obj); + writeClassDescriptor((ObjectStreamClass) obj); break; } @@ -235,7 +235,7 @@ public class ObjectOutputStream extends OutputStream && ! replaceDone) { replacedObject = obj; - + if (obj instanceof Serializable) { Method m = null; @@ -247,7 +247,7 @@ public class ObjectOutputStream extends OutputStream // 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[] {}); + obj = m.invoke(obj, new Object[] {}); } catch (NoSuchMethodException ignore) { @@ -259,55 +259,55 @@ public class ObjectOutputStream extends OutputStream { } } - + if (replacementEnabled) - obj = replaceObject (obj); - + obj = replaceObject(obj); + replaceDone = true; continue; } if (obj instanceof String) { - realOutput.writeByte (TC_STRING); - assignNewHandle (obj); - realOutput.writeUTF ((String)obj); + realOutput.writeByte(TC_STRING); + assignNewHandle(obj); + realOutput.writeUTF((String)obj); break; } - Class clazz = obj.getClass (); - ObjectStreamClass osc = ObjectStreamClass.lookupForClassObject (clazz); + Class clazz = obj.getClass(); + ObjectStreamClass osc = ObjectStreamClass.lookupForClassObject(clazz); if (osc == null) - throw new NotSerializableException (clazz.getName ()); - + throw new NotSerializableException(clazz.getName()); + if (clazz.isArray ()) { - realOutput.writeByte (TC_ARRAY); - writeObject (osc); - assignNewHandle (obj); - writeArraySizeAndElements (obj, clazz.getComponentType ()); + realOutput.writeByte(TC_ARRAY); + writeObject(osc); + assignNewHandle(obj); + writeArraySizeAndElements(obj, clazz.getComponentType()); break; } - - realOutput.writeByte (TC_OBJECT); - writeObject (osc); + + realOutput.writeByte(TC_OBJECT); + writeObject(osc); if (replaceDone) - assignNewHandle (replacedObject); + assignNewHandle(replacedObject); else - assignNewHandle (obj); + assignNewHandle(obj); if (obj instanceof Externalizable) { if (protocolVersion == PROTOCOL_VERSION_2) - setBlockDataMode (true); - - ((Externalizable)obj).writeExternal (this); - + setBlockDataMode(true); + + ((Externalizable)obj).writeExternal(this); + if (protocolVersion == PROTOCOL_VERSION_2) { - setBlockDataMode (false); - realOutput.writeByte (TC_ENDBLOCKDATA); + setBlockDataMode(false); + realOutput.writeByte(TC_ENDBLOCKDATA); } break; @@ -317,22 +317,22 @@ public class ObjectOutputStream extends OutputStream { currentObject = obj; ObjectStreamClass[] hierarchy = - ObjectStreamClass.getObjectStreamClasses (clazz); - - for (int i=0; i < hierarchy.length; i++) + ObjectStreamClass.getObjectStreamClasses(clazz); + + for (int i = 0; i < hierarchy.length; i++) { currentObjectStreamClass = hierarchy[i]; - + fieldsAlreadyWritten = false; - if (currentObjectStreamClass.hasWriteMethod ()) + if (currentObjectStreamClass.hasWriteMethod()) { - setBlockDataMode (true); - callWriteMethod (obj, currentObjectStreamClass); - setBlockDataMode (false); - realOutput.writeByte (TC_ENDBLOCKDATA); + setBlockDataMode(true); + callWriteMethod(obj, currentObjectStreamClass); + setBlockDataMode(false); + realOutput.writeByte(TC_ENDBLOCKDATA); } else - writeFields (obj, currentObjectStreamClass); + writeFields(obj, currentObjectStreamClass); } currentObject = null; @@ -341,7 +341,7 @@ public class ObjectOutputStream extends OutputStream break; } - throw new NotSerializableException (clazz.getName ()); + throw new NotSerializableException(clazz.getName ()); } // end pseudo-loop } catch (ObjectStreamException ose) @@ -351,243 +351,247 @@ public class ObjectOutputStream extends OutputStream } catch (IOException e) { - realOutput.writeByte (TC_EXCEPTION); - reset (true); + realOutput.writeByte(TC_EXCEPTION); + reset(true); - setBlockDataMode (false); + setBlockDataMode(false); try { - writeObject (e); + writeObject(e); } catch (IOException ioe) { - throw new StreamCorruptedException ("Exception " + ioe + " thrown while exception ("+e+") was being written to stream."); + throw new StreamCorruptedException + ("Exception " + ioe + " thrown while exception was being written to stream."); } reset (true); + } finally { isSerializing = was_serializing; - setBlockDataMode (old_mode); + setBlockDataMode(old_mode); } } - protected void writeClassDescriptor (ObjectStreamClass osc) throws IOException + protected void writeClassDescriptor(ObjectStreamClass osc) throws IOException { - realOutput.writeByte (TC_CLASSDESC); - realOutput.writeUTF (osc.getName ()); - realOutput.writeLong (osc.getSerialVersionUID ()); - assignNewHandle (osc); + realOutput.writeByte(TC_CLASSDESC); + realOutput.writeUTF(osc.getName()); + realOutput.writeLong(osc.getSerialVersionUID()); + assignNewHandle(osc); - int flags = osc.getFlags (); + int flags = osc.getFlags(); if (protocolVersion == PROTOCOL_VERSION_2 - && osc.isExternalizable ()) + && osc.isExternalizable()) flags |= SC_BLOCK_DATA; - realOutput.writeByte (flags); + realOutput.writeByte(flags); ObjectStreamField[] fields = osc.fields; - realOutput.writeShort (fields.length); + realOutput.writeShort(fields.length); ObjectStreamField field; - for (int i=0; i < fields.length; i++) + for (int i = 0; i < fields.length; i++) { field = fields[i]; - realOutput.writeByte (field.getTypeCode ()); - realOutput.writeUTF (field.getName ()); + realOutput.writeByte(field.getTypeCode ()); + realOutput.writeUTF(field.getName ()); - if (! field.isPrimitive ()) - writeObject (field.getTypeString ()); + if (! field.isPrimitive()) + writeObject(field.getTypeString()); } - boolean oldmode = setBlockDataMode (true); - annotateClass (osc.forClass ()); - setBlockDataMode (oldmode); - realOutput.writeByte (TC_ENDBLOCKDATA); + boolean oldmode = setBlockDataMode(true); + annotateClass(osc.forClass()); + setBlockDataMode(oldmode); + realOutput.writeByte(TC_ENDBLOCKDATA); - if (osc.isSerializable() - || osc.isExternalizable()) - writeObject (osc.getSuper ()); + if (osc.isSerializable() || osc.isExternalizable()) + writeObject(osc.getSuper()); else - writeObject (null); + writeObject(null); } /** - Writes the current objects non-transient, non-static fields from - the current class to the underlying output stream. - - This method is intended to be called from within a object's - <code>private void writeObject (ObjectOutputStream)</code> - method. - - @exception NotActiveException This method was called from a - context other than from the current object's and current class's - <code>private void writeObject (ObjectOutputStream)</code> - method. - - @exception IOException Exception from underlying - <code>OutputStream</code>. - */ - public void defaultWriteObject () + * Writes the current objects non-transient, non-static fields from + * the current class to the underlying output stream. + * + * This method is intended to be called from within a object's + * <code>private void writeObject (ObjectOutputStream)</code> + * method. + * + * @exception NotActiveException This method was called from a + * context other than from the current object's and current class's + * <code>private void writeObject (ObjectOutputStream)</code> + * method. + * + * @exception IOException Exception from underlying + * <code>OutputStream</code>. + */ + public void defaultWriteObject() throws IOException, NotActiveException { - markFieldsWritten (); - writeFields (currentObject, currentObjectStreamClass); + markFieldsWritten(); + writeFields(currentObject, currentObjectStreamClass); } - private void markFieldsWritten () throws IOException + private void markFieldsWritten() throws IOException { if (currentObject == null || currentObjectStreamClass == null) - throw new NotActiveException ("defaultWriteObject called by non-active class and/or object"); + throw new NotActiveException + ("defaultWriteObject called by non-active class and/or object"); if (fieldsAlreadyWritten) - throw new IOException ("Only one of writeFields and defaultWriteObject may be called, and it may only be called once"); + throw new IOException + ("Only one of putFields and defaultWriteObject may be called, and it may only be called once"); fieldsAlreadyWritten = true; } - /** - Resets stream to state equivalent to the state just after it was - constructed. - - Causes all objects previously written to the stream to be - forgotten. A notification of this reset is also written to the - underlying stream. - - @exception IOException Exception from underlying - <code>OutputStream</code> or reset called while serialization is - in progress. - */ - public void reset () throws IOException + * Resets stream to state equivalent to the state just after it was + * constructed. + * + * Causes all objects previously written to the stream to be + * forgotten. A notification of this reset is also written to the + * underlying stream. + * + * @exception IOException Exception from underlying + * <code>OutputStream</code> or reset called while serialization is + * in progress. + */ + public void reset() throws IOException { - reset (false); + reset(false); } - private void reset (boolean internal) throws IOException + private void reset(boolean internal) throws IOException { if (!internal) { if (isSerializing) - throw new IOException ("Reset called while serialization in progress"); + throw new IOException("Reset called while serialization in progress"); - realOutput.writeByte (TC_RESET); + realOutput.writeByte(TC_RESET); } - - clearHandles (); + + clearHandles(); } /** - Informs this <code>ObjectOutputStream</code> to write data - according to the specified protocol. There are currently two - different protocols, specified by <code>PROTOCOL_VERSION_1</code> - and <code>PROTOCOL_VERSION_2</code>. This implementation writes - data using <code>PROTOCOL_VERSION_2</code> by default, as is done - by the JDK 1.2. - - A non-portable method, <code>setDefaultProtocolVersion (int - version)</code> is provided to change the default protocol - version. - - For an explination of the differences beween the two protocols - see XXX: the Java ObjectSerialization Specification. - - @exception IOException if <code>version</code> is not a valid - protocol - - @see #setDefaultProtocolVersion(int) - */ - public void useProtocolVersion (int version) throws IOException + * Informs this <code>ObjectOutputStream</code> to write data + * according to the specified protocol. There are currently two + * different protocols, specified by <code>PROTOCOL_VERSION_1</code> + * and <code>PROTOCOL_VERSION_2</code>. This implementation writes + * data using <code>PROTOCOL_VERSION_2</code> by default, as is done + * by the JDK 1.2. + * + * A non-portable method, <code>setDefaultProtocolVersion (int + * version)</code> is provided to change the default protocol + * version. + * + * For an explination of the differences beween the two protocols + * see XXX: the Java ObjectSerialization Specification. + * + * @exception IOException if <code>version</code> is not a valid + * protocol + * + * @see #setDefaultProtocolVersion(int) + */ + public void useProtocolVersion(int version) throws IOException { if (version != PROTOCOL_VERSION_1 && version != PROTOCOL_VERSION_2) - throw new IOException ("Invalid protocol version requested."); - + throw new IOException("Invalid protocol version requested."); + protocolVersion = version; } /** - <em>GNU $classpath specific</em> - - Changes the default stream protocol used by all - <code>ObjectOutputStream</code>s. There are currently two - different protocols, specified by <code>PROTOCOL_VERSION_1</code> - and <code>PROTOCOL_VERSION_2</code>. The default default is - <code>PROTOCOL_VERSION_1</code>. - - @exception IOException if <code>version</code> is not a valid - protocol - - @see #useProtocolVersion(int) - */ - public static void setDefaultProtocolVersion (int version) + * <em>GNU $classpath specific</em> + * + * Changes the default stream protocol used by all + * <code>ObjectOutputStream</code>s. There are currently two + * different protocols, specified by <code>PROTOCOL_VERSION_1</code> + * and <code>PROTOCOL_VERSION_2</code>. The default default is + * <code>PROTOCOL_VERSION_1</code>. + * + * @exception IOException if <code>version</code> is not a valid + * protocol + * + * @see #useProtocolVersion(int) + */ + public static void setDefaultProtocolVersion(int version) throws IOException { if (version != PROTOCOL_VERSION_1 && version != PROTOCOL_VERSION_2) - throw new IOException ("Invalid protocol version requested."); + throw new IOException("Invalid protocol version requested."); defaultProtocolVersion = version; } /** - An empty hook that allows subclasses to write extra information - about classes to the stream. This method is called the first - time each class is seen, and after all of the standard - information about the class has been written. - - @exception IOException Exception from underlying - <code>OutputStream</code>. - - @see ObjectInputStream#resolveClass(java.io.ObjectStreamClass) - */ - protected void annotateClass (Class cl) throws IOException - {} + * An empty hook that allows subclasses to write extra information + * about classes to the stream. This method is called the first + * time each class is seen, and after all of the standard + * information about the class has been written. + * + * @exception IOException Exception from underlying + * <code>OutputStream</code>. + * + * @see ObjectInputStream#resolveClass(java.io.ObjectStreamClass) + */ + protected void annotateClass(Class cl) throws IOException + { + } protected void annotateProxyClass(Class cl) throws IOException - {} + { + } /** - Allows subclasses to replace objects that are written to the - stream with other objects to be written in their place. This - method is called the first time each object is encountered - (modulo reseting of the stream). - - This method must be enabled before it will be called in the - serialization process. - - @exception IOException Exception from underlying - <code>OutputStream</code>. - - @see #enableReplaceObject(boolean) - */ - protected Object replaceObject (Object obj) throws IOException + * Allows subclasses to replace objects that are written to the + * stream with other objects to be written in their place. This + * method is called the first time each object is encountered + * (modulo reseting of the stream). + * + * This method must be enabled before it will be called in the + * serialization process. + * + * @exception IOException Exception from underlying + * <code>OutputStream</code>. + * + * @see #enableReplaceObject(boolean) + */ + protected Object replaceObject(Object obj) throws IOException { return obj; } /** - If <code>enable</code> is <code>true</code> and this object is - trusted, then <code>replaceObject (Object)</code> will be called - in subsequent calls to <code>writeObject (Object)</code>. - Otherwise, <code>replaceObject (Object)</code> will not be called. - - @exception SecurityException This class is not trusted. - */ - protected boolean enableReplaceObject (boolean enable) + * If <code>enable</code> is <code>true</code> and this object is + * trusted, then <code>replaceObject (Object)</code> will be called + * in subsequent calls to <code>writeObject (Object)</code>. + * Otherwise, <code>replaceObject (Object)</code> will not be called. + * + * @exception SecurityException This class is not trusted. + */ + protected boolean enableReplaceObject(boolean enable) throws SecurityException { if (enable) { - SecurityManager sm = System.getSecurityManager (); + SecurityManager sm = System.getSecurityManager(); if (sm != null) - sm.checkPermission (new SerializablePermission ("enableSubstitution")); + sm.checkPermission(new SerializablePermission("enableSubstitution")); } boolean old_val = replacementEnabled; @@ -597,20 +601,18 @@ public class ObjectOutputStream extends OutputStream /** - Writes stream magic and stream version information to the - underlying stream. - - @exception IOException Exception from underlying - <code>OutputStream</code>. - */ - protected void writeStreamHeader () throws IOException + * Writes stream magic and stream version information to the + * underlying stream. + * + * @exception IOException Exception from underlying + * <code>OutputStream</code>. + */ + protected void writeStreamHeader() throws IOException { - realOutput.writeShort (STREAM_MAGIC); - realOutput.writeShort (STREAM_VERSION); + realOutput.writeShort(STREAM_MAGIC); + realOutput.writeShort(STREAM_VERSION); } - - /** * Protected constructor that allows subclasses to override * serialization. This constructor should be called by subclasses @@ -622,11 +624,11 @@ public class ObjectOutputStream extends OutputStream * * @see #writeObjectOverride(Object) */ - protected ObjectOutputStream () throws IOException, SecurityException + protected ObjectOutputStream() throws IOException, SecurityException { SecurityManager sec_man = System.getSecurityManager (); if (sec_man != null) - sec_man.checkPermission (SUBCLASS_IMPLEMENTATION_PERMISSION); + sec_man.checkPermission(SUBCLASS_IMPLEMENTATION_PERMISSION); useSubclassMethod = true; } @@ -643,10 +645,11 @@ public class ObjectOutputStream extends OutputStream * @exception NotActiveException Subclass has arranged for this * method to be called, but did not implement this method. */ - protected void writeObjectOverride (Object obj) throws NotActiveException, + protected void writeObjectOverride(Object obj) throws NotActiveException, IOException { - throw new NotActiveException ("Subclass of ObjectOutputStream must implement writeObjectOverride"); + throw new NotActiveException + ("Subclass of ObjectOutputStream must implement writeObjectOverride"); } @@ -658,48 +661,48 @@ public class ObjectOutputStream extends OutputStream if (writeDataAsBlocks) { if (blockDataCount == BUFFER_SIZE) - drain (); + drain(); blockData[ blockDataCount++ ] = (byte)data; } else - realOutput.write (data); + realOutput.write(data); } /** * @see DataOutputStream#write(byte[]) */ - public void write (byte[] b) throws IOException + public void write(byte[] b) throws IOException { - write (b, 0, b.length); + write(b, 0, b.length); } /** * @see DataOutputStream#write(byte[],int,int) */ - public void write (byte[] b, int off, int len) throws IOException + public void write(byte[] b, int off, int len) throws IOException { if (writeDataAsBlocks) { if (len < 0) - throw new IndexOutOfBoundsException (); + throw new IndexOutOfBoundsException(); if (blockDataCount + len < BUFFER_SIZE) { - System.arraycopy (b, off, blockData, blockDataCount, len); + System.arraycopy(b, off, blockData, blockDataCount, len); blockDataCount += len; } else { - drain (); - writeBlockDataHeader (len); - realOutput.write (b, off, len); + drain(); + writeBlockDataHeader(len); + realOutput.write(b, off, len); } } else - realOutput.write (b, off, len); + realOutput.write(b, off, len); } @@ -708,8 +711,8 @@ public class ObjectOutputStream extends OutputStream */ public void flush () throws IOException { - drain (); - realOutput.flush (); + drain(); + realOutput.flush(); } @@ -720,14 +723,14 @@ public class ObjectOutputStream extends OutputStream * @exception IOException Exception from underlying * <code>OutputStream</code>. */ - protected void drain () throws IOException + protected void drain() throws IOException { if (blockDataCount == 0) return; if (writeDataAsBlocks) - writeBlockDataHeader (blockDataCount); - realOutput.write (blockData, 0, blockDataCount); + writeBlockDataHeader(blockDataCount); + realOutput.write(blockData, 0, blockDataCount); blockDataCount = 0; } @@ -735,28 +738,28 @@ public class ObjectOutputStream extends OutputStream /** * @see java.io.DataOutputStream#close () */ - public void close () throws IOException + public void close() throws IOException { - flush (); - realOutput.close (); + flush(); + realOutput.close(); } /** * @see java.io.DataOutputStream#writeBoolean (boolean) */ - public void writeBoolean (boolean data) throws IOException + public void writeBoolean(boolean data) throws IOException { - blockDataOutput.writeBoolean (data); + blockDataOutput.writeBoolean(data); } /** * @see java.io.DataOutputStream#writeByte (int) */ - public void writeByte (int data) throws IOException + public void writeByte(int data) throws IOException { - blockDataOutput.writeByte (data); + blockDataOutput.writeByte(data); } @@ -765,79 +768,79 @@ public class ObjectOutputStream extends OutputStream */ public void writeShort (int data) throws IOException { - blockDataOutput.writeShort (data); + blockDataOutput.writeShort(data); } /** * @see java.io.DataOutputStream#writeChar (int) */ - public void writeChar (int data) throws IOException + public void writeChar(int data) throws IOException { - blockDataOutput.writeChar (data); + blockDataOutput.writeChar(data); } /** * @see java.io.DataOutputStream#writeInt (int) */ - public void writeInt (int data) throws IOException + public void writeInt(int data) throws IOException { - blockDataOutput.writeInt (data); + blockDataOutput.writeInt(data); } /** * @see java.io.DataOutputStream#writeLong (long) */ - public void writeLong (long data) throws IOException + public void writeLong(long data) throws IOException { - blockDataOutput.writeLong (data); + blockDataOutput.writeLong(data); } /** * @see java.io.DataOutputStream#writeFloat (float) */ - public void writeFloat (float data) throws IOException + public void writeFloat(float data) throws IOException { - blockDataOutput.writeFloat (data); + blockDataOutput.writeFloat(data); } /** * @see java.io.DataOutputStream#writeDouble (double) */ - public void writeDouble (double data) throws IOException + public void writeDouble(double data) throws IOException { - blockDataOutput.writeDouble (data); + blockDataOutput.writeDouble(data); } /** * @see java.io.DataOutputStream#writeBytes (java.lang.String) */ - public void writeBytes (String data) throws IOException + public void writeBytes(String data) throws IOException { - blockDataOutput.writeBytes (data); + blockDataOutput.writeBytes(data); } /** * @see java.io.DataOutputStream#writeChars (java.lang.String) */ - public void writeChars (String data) throws IOException + public void writeChars(String data) throws IOException { - dataOutput.writeChars (data); + dataOutput.writeChars(data); } /** * @see java.io.DataOutputStream#writeUTF (java.lang.String) */ - public void writeUTF (String data) throws IOException + public void writeUTF(String data) throws IOException { - dataOutput.writeUTF (data); + dataOutput.writeUTF(data); } @@ -865,7 +868,7 @@ public class ObjectOutputStream extends OutputStream public abstract void write (ObjectOutput out) throws IOException; } - public PutField putFields () throws IOException + public PutField putFields() throws IOException { if (currentPutField == null) { @@ -1008,183 +1011,184 @@ public class ObjectOutputStream extends OutputStream } - public void writeFields () throws IOException + public void writeFields() throws IOException { if (currentPutField == null) - throw new NotActiveException ("writeFields can only be called after putFields has been called"); + throw new NotActiveException("writeFields can only be called after putFields has been called"); // putFields may be called more than once, but not writeFields. markFieldsWritten(); - currentPutField.write (this); + currentPutField.write(this); currentPutField = null; } // write out the block-data buffer, picking the correct header // depending on the size of the buffer - private void writeBlockDataHeader (int size) throws IOException + private void writeBlockDataHeader(int size) throws IOException { if (size < 256) { - realOutput.writeByte (TC_BLOCKDATA); - realOutput.write (size); + realOutput.writeByte(TC_BLOCKDATA); + realOutput.write(size); } else { - realOutput.writeByte (TC_BLOCKDATALONG); - realOutput.writeInt (size); + realOutput.writeByte(TC_BLOCKDATALONG); + realOutput.writeInt(size); } } // lookup the handle for OBJ, return null if OBJ doesn't have a // handle yet - private Integer findHandle (Object obj) + private Integer findHandle(Object obj) { - return (Integer)OIDLookupTable.get (new ObjectIdentityWrapper (obj)); + return (Integer)OIDLookupTable.get(new ObjectIdentityWrapper(obj)); } // assigns the next availible handle to OBJ - private int assignNewHandle (Object obj) + private int assignNewHandle(Object obj) { - OIDLookupTable.put (new ObjectIdentityWrapper (obj), - new Integer (nextOID)); + OIDLookupTable.put(new ObjectIdentityWrapper(obj), + new Integer(nextOID)); return nextOID++; } // resets mapping from objects to handles - private void clearHandles () + private void clearHandles() { nextOID = baseWireHandle; - OIDLookupTable.clear (); + OIDLookupTable.clear(); } // write out array size followed by each element of the array - private void writeArraySizeAndElements (Object array, Class clazz) + private void writeArraySizeAndElements(Object array, Class clazz) throws IOException { - int length = Array.getLength (array); + int length = Array.getLength(array); - if (clazz.isPrimitive ()) + if (clazz.isPrimitive()) { if (clazz == Boolean.TYPE) { boolean[] cast_array = (boolean[])array; realOutput.writeInt (length); - for (int i=0; i < length; i++) - realOutput.writeBoolean (cast_array[i]); + for (int i = 0; i < length; i++) + realOutput.writeBoolean(cast_array[i]); return; } if (clazz == Byte.TYPE) { byte[] cast_array = (byte[])array; - realOutput.writeInt (length); + realOutput.writeInt(length); realOutput.write(cast_array, 0, length); return; } if (clazz == Character.TYPE) { char[] cast_array = (char[])array; - realOutput.writeInt (length); - for (int i=0; i < length; i++) - realOutput.writeChar (cast_array[i]); + realOutput.writeInt(length); + for (int i = 0; i < length; i++) + realOutput.writeChar(cast_array[i]); return; } if (clazz == Double.TYPE) { double[] cast_array = (double[])array; - realOutput.writeInt (length); - for (int i=0; i < length; i++) - realOutput.writeDouble (cast_array[i]); + realOutput.writeInt(length); + for (int i = 0; i < length; i++) + realOutput.writeDouble(cast_array[i]); return; } if (clazz == Float.TYPE) { float[] cast_array = (float[])array; - realOutput.writeInt (length); - for (int i=0; i < length; i++) - realOutput.writeFloat (cast_array[i]); + realOutput.writeInt(length); + for (int i = 0; i < length; i++) + realOutput.writeFloat(cast_array[i]); return; } if (clazz == Integer.TYPE) { int[] cast_array = (int[])array; - realOutput.writeInt (length); - for (int i=0; i < length; i++) - realOutput.writeInt (cast_array[i]); + realOutput.writeInt(length); + for (int i = 0; i < length; i++) + realOutput.writeInt(cast_array[i]); return; } if (clazz == Long.TYPE) { long[] cast_array = (long[])array; realOutput.writeInt (length); - for (int i=0; i < length; i++) - realOutput.writeLong (cast_array[i]); + for (int i = 0; i < length; i++) + realOutput.writeLong(cast_array[i]); return; } if (clazz == Short.TYPE) { short[] cast_array = (short[])array; realOutput.writeInt (length); - for (int i=0; i < length; i++) - realOutput.writeShort (cast_array[i]); + for (int i = 0; i < length; i++) + realOutput.writeShort(cast_array[i]); return; } } else { Object[] cast_array = (Object[])array; - realOutput.writeInt (length); - for (int i=0; i < length; i++) - writeObject (cast_array[i]); + realOutput.writeInt(length); + for (int i = 0; i < length; i++) + writeObject(cast_array[i]); } } // writes out FIELDS of OBJECT for the specified ObjectStreamClass. // FIELDS are already in canonical order. - private void writeFields (Object obj, ObjectStreamClass osc) + private void writeFields(Object obj, ObjectStreamClass osc) throws IOException { ObjectStreamField[] fields = osc.fields; - boolean oldmode = setBlockDataMode (false); + boolean oldmode = setBlockDataMode(false); String field_name; Class type; - for (int i=0; i < fields.length; i++) + + for (int i = 0; i < fields.length; i++) { - field_name = fields[i].getName (); - type = fields[i].getType (); + field_name = fields[i].getName(); + type = fields[i].getType(); if (type == Boolean.TYPE) - realOutput.writeBoolean (getBooleanField (obj, osc.forClass(), field_name)); + realOutput.writeBoolean(getBooleanField(obj, osc.forClass(), field_name)); else if (type == Byte.TYPE) - realOutput.writeByte (getByteField (obj, osc.forClass(), field_name)); + realOutput.writeByte(getByteField(obj, osc.forClass(), field_name)); else if (type == Character.TYPE) - realOutput.writeChar (getCharField (obj, osc.forClass(), field_name)); + realOutput.writeChar(getCharField(obj, osc.forClass(), field_name)); else if (type == Double.TYPE) - realOutput.writeDouble (getDoubleField (obj, osc.forClass(), field_name)); + realOutput.writeDouble(getDoubleField(obj, osc.forClass(), field_name)); else if (type == Float.TYPE) - realOutput.writeFloat (getFloatField (obj, osc.forClass(), field_name)); + realOutput.writeFloat(getFloatField(obj, osc.forClass(), field_name)); else if (type == Integer.TYPE) - realOutput.writeInt (getIntField (obj, osc.forClass(), field_name)); + realOutput.writeInt(getIntField(obj, osc.forClass(), field_name)); else if (type == Long.TYPE) - realOutput.writeLong (getLongField (obj, osc.forClass(), field_name)); + realOutput.writeLong(getLongField(obj, osc.forClass(), field_name)); else if (type == Short.TYPE) - realOutput.writeShort (getShortField (obj, osc.forClass(), field_name)); + realOutput.writeShort(getShortField(obj, osc.forClass(), field_name)); else - writeObject (getObjectField (obj, osc.forClass(), field_name, - fields[i].getTypeString ())); + writeObject(getObjectField(obj, osc.forClass(), field_name, + fields[i].getTypeString ())); } - setBlockDataMode (oldmode); + setBlockDataMode(oldmode); } // Toggles writing primitive data to block-data buffer. - private boolean setBlockDataMode (boolean on) throws IOException + private boolean setBlockDataMode(boolean on) throws IOException { if (on == writeDataAsBlocks) return on; @@ -1202,16 +1206,16 @@ public class ObjectOutputStream extends OutputStream } - private void callWriteMethod (Object obj, ObjectStreamClass osc) + private void callWriteMethod(Object obj, ObjectStreamClass osc) throws IOException { Class klass = osc.forClass(); try { Class classArgs[] = {ObjectOutputStream.class}; - Method m = getMethod (klass, "writeObject", classArgs); + Method m = getMethod(klass, "writeObject", classArgs); Object args[] = {this}; - m.invoke (obj, args); + m.invoke(obj, args); } catch (NoSuchMethodException nsme) { @@ -1227,34 +1231,34 @@ public class ObjectOutputStream extends OutputStream throw (IOException) exception; IOException ioe - = new IOException ("Exception thrown from writeObject() on " + - klass + ": " + exception.getClass().getName()); + = new IOException("Exception thrown from writeObject() on " + + klass + ": " + exception.getClass().getName()); ioe.initCause(exception); throw ioe; } catch (Exception x) { IOException ioe - = new IOException ("Failure invoking writeObject() on " + - klass + ": " + x.getClass().getName()); + = new IOException("Failure invoking writeObject() on " + + klass + ": " + x.getClass().getName()); ioe.initCause(x); throw ioe; } } - private boolean getBooleanField (Object obj, Class klass, String field_name) + private boolean getBooleanField(Object obj, Class klass, String field_name) throws IOException { try { - Field f = getField (klass, field_name); - boolean b = f.getBoolean (obj); + Field f = getField(klass, field_name); + boolean b = f.getBoolean(obj); return b; } catch (Exception _) { - throw new IOException ("Unexpected Exception "+_); - } + throw new IOException("Unexpected exception " + _); + } } private byte getByteField (Object obj, Class klass, String field_name) @@ -1268,7 +1272,7 @@ public class ObjectOutputStream extends OutputStream } catch (Exception _) { - throw new IOException ("Unexpected Exception "+_); + throw new IOException("Unexpected exception " + _); } } @@ -1283,7 +1287,7 @@ public class ObjectOutputStream extends OutputStream } catch (Exception _) { - throw new IOException ("Unexpected Exception "+_); + throw new IOException("Unexpected exception " + _); } } @@ -1298,7 +1302,7 @@ public class ObjectOutputStream extends OutputStream } catch (Exception _) { - throw new IOException ("Unexpected Exception "+_); + throw new IOException("Unexpected exception " + _); } } @@ -1313,8 +1317,8 @@ public class ObjectOutputStream extends OutputStream } catch (Exception _) { - throw new IOException ("Unexpected Exception "+_); - } + throw new IOException("Unexpected exception " + _); + } } private int getIntField (Object obj, Class klass, String field_name) @@ -1328,8 +1332,8 @@ public class ObjectOutputStream extends OutputStream } catch (Exception _) { - throw new IOException ("Unexpected Exception "+_); - } + throw new IOException("Unexpected exception " + _); + } } private long getLongField (Object obj, Class klass, String field_name) @@ -1343,7 +1347,7 @@ public class ObjectOutputStream extends OutputStream } catch (Exception _) { - throw new IOException ("Unexpected Exception "+_); + throw new IOException("Unexpected exception " + _); } } @@ -1358,8 +1362,8 @@ public class ObjectOutputStream extends OutputStream } catch (Exception _) { - throw new IOException ("Unexpected Exception "+_); - } + throw new IOException("Unexpected exception " + _); + } } private Object getObjectField (Object obj, Class klass, String field_name, @@ -1372,9 +1376,9 @@ public class ObjectOutputStream extends OutputStream // FIXME: We should check the type_code here return o; } - catch (Exception _) + catch (Exception e) { - throw new IOException ("Unexpected Exception "+_); + throw new IOException (); } } @@ -1434,7 +1438,7 @@ public class ObjectOutputStream extends OutputStream { if (Configuration.INIT_LOAD_LIBRARY) { - System.loadLibrary ("javaio"); + System.loadLibrary("javaio"); } } } diff --git a/libjava/java/io/ObjectStreamClass.java b/libjava/java/io/ObjectStreamClass.java index 9d9d99d..5bd0e68 100644 --- a/libjava/java/io/ObjectStreamClass.java +++ b/libjava/java/io/ObjectStreamClass.java @@ -2,39 +2,39 @@ about serialized objects. Copyright (C) 1998, 1999, 2000, 2001, 2003 Free Software Foundation, Inc. -This file is part of GNU Classpath. + This file is part of GNU Classpath. -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. + GNU Classpath is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ + GNU Classpath is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNU Classpath; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. */ package java.io; @@ -61,23 +61,23 @@ import gnu.java.security.provider.Gnu; public class ObjectStreamClass implements Serializable { /** - Returns the <code>ObjectStreamClass</code> for <code>cl</code>. - If <code>cl</code> is null, or is not <code>Serializable</code>, - null is returned. <code>ObjectStreamClass</code>'s are memorized; - later calls to this method with the same class will return the - same <code>ObjectStreamClass</code> object and no recalculation - will be done. - - @see java.io.Serializable - */ - public static ObjectStreamClass lookup (Class cl) + * Returns the <code>ObjectStreamClass</code> for <code>cl</code>. + * If <code>cl</code> is null, or is not <code>Serializable</code>, + * null is returned. <code>ObjectStreamClass</code>'s are memorized; + * later calls to this method with the same class will return the + * same <code>ObjectStreamClass</code> object and no recalculation + * will be done. + * + * @see java.io.Serializable + */ + public static ObjectStreamClass lookup(Class cl) { if (cl == null) return null; - if (! (Serializable.class).isAssignableFrom (cl)) + if (! (Serializable.class).isAssignableFrom(cl)) return null; - return lookupForClassObject (cl); + return lookupForClassObject(cl); } /** @@ -85,57 +85,57 @@ public class ObjectStreamClass implements Serializable * we have a java.lang.Class object C for class A, though A is not * serializable, but it's okay to serialize C. */ - static ObjectStreamClass lookupForClassObject (Class cl) + static ObjectStreamClass lookupForClassObject(Class cl) { if (cl == null) return null; - ObjectStreamClass osc = (ObjectStreamClass)classLookupTable.get (cl); + ObjectStreamClass osc = (ObjectStreamClass) classLookupTable.get(cl); if (osc != null) return osc; else - { - osc = new ObjectStreamClass (cl); - classLookupTable.put (cl, osc); - return osc; - } + { + osc = new ObjectStreamClass(cl); + classLookupTable.put(cl, osc); + return osc; + } } /** - Returns the name of the class that this - <code>ObjectStreamClass</code> represents. - */ - public String getName () + * Returns the name of the class that this + * <code>ObjectStreamClass</code> represents. + */ + public String getName() { return name; } /** - Returns the class that this <code>ObjectStreamClass</code> - represents. Null could be returned if this - <code>ObjectStreamClass</code> was read from an - <code>ObjectInputStream</code> and the class it represents cannot - be found or loaded. - - @see java.io.ObjectInputStream - */ - public Class forClass () + * Returns the class that this <code>ObjectStreamClass</code> + * represents. Null could be returned if this + * <code>ObjectStreamClass</code> was read from an + * <code>ObjectInputStream</code> and the class it represents cannot + * be found or loaded. + * + * @see java.io.ObjectInputStream + */ + public Class forClass() { return clazz; } /** - Returns the serial version stream-unique identifier for the class - represented by this <code>ObjectStreamClass</code>. This SUID is - either defined by the class as <code>static final long - serialVersionUID</code> or is calculated as specified in - Javasoft's "Object Serialization Specification" XXX: add reference - */ - public long getSerialVersionUID () + * Returns the serial version stream-unique identifier for the class + * represented by this <code>ObjectStreamClass</code>. This SUID is + * either defined by the class as <code>static final long + * serialVersionUID</code> or is calculated as specified in + * Javasoft's "Object Serialization Specification" XXX: add reference + */ + public long getSerialVersionUID() { return uid; } @@ -145,10 +145,10 @@ public class ObjectStreamClass implements Serializable // of the class represented by this ObjectStreamClass. The Fields // are sorted by name. // XXX doc - public ObjectStreamField[] getFields () + public ObjectStreamField[] getFields() { ObjectStreamField[] copy = new ObjectStreamField[ fields.length ]; - System.arraycopy (fields, 0, copy, 0, fields.length); + System.arraycopy(fields, 0, copy, 0, fields.length); return copy; } @@ -158,8 +158,8 @@ public class ObjectStreamClass implements Serializable // primitiveness. public ObjectStreamField getField (String name) { - for (int i=0; i < fields.length; i++) - if (fields[i].getName ().equals (name)) + for (int i = 0; i < fields.length; i++) + if (fields[i].getName().equals(name)) return fields[i]; return null; } @@ -174,7 +174,7 @@ public class ObjectStreamClass implements Serializable * @see #getSerialVersionUID() * @see #getName() */ - public String toString () + public String toString() { return "java.io.ObjectStreamClass< " + name + ", " + uid + " >"; } @@ -187,7 +187,7 @@ public class ObjectStreamClass implements Serializable // // This method is used by the class to override default // serialization behavior. - boolean hasWriteMethod () + boolean hasWriteMethod() { return (flags & ObjectStreamConstants.SC_WRITE_METHOD) != 0; } @@ -200,24 +200,24 @@ public class ObjectStreamClass implements Serializable // // This method is used by the class to override default // serialization behavior. - boolean hasReadMethod () + boolean hasReadMethod() { - try + try { - Class[] readObjectParams = { ObjectInputStream.class }; - forClass ().getDeclaredMethod ("readObject", readObjectParams); - return true; + Class[] readObjectParams = { ObjectInputStream.class }; + forClass().getDeclaredMethod("readObject", readObjectParams); + return true; } - catch (NoSuchMethodException e) + catch (NoSuchMethodException e) { - return false; + return false; } } // Returns true iff the class that this ObjectStreamClass represents // implements Serializable but does *not* implement Externalizable. - boolean isSerializable () + boolean isSerializable() { return (flags & ObjectStreamConstants.SC_SERIALIZABLE) != 0; } @@ -225,7 +225,7 @@ public class ObjectStreamClass implements Serializable // Returns true iff the class that this ObjectStreamClass represents // implements Externalizable. - boolean isExternalizable () + boolean isExternalizable() { return (flags & ObjectStreamConstants.SC_EXTERNALIZABLE) != 0; } @@ -235,7 +235,7 @@ public class ObjectStreamClass implements Serializable // class that is the superclass of the class this // <code>ObjectStreamClass</code> represents. If the superclass is // not Serializable, null is returned. - ObjectStreamClass getSuper () + ObjectStreamClass getSuper() { return superClass; } @@ -245,30 +245,30 @@ public class ObjectStreamClass implements Serializable // classes of CLAZZ and CLAZZ itself in order from most super to // CLAZZ. ObjectStreamClass[0] is the highest superclass of CLAZZ // that is serializable. - static ObjectStreamClass[] getObjectStreamClasses (Class clazz) + static ObjectStreamClass[] getObjectStreamClasses(Class clazz) { - ObjectStreamClass osc = ObjectStreamClass.lookup (clazz); + ObjectStreamClass osc = ObjectStreamClass.lookup(clazz); if (osc == null) return new ObjectStreamClass[0]; else - { - Vector oscs = new Vector (); - - while (osc != null) { - oscs.addElement (osc); - osc = osc.getSuper (); - } + Vector oscs = new Vector(); - int count = oscs.size (); - ObjectStreamClass[] sorted_oscs = new ObjectStreamClass[ count ]; + while (osc != null) + { + oscs.addElement (osc); + osc = osc.getSuper(); + } + + int count = oscs.size(); + ObjectStreamClass[] sorted_oscs = new ObjectStreamClass[ count ]; - for (int i = count - 1; i >= 0; i--) - sorted_oscs[ count - i - 1 ] = (ObjectStreamClass)oscs.elementAt (i); + for (int i = count - 1; i >= 0; i--) + sorted_oscs[ count - i - 1 ] = (ObjectStreamClass) oscs.elementAt(i); - return sorted_oscs; - } + return sorted_oscs; + } } @@ -276,14 +276,14 @@ public class ObjectStreamClass implements Serializable // properties of the class represented by this ObjectStreamClass. // The bit-flags that could be present are those defined in // ObjectStreamConstants that begin with `SC_' - int getFlags () + int getFlags() { return flags; } - ObjectStreamClass (String name, long uid, byte flags, - ObjectStreamField[] fields) + ObjectStreamClass(String name, long uid, byte flags, + ObjectStreamField[] fields) { this.name = name; this.uid = uid; @@ -302,11 +302,11 @@ public class ObjectStreamClass implements Serializable * @throws InvalidClassException if an incompatibility between computed UID and * already set UID is found. */ - void setClass (Class cl, ObjectStreamClass superClass) throws InvalidClassException + void setClass(Class cl, ObjectStreamClass superClass) throws InvalidClassException { this.clazz = cl; - long class_uid = getClassUID (cl); + long class_uid = getClassUID(cl); if (uid == 0) uid = class_uid; else @@ -322,87 +322,89 @@ public class ObjectStreamClass implements Serializable } } - isProxyClass = clazz != null && Proxy.isProxyClass (clazz); + isProxyClass = clazz != null && Proxy.isProxyClass(clazz); this.superClass = superClass; - calculateOffsets (); - + calculateOffsets(); + try { - ObjectStreamField[] exportedFields = getSerialPersistentFields (clazz); - - if (exportedFields == null) - return; - - ObjectStreamField[] newFieldList = new ObjectStreamField[exportedFields.length + fields.length]; - int i, j, k; - - /* We now check the import fields against the exported fields. - * There should not be contradiction (e.g. int x and String x) - * but extra virtual fields can be added to the class. - */ - - Arrays.sort(exportedFields); - - i = 0; j = 0; k = 0; - while (i < fields.length && j < exportedFields.length) - { - int comp = fields[i].getName().compareTo (exportedFields[j].getName()); - if (comp < 0) - { - newFieldList[k] = fields[i]; - fields[i].setPersistent(false); - fields[i].setToSet(false); - i++; - } - else if (comp > 0) - { - /* field not found in imported fields. We add it - * in the list of supported fields. - */ - newFieldList[k] = exportedFields[j]; - newFieldList[k].setPersistent(true); - newFieldList[k].setToSet(false); - j++; - } - else - { - if (!fields[i].getType().equals (exportedFields[j].getType())) - throw new InvalidClassException ("serialPersistentFields must be compatible with" + - " imported fields (about " + fields[i].getName() + ")"); - newFieldList[k] = fields[i]; - fields[i].setPersistent(true); - i++; - j++; - } - k++; - } - - if (i < fields.length) - for (; i < fields.length; i++, k++) - { - fields[i].setPersistent(false); - fields[i].setToSet(false); - newFieldList[k] = fields[i]; - } - else - if (j < exportedFields.length) - for (; j < exportedFields.length; j++, k++) - { - exportedFields[j].setPersistent(true); - exportedFields[j].setToSet(false); - newFieldList[k] = exportedFields[j]; - } - - fields = new ObjectStreamField[k]; - System.arraycopy (newFieldList, 0, fields, 0, k); + ObjectStreamField[] exportedFields = getSerialPersistentFields (clazz); + + if (exportedFields == null) + return; + + ObjectStreamField[] newFieldList = new ObjectStreamField[exportedFields.length + fields.length]; + int i, j, k; + + /* We now check the import fields against the exported fields. + * There should not be contradiction (e.g. int x and String x) + * but extra virtual fields can be added to the class. + */ + + Arrays.sort(exportedFields); + + i = 0; j = 0; k = 0; + while (i < fields.length && j < exportedFields.length) + { + int comp = fields[i].getName().compareTo(exportedFields[j].getName()); + + if (comp < 0) + { + newFieldList[k] = fields[i]; + fields[i].setPersistent(false); + fields[i].setToSet(false); + i++; + } + else if (comp > 0) + { + /* field not found in imported fields. We add it + * in the list of supported fields. + */ + newFieldList[k] = exportedFields[j]; + newFieldList[k].setPersistent(true); + newFieldList[k].setToSet(false); + j++; + } + else + { + if (!fields[i].getType().equals(exportedFields[j].getType())) + throw new InvalidClassException + ("serialPersistentFields must be compatible with" + + " imported fields (about " + fields[i].getName() + ")"); + newFieldList[k] = fields[i]; + fields[i].setPersistent(true); + i++; + j++; + } + k++; + } + + if (i < fields.length) + for (;i<fields.length;i++,k++) + { + fields[i].setPersistent(false); + fields[i].setToSet(false); + newFieldList[k] = fields[i]; + } + else + if (j < exportedFields.length) + for (;j<exportedFields.length;j++,k++) + { + exportedFields[j].setPersistent(true); + exportedFields[j].setToSet(false); + newFieldList[k] = exportedFields[j]; + } + + fields = new ObjectStreamField[k]; + System.arraycopy(newFieldList, 0, fields, 0, k); } catch (NoSuchFieldException ignore) { - return; + return; } catch (IllegalAccessException ignore) { - return; + return; } } @@ -411,296 +413,300 @@ public class ObjectStreamClass implements Serializable superClass = osc; } - - void calculateOffsets () + void calculateOffsets() { int i; ObjectStreamField field; primFieldSize = 0; int fcount = fields.length; for (i = 0; i < fcount; ++ i) - { - field = fields[i]; - - if (! field.isPrimitive ()) - break; - - field.setOffset (primFieldSize); - switch (field.getTypeCode ()) { - case 'B': - case 'Z': - ++ primFieldSize; - break; - case 'C': - case 'S': - primFieldSize += 2; - break; - case 'I': - case 'F': - primFieldSize += 4; - break; - case 'D': - case 'J': - primFieldSize += 8; + field = fields[i]; + + if (! field.isPrimitive()) break; + + field.setOffset(primFieldSize); + switch (field.getTypeCode()) + { + case 'B': + case 'Z': + ++ primFieldSize; + break; + case 'C': + case 'S': + primFieldSize += 2; + break; + case 'I': + case 'F': + primFieldSize += 4; + break; + case 'D': + case 'J': + primFieldSize += 8; + break; + } } - } for (objectFieldCount = 0; i < fcount; ++ i) - fields[i].setOffset (objectFieldCount++); + fields[i].setOffset(objectFieldCount++); } - private ObjectStreamClass (Class cl) + private ObjectStreamClass(Class cl) { uid = 0; flags = 0; - isProxyClass = Proxy.isProxyClass (cl); + isProxyClass = Proxy.isProxyClass(cl); clazz = cl; - name = cl.getName (); - setFlags (cl); - setFields (cl); + name = cl.getName(); + setFlags(cl); + setFields(cl); // to those class nonserializable, its uid field is 0 - if ( (Serializable.class).isAssignableFrom (cl) && !isProxyClass) - uid = getClassUID (cl); - superClass = lookup (cl.getSuperclass ()); + if ( (Serializable.class).isAssignableFrom(cl) && !isProxyClass) + uid = getClassUID(cl); + superClass = lookup(cl.getSuperclass()); } // Sets bits in flags according to features of CL. - private void setFlags (Class cl) + private void setFlags(Class cl) { - if ((java.io.Externalizable.class).isAssignableFrom (cl)) + if ((java.io.Externalizable.class).isAssignableFrom(cl)) flags |= ObjectStreamConstants.SC_EXTERNALIZABLE; - else if ((java.io.Serializable.class).isAssignableFrom (cl)) + else if ((java.io.Serializable.class).isAssignableFrom(cl)) // only set this bit if CL is NOT Externalizable flags |= ObjectStreamConstants.SC_SERIALIZABLE; try - { - Method writeMethod = cl.getDeclaredMethod ("writeObject", - writeMethodArgTypes); - int modifiers = writeMethod.getModifiers (); - - if (writeMethod.getReturnType () == Void.TYPE - && Modifier.isPrivate (modifiers) - && !Modifier.isStatic (modifiers)) - flags |= ObjectStreamConstants.SC_WRITE_METHOD; - } - catch (NoSuchMethodException oh_well) - {} + { + Method writeMethod = cl.getDeclaredMethod("writeObject", + writeMethodArgTypes); + int modifiers = writeMethod.getModifiers(); + + if (writeMethod.getReturnType() == Void.TYPE + && Modifier.isPrivate(modifiers) + && !Modifier.isStatic(modifiers)) + flags |= ObjectStreamConstants.SC_WRITE_METHOD; + } + catch(NoSuchMethodException oh_well) + { + } } // Sets fields to be a sorted array of the serializable fields of // clazz. - private void setFields (Class cl) + private void setFields(Class cl) { - if (! isSerializable () || isExternalizable ()) - { - fields = NO_FIELDS; - return; - } + if (!isSerializable() || isExternalizable()) + { + fields = NO_FIELDS; + return; + } try - { - Field serialPersistentFields - = cl.getDeclaredField ("serialPersistentFields"); - serialPersistentFields.setAccessible(true); - int modifiers = serialPersistentFields.getModifiers (); - - if (Modifier.isStatic (modifiers) - && Modifier.isFinal (modifiers) - && Modifier.isPrivate (modifiers)) { - fields = getSerialPersistentFields (cl); - if (fields != null) + Field serialPersistentFields = + cl.getDeclaredField("serialPersistentFields"); + serialPersistentFields.setAccessible(true); + int modifiers = serialPersistentFields.getModifiers(); + + if (Modifier.isStatic(modifiers) + && Modifier.isFinal(modifiers) + && Modifier.isPrivate(modifiers)) { - Arrays.sort(fields); - calculateOffsets(); - return; + fields = getSerialPersistentFields(cl); + if (fields != null) + { + Arrays.sort (fields); + calculateOffsets(); + return; + } } } - } catch (NoSuchFieldException ignore) - {} + { + } catch (IllegalAccessException ignore) { } int num_good_fields = 0; - Field[] all_fields = cl.getDeclaredFields (); + Field[] all_fields = cl.getDeclaredFields(); int modifiers; // set non-serializable fields to null in all_fields - for (int i=0; i < all_fields.length; i++) - { - modifiers = all_fields[i].getModifiers (); - if (Modifier.isTransient (modifiers) - || Modifier.isStatic (modifiers)) - all_fields[i] = null; - else - num_good_fields++; - } + for (int i = 0; i < all_fields.length; i++) + { + modifiers = all_fields[i].getModifiers(); + if (Modifier.isTransient(modifiers) + || Modifier.isStatic(modifiers)) + all_fields[i] = null; + else + num_good_fields++; + } // make a copy of serializable (non-null) fields fields = new ObjectStreamField[ num_good_fields ]; - for (int from=0, to=0; from < all_fields.length; from++) + for (int from = 0, to = 0; from < all_fields.length; from++) if (all_fields[from] != null) - { - Field f = all_fields[from]; - fields[to] = new ObjectStreamField (f.getName (), f.getType ()); - to++; - } + { + Field f = all_fields[from]; + fields[to] = new ObjectStreamField(f.getName(), f.getType()); + to++; + } - Arrays.sort (fields); - calculateOffsets (); + Arrays.sort(fields); + calculateOffsets(); } // Returns the serial version UID defined by class, or if that // isn't present, calculates value of serial version UID. - private long getClassUID (Class cl) + private long getClassUID(Class cl) { try - { - // Use getDeclaredField rather than getField, since serialVersionUID - // may not be public AND we only want the serialVersionUID of this - // class, not a superclass or interface. - Field suid = cl.getDeclaredField ("serialVersionUID"); - suid.setAccessible(true); - int modifiers = suid.getModifiers (); - - if (Modifier.isStatic (modifiers) - && Modifier.isFinal (modifiers) - && suid.getType() == Long.TYPE) - return suid.getLong (null); - } + { + // Use getDeclaredField rather than getField, since serialVersionUID + // may not be public AND we only want the serialVersionUID of this + // class, not a superclass or interface. + Field suid = cl.getDeclaredField("serialVersionUID"); + suid.setAccessible(true); + int modifiers = suid.getModifiers(); + + if (Modifier.isStatic(modifiers) + && Modifier.isFinal(modifiers) + && suid.getType() == Long.TYPE) + return suid.getLong(null); + } catch (NoSuchFieldException ignore) - {} + { + } catch (IllegalAccessException ignore) - {} + { + } // cl didn't define serialVersionUID, so we have to compute it try - { - MessageDigest md; - try - { - md = MessageDigest.getInstance ("SHA"); - } - catch (NoSuchAlgorithmException e) - { - // If a provider already provides SHA, use it; otherwise, use this. - Gnu gnuProvider = new Gnu(); - Security.addProvider(gnuProvider); - md = MessageDigest.getInstance ("SHA"); - } + { + MessageDigest md; + try + { + md = MessageDigest.getInstance("SHA"); + } + catch (NoSuchAlgorithmException e) + { + // If a provider already provides SHA, use it; otherwise, use this. + Gnu gnuProvider = new Gnu(); + Security.addProvider(gnuProvider); + md = MessageDigest.getInstance("SHA"); + } - DigestOutputStream digest_out = - new DigestOutputStream (nullOutputStream, md); - DataOutputStream data_out = new DataOutputStream (digest_out); + DigestOutputStream digest_out = + new DigestOutputStream(nullOutputStream, md); + DataOutputStream data_out = new DataOutputStream(digest_out); - data_out.writeUTF (cl.getName ()); + data_out.writeUTF(cl.getName()); - int modifiers = cl.getModifiers (); - // just look at interesting bits - modifiers = modifiers & (Modifier.ABSTRACT | Modifier.FINAL - | Modifier.INTERFACE | Modifier.PUBLIC); - data_out.writeInt (modifiers); + int modifiers = cl.getModifiers(); + // just look at interesting bits + modifiers = modifiers & (Modifier.ABSTRACT | Modifier.FINAL + | Modifier.INTERFACE | Modifier.PUBLIC); + data_out.writeInt(modifiers); - // Pretend that an array has no interfaces, because when array - // serialization was defined (JDK 1.1), arrays didn't have it. - if (! cl.isArray ()) - { - Class[] interfaces = cl.getInterfaces (); - Arrays.sort (interfaces, interfaceComparator); - for (int i=0; i < interfaces.length; i++) - data_out.writeUTF (interfaces[i].getName ()); - } + // Pretend that an array has no interfaces, because when array + // serialization was defined (JDK 1.1), arrays didn't have it. + if (! cl.isArray()) + { + Class[] interfaces = cl.getInterfaces(); + Arrays.sort(interfaces, interfaceComparator); + for (int i = 0; i < interfaces.length; i++) + data_out.writeUTF(interfaces[i].getName()); + } - Field field; - Field[] fields = cl.getDeclaredFields (); - Arrays.sort (fields, memberComparator); - for (int i=0; i < fields.length; i++) - { - field = fields[i]; - modifiers = field.getModifiers (); - if (Modifier.isPrivate (modifiers) - && (Modifier.isStatic (modifiers) - || Modifier.isTransient (modifiers))) - continue; - - data_out.writeUTF (field.getName ()); - data_out.writeInt (modifiers); - data_out.writeUTF (TypeSignature.getEncodingOfClass (field.getType ())); - } + Field field; + Field[] fields = cl.getDeclaredFields(); + Arrays.sort(fields, memberComparator); + for (int i = 0; i < fields.length; i++) + { + field = fields[i]; + modifiers = field.getModifiers(); + if (Modifier.isPrivate(modifiers) + && (Modifier.isStatic(modifiers) + || Modifier.isTransient(modifiers))) + continue; + + data_out.writeUTF(field.getName()); + data_out.writeInt(modifiers); + data_out.writeUTF(TypeSignature.getEncodingOfClass (field.getType())); + } - // write class initializer method if present - if (VMObjectStreamClass.hasClassInitializer (cl)) - { - data_out.writeUTF ("<clinit>"); - data_out.writeInt (Modifier.STATIC); - data_out.writeUTF ("()V"); - } + // write class initializer method if present + if (VMObjectStreamClass.hasClassInitializer(cl)) + { + data_out.writeUTF("<clinit>"); + data_out.writeInt(Modifier.STATIC); + data_out.writeUTF("()V"); + } - Constructor constructor; - Constructor[] constructors = cl.getDeclaredConstructors (); - Arrays.sort (constructors, memberComparator); - for (int i=0; i < constructors.length; i++) - { - constructor = constructors[i]; - modifiers = constructor.getModifiers (); - if (Modifier.isPrivate (modifiers)) - continue; - - data_out.writeUTF ("<init>"); - data_out.writeInt (modifiers); - - // the replacement of '/' with '.' was needed to make computed - // SUID's agree with those computed by JDK - data_out.writeUTF ( - TypeSignature.getEncodingOfConstructor (constructor).replace ('/','.')); - } + Constructor constructor; + Constructor[] constructors = cl.getDeclaredConstructors(); + Arrays.sort (constructors, memberComparator); + for (int i = 0; i < constructors.length; i++) + { + constructor = constructors[i]; + modifiers = constructor.getModifiers(); + if (Modifier.isPrivate(modifiers)) + continue; + + data_out.writeUTF("<init>"); + data_out.writeInt(modifiers); + + // the replacement of '/' with '.' was needed to make computed + // SUID's agree with those computed by JDK + data_out.writeUTF + (TypeSignature.getEncodingOfConstructor(constructor).replace('/','.')); + } - Method method; - Method[] methods = cl.getDeclaredMethods (); - Arrays.sort (methods, memberComparator); - for (int i=0; i < methods.length; i++) - { - method = methods[i]; - modifiers = method.getModifiers (); - if (Modifier.isPrivate (modifiers)) - continue; - - data_out.writeUTF (method.getName ()); - data_out.writeInt (modifiers); - - // the replacement of '/' with '.' was needed to make computed - // SUID's agree with those computed by JDK - data_out.writeUTF ( - TypeSignature.getEncodingOfMethod (method).replace ('/', '.')); - } + Method method; + Method[] methods = cl.getDeclaredMethods(); + Arrays.sort(methods, memberComparator); + for (int i = 0; i < methods.length; i++) + { + method = methods[i]; + modifiers = method.getModifiers(); + if (Modifier.isPrivate(modifiers)) + continue; + + data_out.writeUTF(method.getName()); + data_out.writeInt(modifiers); + + // the replacement of '/' with '.' was needed to make computed + // SUID's agree with those computed by JDK + data_out.writeUTF + (TypeSignature.getEncodingOfMethod(method).replace('/', '.')); + } - data_out.close (); - byte[] sha = md.digest (); - long result = 0; - int len = sha.length < 8 ? sha.length : 8; - for (int i=0; i < len; i++) - result += (long)(sha[i] & 0xFF) << (8 * i); + data_out.close(); + byte[] sha = md.digest(); + long result = 0; + int len = sha.length < 8 ? sha.length : 8; + for (int i = 0; i < len; i++) + result += (long) (sha[i] & 0xFF) << (8 * i); - return result; - } + return result; + } catch (NoSuchAlgorithmException e) - { - throw new RuntimeException ("The SHA algorithm was not found to use in computing the Serial Version UID for class " - + cl.getName (), e); - } + { + throw new RuntimeException + ("The SHA algorithm was not found to use in computing the Serial Version UID for class " + + cl.getName(), e); + } catch (IOException ioe) - { - throw new RuntimeException (ioe); - } + { + throw new RuntimeException(ioe); + } } /** @@ -712,7 +718,7 @@ public class ObjectStreamClass implements Serializable * @param clazz Class to retrieve 'serialPersistentFields' from. * @return The content of 'serialPersistentFields'. */ - private ObjectStreamField[] getSerialPersistentFields (Class clazz) + private ObjectStreamField[] getSerialPersistentFields(Class clazz) throws NoSuchFieldException, IllegalAccessException { ObjectStreamField[] fieldsArray = null; @@ -724,9 +730,9 @@ public class ObjectStreamClass implements Serializable f.setAccessible(true); int modifiers = f.getModifiers(); - if (!(Modifier.isStatic(modifiers) - && Modifier.isFinal(modifiers) - && Modifier.isPrivate(modifiers))) + if (!(Modifier.isStatic(modifiers) && + Modifier.isFinal(modifiers) && + Modifier.isPrivate(modifiers))) return null; o = (ObjectStreamField[]) f.get(null); @@ -734,7 +740,7 @@ public class ObjectStreamClass implements Serializable if (o == null) return null; - fieldsArray = new ObjectStreamField[o.length]; + fieldsArray = new ObjectStreamField[ o.length ]; System.arraycopy(o, 0, fieldsArray, 0, o.length); return fieldsArray; @@ -742,10 +748,10 @@ public class ObjectStreamClass implements Serializable public static final ObjectStreamField[] NO_FIELDS = {}; - private static Hashtable classLookupTable = new Hashtable (); - private static final NullOutputStream nullOutputStream = new NullOutputStream (); - private static final Comparator interfaceComparator = new InterfaceComparator (); - private static final Comparator memberComparator = new MemberComparator (); + private static Hashtable classLookupTable = new Hashtable(); + private static final NullOutputStream nullOutputStream = new NullOutputStream(); + private static final Comparator interfaceComparator = new InterfaceComparator(); + private static final Comparator memberComparator = new MemberComparator(); private static final Class[] writeMethodArgTypes = { java.io.ObjectOutputStream.class }; @@ -775,9 +781,9 @@ public class ObjectStreamClass implements Serializable // interfaces are compared only by name class InterfaceComparator implements Comparator { - public int compare (Object o1, Object o2) + public int compare(Object o1, Object o2) { - return ((Class)o1).getName ().compareTo (((Class)o2).getName ()); + return ((Class) o1).getName().compareTo(((Class) o2).getName()); } } @@ -786,16 +792,16 @@ class InterfaceComparator implements Comparator // conflicts are resolved by comparing type signatures class MemberComparator implements Comparator { - public int compare (Object o1, Object o2) + public int compare(Object o1, Object o2) { - Member m1 = (Member)o1; - Member m2 = (Member)o2; + Member m1 = (Member) o1; + Member m2 = (Member) o2; - int comp = m1.getName ().compareTo (m2.getName ()); + int comp = m1.getName().compareTo(m2.getName()); if (comp == 0) - return TypeSignature.getEncodingOfMember (m1). - compareTo (TypeSignature.getEncodingOfMember (m2)); + return TypeSignature.getEncodingOfMember(m1). + compareTo(TypeSignature.getEncodingOfMember(m2)); else return comp; } |