Merged gcj-eclipse branch to trunk.
From-SVN: r120621
This commit is contained in:
parent
c648dedbde
commit
97b8365caf
17478 changed files with 606493 additions and 100744 deletions
|
@ -39,7 +39,7 @@ exception statement from your version. */
|
|||
|
||||
package java.io;
|
||||
|
||||
import gnu.java.io.ObjectIdentityWrapper;
|
||||
import gnu.java.io.ObjectIdentityMap2Int;
|
||||
import gnu.java.lang.reflect.TypeSignature;
|
||||
import gnu.java.security.action.SetAccessibleAction;
|
||||
|
||||
|
@ -47,8 +47,7 @@ import java.lang.reflect.Array;
|
|||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.security.AccessController;
|
||||
import java.util.Hashtable;
|
||||
|
||||
|
||||
/**
|
||||
* An <code>ObjectOutputStream</code> can be used to write objects
|
||||
|
@ -115,6 +114,11 @@ import java.util.Hashtable;
|
|||
* @see java.io.Externalizable
|
||||
* @see java.io.ObjectInputStream
|
||||
* @see java.io.Serializable
|
||||
* @author Tom Tromey (tromey@redhat.com)
|
||||
* @author Jeroen Frijters (jeroen@frijters.net)
|
||||
* @author Guilhem Lavaux (guilhem@kaffe.org)
|
||||
* @author Michael Koch (konqueror@gmx.de)
|
||||
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
|
||||
*/
|
||||
public class ObjectOutputStream extends OutputStream
|
||||
implements ObjectOutput, ObjectStreamConstants
|
||||
|
@ -140,7 +144,7 @@ public class ObjectOutputStream extends OutputStream
|
|||
replacementEnabled = false;
|
||||
isSerializing = false;
|
||||
nextOID = baseWireHandle;
|
||||
OIDLookupTable = new Hashtable();
|
||||
OIDLookupTable = new ObjectIdentityMap2Int();
|
||||
protocolVersion = defaultProtocolVersion;
|
||||
useSubclassMethod = false;
|
||||
writeStreamHeader();
|
||||
|
@ -207,11 +211,11 @@ public class ObjectOutputStream extends OutputStream
|
|||
break;
|
||||
}
|
||||
|
||||
Integer handle = findHandle(obj);
|
||||
if (handle != null)
|
||||
int handle = findHandle(obj);
|
||||
if (handle >= 0)
|
||||
{
|
||||
realOutput.writeByte(TC_REFERENCE);
|
||||
realOutput.writeInt(handle.intValue());
|
||||
realOutput.writeInt(handle);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -225,7 +229,7 @@ public class ObjectOutputStream extends OutputStream
|
|||
writeObject (osc);
|
||||
}
|
||||
else
|
||||
{
|
||||
{System.err.println("1");
|
||||
realOutput.writeByte(TC_PROXYCLASSDESC);
|
||||
Class[] intfs = cl.getInterfaces();
|
||||
realOutput.writeInt(intfs.length);
|
||||
|
@ -338,8 +342,7 @@ public class ObjectOutputStream extends OutputStream
|
|||
Object prevObject = this.currentObject;
|
||||
ObjectStreamClass prevObjectStreamClass = this.currentObjectStreamClass;
|
||||
currentObject = obj;
|
||||
ObjectStreamClass[] hierarchy =
|
||||
ObjectStreamClass.getObjectStreamClasses(clazz);
|
||||
ObjectStreamClass[] hierarchy = osc.hierarchy();
|
||||
|
||||
for (int i = 0; i < hierarchy.length; i++)
|
||||
{
|
||||
|
@ -604,11 +607,11 @@ public class ObjectOutputStream extends OutputStream
|
|||
*
|
||||
* @see ObjectInputStream#resolveClass(java.io.ObjectStreamClass)
|
||||
*/
|
||||
protected void annotateClass(Class cl) throws IOException
|
||||
protected void annotateClass(Class<?> cl) throws IOException
|
||||
{
|
||||
}
|
||||
|
||||
protected void annotateProxyClass(Class cl) throws IOException
|
||||
protected void annotateProxyClass(Class<?> cl) throws IOException
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -1104,17 +1107,16 @@ public class ObjectOutputStream extends OutputStream
|
|||
|
||||
// lookup the handle for OBJ, return null if OBJ doesn't have a
|
||||
// handle yet
|
||||
private Integer findHandle(Object obj)
|
||||
private int findHandle(Object obj)
|
||||
{
|
||||
return (Integer)OIDLookupTable.get(new ObjectIdentityWrapper(obj));
|
||||
return OIDLookupTable.get(obj);
|
||||
}
|
||||
|
||||
|
||||
// assigns the next availible handle to OBJ
|
||||
private int assignNewHandle(Object obj)
|
||||
{
|
||||
OIDLookupTable.put(new ObjectIdentityWrapper(obj),
|
||||
new Integer(nextOID));
|
||||
OIDLookupTable.put(obj, nextOID);
|
||||
return nextOID++;
|
||||
}
|
||||
|
||||
|
@ -1216,38 +1218,69 @@ public class ObjectOutputStream extends OutputStream
|
|||
{
|
||||
ObjectStreamField[] fields = osc.fields;
|
||||
boolean oldmode = setBlockDataMode(false);
|
||||
String field_name;
|
||||
Class type;
|
||||
|
||||
try
|
||||
{
|
||||
writeFields(obj,fields);
|
||||
}
|
||||
catch (IllegalArgumentException _)
|
||||
{
|
||||
InvalidClassException e = new InvalidClassException
|
||||
("writing fields of class " + osc.forClass().getName());
|
||||
e.initCause(_);
|
||||
throw e;
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
catch (Exception _)
|
||||
{
|
||||
IOException e = new IOException("Unexpected exception " + _);
|
||||
e.initCause(_);
|
||||
throw(e);
|
||||
}
|
||||
|
||||
setBlockDataMode(oldmode);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Helper function for writeFields(Object,ObjectStreamClass): write
|
||||
* fields from given fields array. Pass exception on.
|
||||
*
|
||||
* @param obj the object to be written
|
||||
*
|
||||
* @param fields the fields of obj to be written.
|
||||
*/
|
||||
private void writeFields(Object obj, ObjectStreamField[] fields)
|
||||
throws
|
||||
IllegalArgumentException, IllegalAccessException, IOException
|
||||
{
|
||||
for (int i = 0; i < fields.length; i++)
|
||||
{
|
||||
field_name = fields[i].getName();
|
||||
type = fields[i].getType();
|
||||
|
||||
if (dump)
|
||||
dumpElementln ("WRITE FIELD: " + field_name + " type=" + type);
|
||||
|
||||
if (type == Boolean.TYPE)
|
||||
realOutput.writeBoolean(getBooleanField(obj, osc.forClass(), field_name));
|
||||
else if (type == Byte.TYPE)
|
||||
realOutput.writeByte(getByteField(obj, osc.forClass(), field_name));
|
||||
else if (type == Character.TYPE)
|
||||
realOutput.writeChar(getCharField(obj, osc.forClass(), field_name));
|
||||
else if (type == Double.TYPE)
|
||||
realOutput.writeDouble(getDoubleField(obj, osc.forClass(), field_name));
|
||||
else if (type == Float.TYPE)
|
||||
realOutput.writeFloat(getFloatField(obj, osc.forClass(), field_name));
|
||||
else if (type == Integer.TYPE)
|
||||
realOutput.writeInt(getIntField(obj, osc.forClass(), field_name));
|
||||
else if (type == Long.TYPE)
|
||||
realOutput.writeLong(getLongField(obj, osc.forClass(), field_name));
|
||||
else if (type == Short.TYPE)
|
||||
realOutput.writeShort(getShortField(obj, osc.forClass(), field_name));
|
||||
else
|
||||
writeObject(getObjectField(obj, osc.forClass(), field_name,
|
||||
fields[i].getTypeString ()));
|
||||
ObjectStreamField osf = fields[i];
|
||||
Field field = osf.field;
|
||||
|
||||
if (DEBUG && dump)
|
||||
dumpElementln ("WRITE FIELD: " + osf.getName() + " type=" + osf.getType());
|
||||
|
||||
switch (osf.getTypeCode())
|
||||
{
|
||||
case 'Z': realOutput.writeBoolean(field.getBoolean(obj)); break;
|
||||
case 'B': realOutput.writeByte (field.getByte (obj)); break;
|
||||
case 'S': realOutput.writeShort (field.getShort (obj)); break;
|
||||
case 'C': realOutput.writeChar (field.getChar (obj)); break;
|
||||
case 'I': realOutput.writeInt (field.getInt (obj)); break;
|
||||
case 'F': realOutput.writeFloat (field.getFloat (obj)); break;
|
||||
case 'J': realOutput.writeLong (field.getLong (obj)); break;
|
||||
case 'D': realOutput.writeDouble (field.getDouble (obj)); break;
|
||||
case 'L':
|
||||
case '[': writeObject (field.get (obj)); break;
|
||||
default:
|
||||
throw new IOException("Unexpected type code " + osf.getTypeCode());
|
||||
}
|
||||
}
|
||||
setBlockDataMode(oldmode);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1307,248 +1340,6 @@ public class ObjectOutputStream extends OutputStream
|
|||
}
|
||||
}
|
||||
|
||||
private boolean getBooleanField(Object obj, Class klass, String field_name)
|
||||
throws IOException
|
||||
{
|
||||
try
|
||||
{
|
||||
Field f = getField(klass, field_name);
|
||||
boolean b = f.getBoolean(obj);
|
||||
return b;
|
||||
}
|
||||
catch (IllegalArgumentException _)
|
||||
{
|
||||
throw new InvalidClassException
|
||||
("invalid requested type for field " + field_name + " in class " + klass.getName());
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
catch (Exception _)
|
||||
{
|
||||
throw new IOException("Unexpected exception " + _);
|
||||
}
|
||||
}
|
||||
|
||||
private byte getByteField (Object obj, Class klass, String field_name)
|
||||
throws IOException
|
||||
{
|
||||
try
|
||||
{
|
||||
Field f = getField (klass, field_name);
|
||||
byte b = f.getByte (obj);
|
||||
return b;
|
||||
}
|
||||
catch (IllegalArgumentException _)
|
||||
{
|
||||
throw new InvalidClassException
|
||||
("invalid requested type for field " + field_name + " in class " + klass.getName());
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
catch (Exception _)
|
||||
{
|
||||
throw new IOException("Unexpected exception " + _);
|
||||
}
|
||||
}
|
||||
|
||||
private char getCharField (Object obj, Class klass, String field_name)
|
||||
throws IOException
|
||||
{
|
||||
try
|
||||
{
|
||||
Field f = getField (klass, field_name);
|
||||
char b = f.getChar (obj);
|
||||
return b;
|
||||
}
|
||||
catch (IllegalArgumentException _)
|
||||
{
|
||||
throw new InvalidClassException
|
||||
("invalid requested type for field " + field_name + " in class " + klass.getName());
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
catch (Exception _)
|
||||
{
|
||||
throw new IOException("Unexpected exception " + _);
|
||||
}
|
||||
}
|
||||
|
||||
private double getDoubleField (Object obj, Class klass, String field_name)
|
||||
throws IOException
|
||||
{
|
||||
try
|
||||
{
|
||||
Field f = getField (klass, field_name);
|
||||
double b = f.getDouble (obj);
|
||||
return b;
|
||||
}
|
||||
catch (IllegalArgumentException _)
|
||||
{
|
||||
throw new InvalidClassException
|
||||
("invalid requested type for field " + field_name + " in class " + klass.getName());
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
catch (Exception _)
|
||||
{
|
||||
throw new IOException("Unexpected exception " + _);
|
||||
}
|
||||
}
|
||||
|
||||
private float getFloatField (Object obj, Class klass, String field_name)
|
||||
throws IOException
|
||||
{
|
||||
try
|
||||
{
|
||||
Field f = getField (klass, field_name);
|
||||
float b = f.getFloat (obj);
|
||||
return b;
|
||||
}
|
||||
catch (IllegalArgumentException _)
|
||||
{
|
||||
throw new InvalidClassException
|
||||
("invalid requested type for field " + field_name + " in class " + klass.getName());
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
catch (Exception _)
|
||||
{
|
||||
throw new IOException("Unexpected exception " + _);
|
||||
}
|
||||
}
|
||||
|
||||
private int getIntField (Object obj, Class klass, String field_name)
|
||||
throws IOException
|
||||
{
|
||||
try
|
||||
{
|
||||
Field f = getField (klass, field_name);
|
||||
int b = f.getInt (obj);
|
||||
return b;
|
||||
}
|
||||
catch (IllegalArgumentException _)
|
||||
{
|
||||
throw new InvalidClassException
|
||||
("invalid requested type for field " + field_name + " in class " + klass.getName());
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
catch (Exception _)
|
||||
{
|
||||
throw new IOException("Unexpected exception " + _);
|
||||
}
|
||||
}
|
||||
|
||||
private long getLongField (Object obj, Class klass, String field_name)
|
||||
throws IOException
|
||||
{
|
||||
try
|
||||
{
|
||||
Field f = getField (klass, field_name);
|
||||
long b = f.getLong (obj);
|
||||
return b;
|
||||
}
|
||||
catch (IllegalArgumentException _)
|
||||
{
|
||||
throw new InvalidClassException
|
||||
("invalid requested type for field " + field_name + " in class " + klass.getName());
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
catch (Exception _)
|
||||
{
|
||||
throw new IOException("Unexpected exception " + _);
|
||||
}
|
||||
}
|
||||
|
||||
private short getShortField (Object obj, Class klass, String field_name)
|
||||
throws IOException
|
||||
{
|
||||
try
|
||||
{
|
||||
Field f = getField (klass, field_name);
|
||||
short b = f.getShort (obj);
|
||||
return b;
|
||||
}
|
||||
catch (IllegalArgumentException _)
|
||||
{
|
||||
throw new InvalidClassException
|
||||
("invalid requested type for field " + field_name + " in class " + klass.getName());
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
catch (Exception _)
|
||||
{
|
||||
throw new IOException("Unexpected exception " + _);
|
||||
}
|
||||
}
|
||||
|
||||
private Object getObjectField (Object obj, Class klass, String field_name,
|
||||
String type_code) throws IOException
|
||||
{
|
||||
try
|
||||
{
|
||||
Field f = getField (klass, field_name);
|
||||
ObjectStreamField of = new ObjectStreamField(f.getName(), f.getType());
|
||||
|
||||
/* if of is primitive something went wrong
|
||||
* in the check for primitive classes in writeFields.
|
||||
*/
|
||||
if (of.isPrimitive())
|
||||
throw new InvalidClassException
|
||||
("invalid type code for " + field_name + " in class " + klass.getName() + " : object stream field is primitive");
|
||||
|
||||
if (!of.getTypeString().equals(type_code))
|
||||
throw new InvalidClassException
|
||||
("invalid type code for " + field_name + " in class " + klass.getName() + " : object stream field " + of + " has type string " + of.getTypeString() + " instead of " + type_code);
|
||||
|
||||
Object o = f.get (obj);
|
||||
// FIXME: We should check the type_code here
|
||||
return o;
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new IOException ();
|
||||
}
|
||||
}
|
||||
|
||||
private Field getField (Class klass, String name)
|
||||
throws java.io.InvalidClassException
|
||||
{
|
||||
try
|
||||
{
|
||||
final Field f = klass.getDeclaredField(name);
|
||||
setAccessible.setMember(f);
|
||||
AccessController.doPrivileged(setAccessible);
|
||||
return f;
|
||||
}
|
||||
catch (java.lang.NoSuchFieldException e)
|
||||
{
|
||||
throw new InvalidClassException
|
||||
("no field called " + name + " in class " + klass.getName());
|
||||
}
|
||||
}
|
||||
|
||||
private void dumpElementln (String msg)
|
||||
{
|
||||
for (int i = 0; i < depth; i++)
|
||||
|
@ -1576,7 +1367,7 @@ public class ObjectOutputStream extends OutputStream
|
|||
private boolean replacementEnabled;
|
||||
private boolean isSerializing;
|
||||
private int nextOID;
|
||||
private Hashtable OIDLookupTable;
|
||||
private ObjectIdentityMap2Int OIDLookupTable;
|
||||
private int protocolVersion;
|
||||
private boolean useSubclassMethod;
|
||||
private SetAccessibleAction setAccessible = new SetAccessibleAction();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue