2003-06-25 Michael Koch <konqueror@gmx.de>

* java/io/ObjectInputStream.java
	(readClassDescriptor): New method.
	(readObject): Moved functionality to readClassDescriptor().
	* java/io/ObjectOutputStream.java
	(writeClassDescriptor): New method.
	(writeObject): Moved functionality to writeClassDescriptor().

From-SVN: r68465
This commit is contained in:
Michael Koch 2003-06-25 06:31:59 +00:00 committed by Michael Koch
parent 55a5d1f714
commit 3cc9a95d27
3 changed files with 96 additions and 78 deletions

View File

@ -1,3 +1,12 @@
2003-06-25 Michael Koch <konqueror@gmx.de>
* java/io/ObjectInputStream.java
(readClassDescriptor): New method.
(readObject): Moved functionality to readClassDescriptor().
* java/io/ObjectOutputStream.java
(writeClassDescriptor): New method.
(writeObject): Moved functionality to writeClassDescriptor().
2003-06-25 Michael Koch <konqueror@gmx.de>
* javax/swing/plaf/basic/BasicListUI.java,

View File

@ -219,44 +219,7 @@ public class ObjectInputStream extends InputStream
case TC_CLASSDESC:
{
dumpElement ("CLASSDESC NAME=");
String name = this.realInputStream.readUTF ();
dumpElement (name + "; UID=");
long uid = this.realInputStream.readLong ();
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));
ObjectStreamField[] fields = new ObjectStreamField[field_count];
ObjectStreamClass osc = new ObjectStreamClass (name, uid,
flags, fields);
assignNewHandle (osc);
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);
String class_name;
if (type_code == 'L' || type_code == '[')
class_name = (String)readObject ();
else
class_name = String.valueOf (type_code);
// There're many cases you can't get java.lang.Class from
// typename if your context class loader can't load it,
// then use typename to construct the field
fields[i] =
new ObjectStreamField (field_name, class_name);
}
boolean oldmode = setBlockDataMode (true);
osc.setClass (resolveClass (osc));
setBlockDataMode (oldmode);
ObjectStreamClass osc = readClassDescriptor ();
if (!is_consumed)
{
@ -451,6 +414,51 @@ public class ObjectInputStream extends InputStream
return ret_val;
}
protected ObjectStreamClass readClassDescriptor ()
throws ClassNotFoundException, IOException
{
dumpElement ("CLASSDESC NAME=");
String name = this.realInputStream.readUTF ();
dumpElement (name + "; UID=");
long uid = this.realInputStream.readLong ();
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));
ObjectStreamField[] fields = new ObjectStreamField[field_count];
ObjectStreamClass osc = new ObjectStreamClass (name, uid,
flags, fields);
assignNewHandle (osc);
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);
String class_name;
if (type_code == 'L' || type_code == '[')
class_name = (String)readObject ();
else
class_name = String.valueOf (type_code);
// There're many cases you can't get java.lang.Class from
// typename if your context class loader can't load it,
// then use typename to construct the field
fields[i] =
new ObjectStreamField (field_name, class_name);
}
boolean oldmode = setBlockDataMode (true);
osc.setClass (resolveClass (osc));
setBlockDataMode (oldmode);
return osc;
}
/**
* Reads the current objects non-transient, non-static fields from
* the current class from the underlying output stream.

View File

@ -224,46 +224,7 @@ public class ObjectOutputStream extends OutputStream
}
if (obj instanceof ObjectStreamClass)
{
ObjectStreamClass osc = (ObjectStreamClass)obj;
realOutput.writeByte (TC_CLASSDESC);
realOutput.writeUTF (osc.getName ());
realOutput.writeLong (osc.getSerialVersionUID ());
assignNewHandle (obj);
int flags = osc.getFlags ();
if (protocolVersion == PROTOCOL_VERSION_2
&& osc.isExternalizable ())
flags |= SC_BLOCK_DATA;
realOutput.writeByte (flags);
ObjectStreamField[] fields = osc.fields;
realOutput.writeShort (fields.length);
ObjectStreamField field;
for (int i=0; i < fields.length; i++)
{
field = fields[i];
realOutput.writeByte (field.getTypeCode ());
realOutput.writeUTF (field.getName ());
if (! field.isPrimitive ())
writeObject (field.getTypeString ());
}
boolean oldmode = setBlockDataMode (true);
annotateClass (osc.forClass ());
setBlockDataMode (oldmode);
realOutput.writeByte (TC_ENDBLOCKDATA);
if (osc.isSerializable ())
writeObject (osc.getSuper ());
else
writeObject (null);
break;
}
writeClassDescriptor ((ObjectStreamClass) obj);
if ((replacementEnabled || obj instanceof Serializable)
&& ! replaceDone)
@ -406,6 +367,46 @@ public class ObjectOutputStream extends OutputStream
}
}
protected void writeClassDescriptor (ObjectStreamClass osc) throws IOException
{
realOutput.writeByte (TC_CLASSDESC);
realOutput.writeUTF (osc.getName ());
realOutput.writeLong (osc.getSerialVersionUID ());
assignNewHandle (osc);
int flags = osc.getFlags ();
if (protocolVersion == PROTOCOL_VERSION_2
&& osc.isExternalizable ())
flags |= SC_BLOCK_DATA;
realOutput.writeByte (flags);
ObjectStreamField[] fields = osc.fields;
realOutput.writeShort (fields.length);
ObjectStreamField field;
for (int i=0; i < fields.length; i++)
{
field = fields[i];
realOutput.writeByte (field.getTypeCode ());
realOutput.writeUTF (field.getName ());
if (! field.isPrimitive ())
writeObject (field.getTypeString ());
}
boolean oldmode = setBlockDataMode (true);
annotateClass (osc.forClass ());
setBlockDataMode (oldmode);
realOutput.writeByte (TC_ENDBLOCKDATA);
if (osc.isSerializable ())
writeObject (osc.getSuper ());
else
writeObject (null);
}
/**
Writes the current objects non-transient, non-static fields from
the current class to the underlying output stream.