1 |
/* ObjectOutputStream.java -- Class used to write serialized objects |
/* ObjectOutputStream.java -- Class used to write serialized objects |
2 |
Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc. |
Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. |
3 |
|
|
4 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
5 |
|
|
168 |
public final void writeObject (Object obj) throws IOException |
public final void writeObject (Object obj) throws IOException |
169 |
{ |
{ |
170 |
if (useSubclassMethod) |
if (useSubclassMethod) |
171 |
{ |
{ |
172 |
writeObjectOverride (obj); |
writeObjectOverride (obj); |
173 |
return; |
return; |
174 |
} |
} |
175 |
|
|
176 |
boolean was_serializing = isSerializing; |
boolean was_serializing = isSerializing; |
177 |
boolean old_mode = setBlockDataMode (false); |
boolean old_mode = setBlockDataMode (false); |
541 |
@see java.io.ObjectInputStream#resolveClass (java.io.ObjectStreamClass) |
@see java.io.ObjectInputStream#resolveClass (java.io.ObjectStreamClass) |
542 |
*/ |
*/ |
543 |
protected void annotateClass (Class cl) throws IOException |
protected void annotateClass (Class cl) throws IOException |
544 |
{ |
{} |
|
} |
|
545 |
|
|
546 |
protected void annotateProxyClass(Class cl) throws IOException |
protected void annotateProxyClass(Class cl) throws IOException |
547 |
{ |
{} |
|
} |
|
548 |
|
|
549 |
/** |
/** |
550 |
Allows subclasses to replace objects that are written to the |
Allows subclasses to replace objects that are written to the |
643 |
throw new NotActiveException ("Subclass of ObjectOutputStream must implement writeObjectOverride"); |
throw new NotActiveException ("Subclass of ObjectOutputStream must implement writeObjectOverride"); |
644 |
} |
} |
645 |
|
|
646 |
|
|
647 |
/** |
/** |
648 |
@see java.io.DataOutputStream#write (int) |
@see java.io.DataOutputStream#write (int) |
649 |
*/ |
*/ |
664 |
/** |
/** |
665 |
@see java.io.DataOutputStream#write (byte[]) |
@see java.io.DataOutputStream#write (byte[]) |
666 |
*/ |
*/ |
667 |
public void write (byte b[]) throws IOException |
public void write (byte[] b) throws IOException |
668 |
{ |
{ |
669 |
write (b, 0, b.length); |
write (b, 0, b.length); |
670 |
} |
} |
673 |
/** |
/** |
674 |
@see java.io.DataOutputStream#write (byte[],int,int) |
@see java.io.DataOutputStream#write (byte[],int,int) |
675 |
*/ |
*/ |
676 |
public void write (byte b[], int off, int len) throws IOException |
public void write (byte[] b, int off, int len) throws IOException |
677 |
{ |
{ |
678 |
if (writeDataAsBlocks) |
if (writeDataAsBlocks) |
679 |
{ |
{ |
1216 |
} |
} |
1217 |
|
|
1218 |
|
|
1219 |
private native void callWriteMethod (Object obj); |
private void callWriteMethod (Object obj) throws IOException |
1220 |
private native boolean getBooleanField (Object obj, String field_name); |
{ |
1221 |
private native byte getByteField (Object obj, String field_name); |
Class klass = obj.getClass (); |
1222 |
private native char getCharField (Object obj, String field_name); |
try |
1223 |
private native double getDoubleField (Object obj, String field_name); |
{ |
1224 |
private native float getFloatField (Object obj, String field_name); |
Class classArgs[] = {ObjectOutputStream.class}; |
1225 |
private native int getIntField (Object obj, String field_name); |
Method m = getMethod (klass, "writeObject", classArgs); |
1226 |
private native long getLongField (Object obj, String field_name); |
if (m == null) |
1227 |
private native short getShortField (Object obj, String field_name); |
return; |
1228 |
private native Object getObjectField (Object obj, String field_name, |
Object args[] = {this}; |
1229 |
String type_code); |
m.invoke (obj, args); |
1230 |
|
} |
1231 |
|
catch (InvocationTargetException x) |
1232 |
|
{ |
1233 |
|
/* Rethrow if possible. */ |
1234 |
|
Throwable exception = x.getTargetException(); |
1235 |
|
if (exception instanceof RuntimeException) |
1236 |
|
throw (RuntimeException) exception; |
1237 |
|
if (exception instanceof IOException) |
1238 |
|
throw (IOException) exception; |
1239 |
|
|
1240 |
|
throw new IOException ("Exception thrown from writeObject() on " + |
1241 |
|
klass + ": " + exception.getClass().getName()); |
1242 |
|
} |
1243 |
|
catch (Exception x) |
1244 |
|
{ |
1245 |
|
throw new IOException ("Failure invoking writeObject() on " + |
1246 |
|
klass + ": " + x.getClass().getName()); |
1247 |
|
} |
1248 |
|
} |
1249 |
|
|
1250 |
|
private boolean getBooleanField (Object obj, String field_name) throws IOException |
1251 |
|
{ |
1252 |
|
try |
1253 |
|
{ |
1254 |
|
Class klass = obj.getClass (); |
1255 |
|
Field f = getField (klass, field_name); |
1256 |
|
boolean b = f.getBoolean (obj); |
1257 |
|
return b; |
1258 |
|
} |
1259 |
|
catch (Exception _) |
1260 |
|
{ |
1261 |
|
throw new IOException (); |
1262 |
|
} |
1263 |
|
} |
1264 |
|
|
1265 |
|
private byte getByteField (Object obj, String field_name) throws IOException |
1266 |
|
{ |
1267 |
|
try |
1268 |
|
{ |
1269 |
|
Class klass = obj.getClass (); |
1270 |
|
Field f = getField (klass, field_name); |
1271 |
|
byte b = f.getByte (obj); |
1272 |
|
return b; |
1273 |
|
} |
1274 |
|
catch (Exception _) |
1275 |
|
{ |
1276 |
|
throw new IOException (); |
1277 |
|
} |
1278 |
|
} |
1279 |
|
|
1280 |
|
private char getCharField (Object obj, String field_name) throws IOException |
1281 |
|
{ |
1282 |
|
try |
1283 |
|
{ |
1284 |
|
Class klass = obj.getClass (); |
1285 |
|
Field f = getField (klass, field_name); |
1286 |
|
char b = f.getChar (obj); |
1287 |
|
return b; |
1288 |
|
} |
1289 |
|
catch (Exception _) |
1290 |
|
{ |
1291 |
|
throw new IOException (); |
1292 |
|
} |
1293 |
|
} |
1294 |
|
|
1295 |
|
private double getDoubleField (Object obj, String field_name) throws IOException |
1296 |
|
{ |
1297 |
|
try |
1298 |
|
{ |
1299 |
|
Class klass = obj.getClass (); |
1300 |
|
Field f = getField (klass, field_name); |
1301 |
|
double b = f.getDouble (obj); |
1302 |
|
return b; |
1303 |
|
} |
1304 |
|
catch (Exception _) |
1305 |
|
{ |
1306 |
|
throw new IOException (); |
1307 |
|
} |
1308 |
|
} |
1309 |
|
|
1310 |
|
private float getFloatField (Object obj, String field_name) throws IOException |
1311 |
|
{ |
1312 |
|
try |
1313 |
|
{ |
1314 |
|
Class klass = obj.getClass (); |
1315 |
|
Field f = getField (klass, field_name); |
1316 |
|
float b = f.getFloat (obj); |
1317 |
|
return b; |
1318 |
|
} |
1319 |
|
catch (Exception _) |
1320 |
|
{ |
1321 |
|
throw new IOException (); |
1322 |
|
} |
1323 |
|
} |
1324 |
|
|
1325 |
|
private int getIntField (Object obj, String field_name) throws IOException |
1326 |
|
{ |
1327 |
|
try |
1328 |
|
{ |
1329 |
|
Class klass = obj.getClass (); |
1330 |
|
Field f = getField (klass, field_name); |
1331 |
|
int b = f.getInt (obj); |
1332 |
|
return b; |
1333 |
|
} |
1334 |
|
catch (Exception _) |
1335 |
|
{ |
1336 |
|
throw new IOException (); |
1337 |
|
} |
1338 |
|
} |
1339 |
|
|
1340 |
|
private long getLongField (Object obj, String field_name) throws IOException |
1341 |
|
{ |
1342 |
|
try |
1343 |
|
{ |
1344 |
|
Class klass = obj.getClass (); |
1345 |
|
Field f = getField (klass, field_name); |
1346 |
|
long b = f.getLong (obj); |
1347 |
|
return b; |
1348 |
|
} |
1349 |
|
catch (Exception _) |
1350 |
|
{ |
1351 |
|
throw new IOException (); |
1352 |
|
} |
1353 |
|
} |
1354 |
|
|
1355 |
|
private short getShortField (Object obj, String field_name) throws IOException |
1356 |
|
{ |
1357 |
|
try |
1358 |
|
{ |
1359 |
|
Class klass = obj.getClass (); |
1360 |
|
Field f = getField (klass, field_name); |
1361 |
|
short b = f.getShort (obj); |
1362 |
|
return b; |
1363 |
|
} |
1364 |
|
catch (Exception _) |
1365 |
|
{ |
1366 |
|
throw new IOException (); |
1367 |
|
} |
1368 |
|
} |
1369 |
|
|
1370 |
|
private Object getObjectField (Object obj, String field_name, |
1371 |
|
String type_code) throws IOException |
1372 |
|
{ |
1373 |
|
try |
1374 |
|
{ |
1375 |
|
Class klass = obj.getClass (); |
1376 |
|
Field f = getField (klass, field_name); |
1377 |
|
Object o = f.get (obj); |
1378 |
|
// FIXME: We should check the type_code here |
1379 |
|
return o; |
1380 |
|
} |
1381 |
|
catch (Exception _) |
1382 |
|
{ |
1383 |
|
throw new IOException (); |
1384 |
|
} |
1385 |
|
} |
1386 |
|
|
1387 |
|
private static Field getField (Class klass, String name) |
1388 |
|
throws java.lang.NoSuchFieldException |
1389 |
|
{ |
1390 |
|
return klass.getDeclaredField(name); |
1391 |
|
} |
1392 |
|
|
1393 |
|
private static Method getMethod (Class klass, String name, Class[] args) |
1394 |
|
throws java.lang.NoSuchMethodException |
1395 |
|
{ |
1396 |
|
return klass.getDeclaredMethod(name, args); |
1397 |
|
} |
1398 |
|
|
1399 |
|
|
1400 |
// this value comes from 1.2 spec, but is used in 1.1 as well |
// this value comes from 1.2 spec, but is used in 1.1 as well |