7 |
it under the terms of the GNU General Public License as published by |
it under the terms of the GNU General Public License as published by |
8 |
the Free Software Foundation; either version 2, or (at your option) |
the Free Software Foundation; either version 2, or (at your option) |
9 |
any later version. |
any later version. |
10 |
|
|
11 |
GNU Classpath is distributed in the hope that it will be useful, but |
GNU Classpath is distributed in the hope that it will be useful, but |
12 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
140 |
{ |
{ |
141 |
switch (marker) |
switch (marker) |
142 |
{ |
{ |
143 |
case TC_ENDBLOCKDATA: //wgs |
case TC_ENDBLOCKDATA: |
144 |
{ |
{ |
145 |
ret_val = null; |
ret_val = null; |
146 |
is_consumed = true; |
is_consumed = true; |
147 |
break; |
break; |
148 |
} |
} |
149 |
|
|
150 |
case TC_BLOCKDATA: |
case TC_BLOCKDATA: |
151 |
case TC_BLOCKDATALONG: |
case TC_BLOCKDATALONG: |
152 |
{ |
{ |
157 |
readNextBlock (marker); |
readNextBlock (marker); |
158 |
throw new StreamCorruptedException ("Unexpected blockData"); |
throw new StreamCorruptedException ("Unexpected blockData"); |
159 |
} |
} |
160 |
|
|
161 |
case TC_NULL: |
case TC_NULL: |
162 |
{ |
{ |
163 |
dumpElementln ("NULL"); |
dumpElementln ("NULL"); |
164 |
ret_val = null; |
ret_val = null; |
165 |
break; |
break; |
166 |
} |
} |
167 |
|
|
168 |
case TC_REFERENCE: |
case TC_REFERENCE: |
169 |
{ |
{ |
170 |
dumpElement ("REFERENCE "); |
dumpElement ("REFERENCE "); |
174 |
this.objectLookupTable.get (oid)).object; |
this.objectLookupTable.get (oid)).object; |
175 |
break; |
break; |
176 |
} |
} |
177 |
|
|
178 |
case TC_CLASS: |
case TC_CLASS: |
179 |
{ |
{ |
180 |
dumpElementln ("CLASS"); |
dumpElementln ("CLASS"); |
184 |
ret_val = clazz; |
ret_val = clazz; |
185 |
break; |
break; |
186 |
} |
} |
187 |
|
|
188 |
case TC_PROXYCLASSDESC: |
case TC_PROXYCLASSDESC: |
189 |
{ |
{ |
190 |
dumpElementln ("PROXYCLASS"); |
dumpElementln ("PROXYCLASS"); |
191 |
int n_intf = this.realInputStream.readInt(); |
int n_intf = this.realInputStream.readInt(); |
192 |
String[] intfs = new String[n_intf]; |
String[] intfs = new String[n_intf]; |
193 |
for (int i = 0; i < n_intf; i++) |
for (int i = 0; i < n_intf; i++) |
194 |
{ |
{ |
195 |
intfs[i] = this.realInputStream.readUTF(); |
intfs[i] = this.realInputStream.readUTF(); |
196 |
System.out.println(intfs[i]); |
System.out.println(intfs[i]); |
216 |
ret_val = osc; |
ret_val = osc; |
217 |
break; |
break; |
218 |
} |
} |
219 |
|
|
220 |
case TC_CLASSDESC: |
case TC_CLASSDESC: |
221 |
{ |
{ |
222 |
dumpElement ("CLASSDESC NAME="); |
dumpElement ("CLASSDESC NAME="); |
247 |
else |
else |
248 |
class_name = String.valueOf (type_code); |
class_name = String.valueOf (type_code); |
249 |
|
|
250 |
// There're many cases you can't get java.lang.Class from typename |
// There're many cases you can't get java.lang.Class from |
251 |
// if your context |
// typename if your context class loader can't load it, |
252 |
// class loader can't load it, then use typename to construct the field |
// then use typename to construct the field |
253 |
fields[i] = |
fields[i] = |
254 |
new ObjectStreamField (field_name, class_name); |
new ObjectStreamField (field_name, class_name); |
|
//new ObjectStreamField (field_name, TypeSignature.getClassForEncoding(class_name)); |
|
255 |
} |
} |
256 |
|
|
257 |
boolean oldmode = setBlockDataMode (true); |
boolean oldmode = setBlockDataMode (true); |
271 |
ret_val = osc; |
ret_val = osc; |
272 |
break; |
break; |
273 |
} |
} |
274 |
|
|
275 |
case TC_STRING: |
case TC_STRING: |
276 |
case TC_LONGSTRING: |
case TC_LONGSTRING: |
277 |
{ |
{ |
281 |
ret_val = processResolution (s, assignNewHandle (s)); |
ret_val = processResolution (s, assignNewHandle (s)); |
282 |
break; |
break; |
283 |
} |
} |
284 |
|
|
285 |
case TC_ARRAY: |
case TC_ARRAY: |
286 |
{ |
{ |
287 |
dumpElementln ("ARRAY"); |
dumpElementln ("ARRAY"); |
288 |
ObjectStreamClass osc = (ObjectStreamClass)readObject (); |
ObjectStreamClass osc = (ObjectStreamClass)readObject (); |
289 |
Class componenetType = osc.forClass ().getComponentType (); |
Class componentType = osc.forClass ().getComponentType (); |
290 |
dumpElement ("ARRAY LENGTH="); |
dumpElement ("ARRAY LENGTH="); |
291 |
int length = this.realInputStream.readInt (); |
int length = this.realInputStream.readInt (); |
292 |
dumpElementln (length + "; COMPONENT TYPE=" + componenetType); |
dumpElementln (length + "; COMPONENT TYPE=" + componentType); |
293 |
Object array = Array.newInstance (componenetType, length); |
Object array = Array.newInstance (componentType, length); |
294 |
int handle = assignNewHandle (array); |
int handle = assignNewHandle (array); |
295 |
readArrayElements (array, componenetType); |
readArrayElements (array, componentType); |
296 |
for (int i=0, len=Array.getLength(array); i < len; i++) |
for (int i=0, len=Array.getLength(array); i < len; i++) |
297 |
dumpElementln (" ELEMENT[" + i + "]=" + Array.get(array, i)); |
dumpElementln (" ELEMENT[" + i + "]=" + Array.get(array, i)); |
298 |
ret_val = processResolution (array, handle); |
ret_val = processResolution (array, handle); |
299 |
break; |
break; |
300 |
} |
} |
301 |
|
|
302 |
case TC_OBJECT: |
case TC_OBJECT: |
303 |
{ |
{ |
304 |
dumpElementln ("OBJECT"); |
dumpElementln ("OBJECT"); |
356 |
|| Modifier.isAbstract (first_nonserial.getModifiers ())) |
|| Modifier.isAbstract (first_nonserial.getModifiers ())) |
357 |
first_nonserial = first_nonserial.getSuperclass (); |
first_nonserial = first_nonserial.getSuperclass (); |
358 |
|
|
|
// DEBUGln ("Using " + first_nonserial |
|
|
// + " as starting point for constructing " + clazz); |
|
|
|
|
359 |
Object obj = null; |
Object obj = null; |
360 |
obj = newObject (clazz, first_nonserial); |
obj = newObject (clazz, first_nonserial); |
361 |
|
|
368 |
ObjectStreamClass[] hierarchy = |
ObjectStreamClass[] hierarchy = |
369 |
ObjectStreamClass.getObjectStreamClasses (clazz); |
ObjectStreamClass.getObjectStreamClasses (clazz); |
370 |
|
|
|
// DEBUGln ("Got class hierarchy of depth " + hierarchy.length); |
|
|
|
|
371 |
boolean has_read; |
boolean has_read; |
372 |
for (int i=0; i < hierarchy.length; i++) |
for (int i=0; i < hierarchy.length; i++) |
373 |
{ |
{ |
387 |
{ |
{ |
388 |
has_read = false; |
has_read = false; |
389 |
} |
} |
390 |
|
|
391 |
// XXX: should initialize fields in classes in the hierarchy |
// XXX: should initialize fields in classes in the hierarchy |
392 |
// that aren't in the stream |
// that aren't in the stream |
393 |
// should skip over classes in the stream that aren't in the |
// should skip over classes in the stream that aren't in the |
394 |
// real classes hierarchy |
// real classes hierarchy |
395 |
readFields (obj, this.currentObjectStreamClass.fields, |
readFields (obj, this.currentObjectStreamClass.fields, |
396 |
has_read, this.currentObjectStreamClass); |
has_read, this.currentObjectStreamClass); |
397 |
|
|
398 |
if (has_read) |
if (has_read) |
399 |
{ |
{ |
400 |
dumpElement ("ENDBLOCKDATA? "); |
dumpElement ("ENDBLOCKDATA? "); |
416 |
} |
} |
417 |
} |
} |
418 |
} |
} |
419 |
|
|
420 |
this.currentObject = null; |
this.currentObject = null; |
421 |
this.currentObjectStreamClass = null; |
this.currentObjectStreamClass = null; |
422 |
ret_val = processResolution (obj, handle); |
ret_val = processResolution (obj, handle); |
423 |
break; |
break; |
424 |
} |
} |
425 |
|
|
426 |
case TC_RESET: |
case TC_RESET: |
427 |
dumpElementln ("RESET"); |
dumpElementln ("RESET"); |
428 |
clearHandles (); |
clearHandles (); |
429 |
ret_val = readObject (); |
ret_val = readObject (); |
430 |
break; |
break; |
431 |
|
|
432 |
case TC_EXCEPTION: |
case TC_EXCEPTION: |
433 |
{ |
{ |
434 |
dumpElement ("EXCEPTION="); |
dumpElement ("EXCEPTION="); |
435 |
Exception e = (Exception)readObject (); |
Exception e = (Exception)readObject (); |
436 |
dumpElementln (e.toString()); |
dumpElementln (e.toString()); |
437 |
clearHandles (); |
clearHandles (); |
|
//try{ |
|
438 |
throw new WriteAbortedException ("Exception thrown during writing of stream", e); |
throw new WriteAbortedException ("Exception thrown during writing of stream", e); |
|
//}catch(IOException _){ |
|
|
// ret_val = null; |
|
|
//} |
|
|
//break; |
|
439 |
} |
} |
440 |
|
|
441 |
default: |
default: |
442 |
throw new IOException ("Unknown marker on stream: " + marker); |
throw new IOException ("Unknown marker on stream: " + marker); |
443 |
} |
} |
450 |
|
|
451 |
if (! was_deserializing) |
if (! was_deserializing) |
452 |
{ |
{ |
|
//setBlockDataMode (true); |
|
|
|
|
453 |
if (validators.size () > 0) |
if (validators.size () > 0) |
454 |
invokeValidators (); |
invokeValidators (); |
455 |
} |
} |
458 |
return ret_val; |
return ret_val; |
459 |
} |
} |
460 |
|
|
|
|
|
461 |
/** |
/** |
462 |
Reads the current objects non-transient, non-static fields from |
Reads the current objects non-transient, non-static fields from |
463 |
the current class from the underlying output stream. |
the current class from the underlying output stream. |
548 |
protected Class resolveClass (ObjectStreamClass osc) |
protected Class resolveClass (ObjectStreamClass osc) |
549 |
throws ClassNotFoundException, IOException |
throws ClassNotFoundException, IOException |
550 |
{ |
{ |
|
// DEBUGln ("Resolving " + osc); |
|
|
|
|
551 |
SecurityManager sm = System.getSecurityManager (); |
SecurityManager sm = System.getSecurityManager (); |
|
|
|
552 |
if (sm == null) |
if (sm == null) |
553 |
sm = new SecurityManager () {}; |
sm = new SecurityManager () {}; |
554 |
|
|
555 |
ClassLoader cl = currentClassLoader (sm); |
ClassLoader cl = currentClassLoader (sm); |
556 |
|
|
557 |
if (cl == null) |
if (cl == null) |
|
{ |
|
|
// DEBUGln ("No class loader found"); |
|
558 |
return Class.forName (osc.getName ()); |
return Class.forName (osc.getName ()); |
|
} |
|
559 |
else |
else |
|
{ |
|
|
// DEBUGln ("Using " + cl); |
|
560 |
return cl.loadClass (osc.getName ()); |
return cl.loadClass (osc.getName ()); |
|
} |
|
561 |
} |
} |
562 |
|
|
|
|
|
563 |
/** |
/** |
564 |
Allows subclasses to resolve objects that are read from the |
Allows subclasses to resolve objects that are read from the |
565 |
stream with other objects to be returned in their place. This |
stream with other objects to be returned in their place. This |
654 |
public int read () throws IOException |
public int read () throws IOException |
655 |
{ |
{ |
656 |
if (this.readDataFromBlock) |
if (this.readDataFromBlock) |
657 |
{ |
{ |
658 |
if (this.blockDataPosition >= this.blockDataBytes) |
if (this.blockDataPosition >= this.blockDataBytes) |
659 |
readNextBlock (); |
readNextBlock (); |
660 |
return (this.blockData[this.blockDataPosition++] & 0xff); |
return (this.blockData[this.blockDataPosition++] & 0xff); |
661 |
} |
} |
662 |
else |
else |
663 |
return this.realInputStream.read (); |
return this.realInputStream.read (); |
664 |
} |
} |
666 |
public int read (byte[] data, int offset, int length) throws IOException |
public int read (byte[] data, int offset, int length) throws IOException |
667 |
{ |
{ |
668 |
if (this.readDataFromBlock) |
if (this.readDataFromBlock) |
669 |
{ |
{ |
670 |
if (this.blockDataPosition + length > this.blockDataBytes) |
if (this.blockDataPosition + length > this.blockDataBytes) |
671 |
{ |
{ |
672 |
int remain = this.blockDataBytes - this.blockDataPosition; |
int remain = this.blockDataBytes - this.blockDataPosition; |
673 |
if (remain != 0) |
if (remain != 0) |
674 |
{ |
{ |
675 |
System.arraycopy (this.blockData, this.blockDataPosition, |
System.arraycopy (this.blockData, this.blockDataPosition, |
676 |
data, offset, remain); |
data, offset, remain); |
677 |
offset += remain; |
offset += remain; |
678 |
length -= remain; |
length -= remain; |
679 |
} |
} |
680 |
readNextBlock (); |
readNextBlock (); |
681 |
} |
} |
682 |
|
|
683 |
System.arraycopy (this.blockData, this.blockDataPosition, |
System.arraycopy (this.blockData, this.blockDataPosition, |
684 |
data, offset, length); |
data, offset, length); |
685 |
this.blockDataPosition += length; |
this.blockDataPosition += length; |
686 |
|
|
687 |
return length; |
return length; |
688 |
} |
} |
689 |
else |
else |
690 |
return this.realInputStream.read (data, offset, length); |
return this.realInputStream.read (data, offset, length); |
691 |
} |
} |
693 |
public int available () throws IOException |
public int available () throws IOException |
694 |
{ |
{ |
695 |
if (this.readDataFromBlock) |
if (this.readDataFromBlock) |
696 |
{ |
{ |
697 |
if (this.blockDataPosition >= this.blockDataBytes) |
if (this.blockDataPosition >= this.blockDataBytes) |
698 |
readNextBlock (); |
readNextBlock (); |
699 |
|
|
700 |
return this.blockDataBytes - this.blockDataPosition; |
return this.blockDataBytes - this.blockDataPosition; |
701 |
} |
} |
702 |
else |
else |
703 |
return this.realInputStream.available (); |
return this.realInputStream.available (); |
704 |
} |
} |
943 |
setBlockDataMode (oldmode); |
setBlockDataMode (oldmode); |
944 |
|
|
945 |
return new GetField () |
return new GetField () |
|
{ |
|
|
public ObjectStreamClass getObjectStreamClass () |
|
946 |
{ |
{ |
947 |
return clazz; |
public ObjectStreamClass getObjectStreamClass () |
948 |
} |
{ |
949 |
|
return clazz; |
950 |
public boolean defaulted (String name) |
} |
|
throws IOException, IllegalArgumentException |
|
|
{ |
|
|
return clazz.getField (name) == null; |
|
|
} |
|
951 |
|
|
952 |
public boolean get (String name, boolean defvalue) |
public boolean defaulted (String name) |
953 |
throws IOException, IllegalArgumentException |
throws IOException, IllegalArgumentException |
954 |
{ |
{ |
955 |
ObjectStreamField field = getField (name, Boolean.TYPE); |
return clazz.getField (name) == null; |
956 |
|
} |
957 |
|
|
958 |
if (field == null) |
public boolean get (String name, boolean defvalue) |
959 |
return defvalue; |
throws IOException, IllegalArgumentException |
960 |
|
{ |
961 |
|
ObjectStreamField field = getField (name, Boolean.TYPE); |
962 |
|
|
963 |
return prim_field_data[field.getOffset ()] == 0 ? false : true; |
if (field == null) |
964 |
} |
return defvalue; |
965 |
|
|
966 |
public char get (String name, char defvalue) |
return prim_field_data[field.getOffset ()] == 0 ? false : true; |
967 |
throws IOException, IllegalArgumentException |
} |
|
{ |
|
|
ObjectStreamField field = getField (name, Character.TYPE); |
|
968 |
|
|
969 |
if (field == null) |
public char get (String name, char defvalue) |
970 |
return defvalue; |
throws IOException, IllegalArgumentException |
971 |
|
{ |
972 |
|
ObjectStreamField field = getField (name, Character.TYPE); |
973 |
|
|
974 |
int off = field.getOffset (); |
if (field == null) |
975 |
|
return defvalue; |
976 |
|
|
977 |
return (char)(((prim_field_data[off++] & 0xFF) << 8) |
int off = field.getOffset (); |
|
| (prim_field_data[off] & 0xFF)); |
|
|
} |
|
978 |
|
|
979 |
public byte get (String name, byte defvalue) |
return (char)(((prim_field_data[off++] & 0xFF) << 8) |
980 |
throws IOException, IllegalArgumentException |
| (prim_field_data[off] & 0xFF)); |
981 |
{ |
} |
|
ObjectStreamField field = getField (name, Byte.TYPE); |
|
982 |
|
|
983 |
if (field == null) |
public byte get (String name, byte defvalue) |
984 |
return defvalue; |
throws IOException, IllegalArgumentException |
985 |
|
{ |
986 |
|
ObjectStreamField field = getField (name, Byte.TYPE); |
987 |
|
|
988 |
return prim_field_data[field.getOffset ()]; |
if (field == null) |
989 |
} |
return defvalue; |
990 |
|
|
991 |
public short get (String name, short defvalue) |
return prim_field_data[field.getOffset ()]; |
992 |
throws IOException, IllegalArgumentException |
} |
|
{ |
|
|
ObjectStreamField field = getField (name, Short.TYPE); |
|
993 |
|
|
994 |
if (field == null) |
public short get (String name, short defvalue) |
995 |
return defvalue; |
throws IOException, IllegalArgumentException |
996 |
|
{ |
997 |
|
ObjectStreamField field = getField (name, Short.TYPE); |
998 |
|
|
999 |
int off = field.getOffset (); |
if (field == null) |
1000 |
|
return defvalue; |
1001 |
|
|
1002 |
return (short)(((prim_field_data[off++] & 0xFF) << 8) |
int off = field.getOffset (); |
|
| (prim_field_data[off] & 0xFF)); |
|
|
} |
|
1003 |
|
|
1004 |
public int get (String name, int defvalue) |
return (short)(((prim_field_data[off++] & 0xFF) << 8) |
1005 |
throws IOException, IllegalArgumentException |
| (prim_field_data[off] & 0xFF)); |
1006 |
{ |
} |
|
ObjectStreamField field = getField (name, Integer.TYPE); |
|
1007 |
|
|
1008 |
if (field == null) |
public int get (String name, int defvalue) |
1009 |
return defvalue; |
throws IOException, IllegalArgumentException |
1010 |
|
{ |
1011 |
|
ObjectStreamField field = getField (name, Integer.TYPE); |
1012 |
|
|
1013 |
int off = field.getOffset (); |
if (field == null) |
1014 |
|
return defvalue; |
1015 |
|
|
1016 |
return ((prim_field_data[off++] & 0xFF) << 24) |
int off = field.getOffset (); |
|
| ((prim_field_data[off++] & 0xFF) << 16) |
|
|
| ((prim_field_data[off++] & 0xFF) << 8) |
|
|
| (prim_field_data[off] & 0xFF); |
|
|
} |
|
1017 |
|
|
1018 |
public long get (String name, long defvalue) |
return ((prim_field_data[off++] & 0xFF) << 24) |
1019 |
throws IOException, IllegalArgumentException |
| ((prim_field_data[off++] & 0xFF) << 16) |
1020 |
{ |
| ((prim_field_data[off++] & 0xFF) << 8) |
1021 |
ObjectStreamField field = getField (name, Long.TYPE); |
| (prim_field_data[off] & 0xFF); |
1022 |
|
} |
1023 |
|
|
1024 |
if (field == null) |
public long get (String name, long defvalue) |
1025 |
return defvalue; |
throws IOException, IllegalArgumentException |
1026 |
|
{ |
1027 |
|
ObjectStreamField field = getField (name, Long.TYPE); |
1028 |
|
|
1029 |
int off = field.getOffset (); |
if (field == null) |
1030 |
|
return defvalue; |
1031 |
|
|
1032 |
return (long)(((prim_field_data[off++] & 0xFF) << 56) |
int off = field.getOffset (); |
|
| ((prim_field_data[off++] & 0xFF) << 48) |
|
|
| ((prim_field_data[off++] & 0xFF) << 40) |
|
|
| ((prim_field_data[off++] & 0xFF) << 32) |
|
|
| ((prim_field_data[off++] & 0xFF) << 24) |
|
|
| ((prim_field_data[off++] & 0xFF) << 16) |
|
|
| ((prim_field_data[off++] & 0xFF) << 8) |
|
|
| (prim_field_data[off] & 0xFF)); |
|
|
} |
|
1033 |
|
|
1034 |
public float get (String name, float defvalue) |
return (long)(((prim_field_data[off++] & 0xFF) << 56) |
1035 |
throws IOException, IllegalArgumentException |
| ((prim_field_data[off++] & 0xFF) << 48) |
1036 |
{ |
| ((prim_field_data[off++] & 0xFF) << 40) |
1037 |
ObjectStreamField field = getField (name, Float.TYPE); |
| ((prim_field_data[off++] & 0xFF) << 32) |
1038 |
|
| ((prim_field_data[off++] & 0xFF) << 24) |
1039 |
|
| ((prim_field_data[off++] & 0xFF) << 16) |
1040 |
|
| ((prim_field_data[off++] & 0xFF) << 8) |
1041 |
|
| (prim_field_data[off] & 0xFF)); |
1042 |
|
} |
1043 |
|
|
1044 |
if (field == null) |
public float get (String name, float defvalue) |
1045 |
return defvalue; |
throws IOException, IllegalArgumentException |
1046 |
|
{ |
1047 |
|
ObjectStreamField field = getField (name, Float.TYPE); |
1048 |
|
|
1049 |
int off = field.getOffset (); |
if (field == null) |
1050 |
|
return defvalue; |
1051 |
|
|
1052 |
return Float.intBitsToFloat (((prim_field_data[off++] & 0xFF) << 24) |
int off = field.getOffset (); |
|
| ((prim_field_data[off++] & 0xFF) << 16) |
|
|
| ((prim_field_data[off++] & 0xFF) << 8) |
|
|
| (prim_field_data[off] & 0xFF)); |
|
|
} |
|
1053 |
|
|
1054 |
public double get (String name, double defvalue) |
return Float.intBitsToFloat (((prim_field_data[off++] & 0xFF) << 24) |
1055 |
throws IOException, IllegalArgumentException |
| ((prim_field_data[off++] & 0xFF) << 16) |
1056 |
{ |
| ((prim_field_data[off++] & 0xFF) << 8) |
1057 |
ObjectStreamField field = getField (name, Double.TYPE); |
| (prim_field_data[off] & 0xFF)); |
1058 |
|
} |
1059 |
|
|
1060 |
if (field == null) |
public double get (String name, double defvalue) |
1061 |
return defvalue; |
throws IOException, IllegalArgumentException |
1062 |
|
{ |
1063 |
|
ObjectStreamField field = getField (name, Double.TYPE); |
1064 |
|
|
1065 |
int off = field.getOffset (); |
if (field == null) |
1066 |
|
return defvalue; |
1067 |
|
|
1068 |
return Double.longBitsToDouble ( |
int off = field.getOffset (); |
|
(long)(((prim_field_data[off++] & 0xFF) << 56) |
|
|
| ((prim_field_data[off++] & 0xFF) << 48) |
|
|
| ((prim_field_data[off++] & 0xFF) << 40) |
|
|
| ((prim_field_data[off++] & 0xFF) << 32) |
|
|
| ((prim_field_data[off++] & 0xFF) << 24) |
|
|
| ((prim_field_data[off++] & 0xFF) << 16) |
|
|
| ((prim_field_data[off++] & 0xFF) << 8) |
|
|
| (prim_field_data[off] & 0xFF))); |
|
|
} |
|
1069 |
|
|
1070 |
public Object get (String name, Object defvalue) |
return Double.longBitsToDouble |
1071 |
throws IOException, IllegalArgumentException |
( (long) (((prim_field_data[off++] & 0xFF) << 56) |
1072 |
{ |
| ((prim_field_data[off++] & 0xFF) << 48) |
1073 |
ObjectStreamField field = |
| ((prim_field_data[off++] & 0xFF) << 40) |
1074 |
getField (name, defvalue == null ? null : defvalue.getClass ()); |
| ((prim_field_data[off++] & 0xFF) << 32) |
1075 |
|
| ((prim_field_data[off++] & 0xFF) << 24) |
1076 |
|
| ((prim_field_data[off++] & 0xFF) << 16) |
1077 |
|
| ((prim_field_data[off++] & 0xFF) << 8) |
1078 |
|
| (prim_field_data[off] & 0xFF))); |
1079 |
|
} |
1080 |
|
|
1081 |
if (field == null) |
public Object get (String name, Object defvalue) |
1082 |
return defvalue; |
throws IOException, IllegalArgumentException |
1083 |
|
{ |
1084 |
|
ObjectStreamField field = |
1085 |
|
getField (name, defvalue == null ? null : defvalue.getClass ()); |
1086 |
|
|
1087 |
return objs[field.getOffset ()]; |
if (field == null) |
1088 |
} |
return defvalue; |
1089 |
|
|
1090 |
private ObjectStreamField getField (String name, Class type) |
return objs[field.getOffset ()]; |
1091 |
throws IllegalArgumentException |
} |
|
{ |
|
|
ObjectStreamField field = clazz.getField (name); |
|
1092 |
|
|
1093 |
if (field == null) |
private ObjectStreamField getField (String name, Class type) |
1094 |
return null; |
throws IllegalArgumentException |
1095 |
|
{ |
1096 |
|
ObjectStreamField field = clazz.getField (name); |
1097 |
|
|
1098 |
Class field_type = field.getType (); |
if (field == null) |
1099 |
|
return null; |
1100 |
|
|
1101 |
if (type == field_type || |
Class field_type = field.getType (); |
|
(type == null && ! field_type.isPrimitive ())) |
|
|
return field; |
|
1102 |
|
|
1103 |
throw new IllegalArgumentException ("Field requested is of type " |
if (type == field_type || |
1104 |
+ field_type.getName () |
(type == null && ! field_type.isPrimitive ())) |
1105 |
+ ", but requested type was " |
return field; |
1106 |
+ (type == null ? |
|
1107 |
"Object" : type.getName ())); |
throw new IllegalArgumentException ("Field requested is of type " |
1108 |
} |
+ field_type.getName () |
1109 |
}; |
+ ", but requested type was " |
1110 |
|
+ (type == null ? |
1111 |
|
"Object" : type.getName ())); |
1112 |
|
} |
1113 |
|
}; |
1114 |
|
|
1115 |
} |
} |
1116 |
|
|
1156 |
private int assignNewHandle (Object obj) |
private int assignNewHandle (Object obj) |
1157 |
{ |
{ |
1158 |
this.objectLookupTable.put (new Integer (this.nextOID), |
this.objectLookupTable.put (new Integer (this.nextOID), |
1159 |
new ObjectIdentityWrapper (obj)); |
new ObjectIdentityWrapper (obj)); |
|
|
|
|
// try |
|
|
// { |
|
|
// DEBUG ("Assigning handle " + this.nextOID); |
|
|
// DEBUGln (" to " + obj); |
|
|
// } |
|
|
// catch (Throwable t) {} |
|
|
|
|
1160 |
return this.nextOID++; |
return this.nextOID++; |
1161 |
} |
} |
1162 |
|
|
1168 |
{ |
{ |
1169 |
Method m = null; |
Method m = null; |
1170 |
try |
try |
1171 |
{ |
{ |
1172 |
Class classArgs[] = {}; |
Class classArgs[] = {}; |
1173 |
m = obj.getClass ().getDeclaredMethod ("readResolve", classArgs); |
m = obj.getClass ().getDeclaredMethod ("readResolve", classArgs); |
1174 |
// m can't be null by definition since an exception would |
// m can't be null by definition since an exception would |
1175 |
// have been thrown so a check for null is not needed. |
// have been thrown so a check for null is not needed. |
1176 |
obj = m.invoke (obj, new Object[] {}); |
obj = m.invoke (obj, new Object[] {}); |
1177 |
} |
} |
1178 |
catch (NoSuchMethodException ignore) |
catch (NoSuchMethodException ignore) |
1179 |
{ |
{ |
1180 |
} |
} |
1181 |
catch (IllegalAccessException ignore) |
catch (IllegalAccessException ignore) |
1182 |
{ |
{ |
1183 |
} |
} |
1184 |
catch (InvocationTargetException ignore) |
catch (InvocationTargetException ignore) |
1185 |
{ |
{ |
1186 |
} |
} |
1187 |
} |
} |
1188 |
|
|
1189 |
if (this.resolveEnabled) |
if (this.resolveEnabled) |
1205 |
|
|
1206 |
private void readNextBlock () throws IOException |
private void readNextBlock () throws IOException |
1207 |
{ |
{ |
|
// DEBUGln ("In readNextBlock "); |
|
1208 |
readNextBlock (this.realInputStream.readByte ()); |
readNextBlock (this.realInputStream.readByte ()); |
1209 |
} |
} |
1210 |
|
|
1212 |
private void readNextBlock (byte marker) throws IOException |
private void readNextBlock (byte marker) throws IOException |
1213 |
{ |
{ |
1214 |
if (marker == TC_BLOCKDATA) |
if (marker == TC_BLOCKDATA) |
1215 |
{ |
{ |
1216 |
dumpElement ("BLOCK DATA SIZE="); |
dumpElement ("BLOCK DATA SIZE="); |
1217 |
this.blockDataBytes = this.realInputStream.readUnsignedByte (); |
this.blockDataBytes = this.realInputStream.readUnsignedByte (); |
1218 |
dumpElementln (Integer.toString(this.blockDataBytes)); |
dumpElementln (Integer.toString(this.blockDataBytes)); |
1219 |
} |
} |
1220 |
else if (marker == TC_BLOCKDATALONG) |
else if (marker == TC_BLOCKDATALONG) |
1221 |
{ |
{ |
1222 |
dumpElement ("BLOCK DATA LONG SIZE="); |
dumpElement ("BLOCK DATA LONG SIZE="); |
1223 |
this.blockDataBytes = this.realInputStream.readInt (); |
this.blockDataBytes = this.realInputStream.readInt (); |
1224 |
dumpElementln (Integer.toString(this.blockDataBytes)); |
dumpElementln (Integer.toString(this.blockDataBytes)); |
1225 |
} |
} |
1226 |
else |
else |
1227 |
{ |
{ |
1228 |
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."); |
1229 |
} |
} |
1230 |
|
|
1231 |
if (this.blockData.length < this.blockDataBytes) |
if (this.blockData.length < this.blockDataBytes) |
1232 |
this.blockData = new byte[this.blockDataBytes]; |
this.blockData = new byte[this.blockDataBytes]; |
1240 |
throws ClassNotFoundException, IOException |
throws ClassNotFoundException, IOException |
1241 |
{ |
{ |
1242 |
if (clazz.isPrimitive ()) |
if (clazz.isPrimitive ()) |
|
{ |
|
|
if (clazz == Boolean.TYPE) |
|
1243 |
{ |
{ |
1244 |
boolean[] cast_array = (boolean[])array; |
if (clazz == Boolean.TYPE) |
1245 |
for (int i=0; i < cast_array.length; i++) |
{ |
1246 |
cast_array[i] = this.realInputStream.readBoolean (); |
boolean[] cast_array = (boolean[])array; |
1247 |
return; |
for (int i=0; i < cast_array.length; i++) |
1248 |
} |
cast_array[i] = this.realInputStream.readBoolean (); |
1249 |
if (clazz == Byte.TYPE) |
return; |
1250 |
{ |
} |
1251 |
byte[] cast_array = (byte[])array; |
if (clazz == Byte.TYPE) |
1252 |
for (int i=0; i < cast_array.length; i++) |
{ |
1253 |
cast_array[i] = this.realInputStream.readByte (); |
byte[] cast_array = (byte[])array; |
1254 |
return; |
for (int i=0; i < cast_array.length; i++) |
1255 |
} |
cast_array[i] = this.realInputStream.readByte (); |
1256 |
if (clazz == Character.TYPE) |
return; |
1257 |
{ |
} |
1258 |
char[] cast_array = (char[])array; |
if (clazz == Character.TYPE) |
1259 |
for (int i=0; i < cast_array.length; i++) |
{ |
1260 |
cast_array[i] = this.realInputStream.readChar (); |
char[] cast_array = (char[])array; |
1261 |
return; |
for (int i=0; i < cast_array.length; i++) |
1262 |
} |
cast_array[i] = this.realInputStream.readChar (); |
1263 |
if (clazz == Double.TYPE) |
return; |
1264 |
{ |
} |
1265 |
double[] cast_array = (double[])array; |
if (clazz == Double.TYPE) |
1266 |
for (int i=0; i < cast_array.length; i++) |
{ |
1267 |
cast_array[i] = this.realInputStream.readDouble (); |
double[] cast_array = (double[])array; |
1268 |
return; |
for (int i=0; i < cast_array.length; i++) |
1269 |
} |
cast_array[i] = this.realInputStream.readDouble (); |
1270 |
if (clazz == Float.TYPE) |
return; |
1271 |
{ |
} |
1272 |
float[] cast_array = (float[])array; |
if (clazz == Float.TYPE) |
1273 |
for (int i=0; i < cast_array.length; i++) |
{ |
1274 |
cast_array[i] = this.realInputStream.readFloat (); |
float[] cast_array = (float[])array; |
1275 |
return; |
for (int i=0; i < cast_array.length; i++) |
1276 |
} |
cast_array[i] = this.realInputStream.readFloat (); |
1277 |
if (clazz == Integer.TYPE) |
return; |
1278 |
{ |
} |
1279 |
int[] cast_array = (int[])array; |
if (clazz == Integer.TYPE) |
1280 |
for (int i=0; i < cast_array.length; i++) |
{ |
1281 |
cast_array[i] = this.realInputStream.readInt (); |
int[] cast_array = (int[])array; |
1282 |
return; |
for (int i=0; i < cast_array.length; i++) |
1283 |
} |
cast_array[i] = this.realInputStream.readInt (); |
1284 |
if (clazz == Long.TYPE) |
return; |
1285 |
{ |
} |
1286 |
long[] cast_array = (long[])array; |
if (clazz == Long.TYPE) |
1287 |
for (int i=0; i < cast_array.length; i++) |
{ |
1288 |
cast_array[i] = this.realInputStream.readLong (); |
long[] cast_array = (long[])array; |
1289 |
return; |
for (int i=0; i < cast_array.length; i++) |
1290 |
|
cast_array[i] = this.realInputStream.readLong (); |
1291 |
|
return; |
1292 |
|
} |
1293 |
|
if (clazz == Short.TYPE) |
1294 |
|
{ |
1295 |
|
short[] cast_array = (short[])array; |
1296 |
|
for (int i=0; i < cast_array.length; i++) |
1297 |
|
cast_array[i] = this.realInputStream.readShort (); |
1298 |
|
return; |
1299 |
|
} |
1300 |
} |
} |
1301 |
if (clazz == Short.TYPE) |
else |
1302 |
{ |
{ |
1303 |
short[] cast_array = (short[])array; |
Object[] cast_array = (Object[])array; |
1304 |
for (int i=0; i < cast_array.length; i++) |
for (int i=0; i < cast_array.length; i++) |
|
cast_array[i] = this.realInputStream.readShort (); |
|
|
return; |
|
|
} |
|
|
} |
|
|
else |
|
|
{ |
|
|
Object[] cast_array = (Object[])array; |
|
|
for (int i=0; i < cast_array.length; i++) |
|
1305 |
cast_array[i] = readObject (); |
cast_array[i] = readObject (); |
1306 |
} |
} |
1307 |
} |
} |
1308 |
|
|
1309 |
|
|
1312 |
ObjectStreamClass stream_osc) |
ObjectStreamClass stream_osc) |
1313 |
throws ClassNotFoundException, IOException |
throws ClassNotFoundException, IOException |
1314 |
{ |
{ |
|
// DEBUGln ("In readFields"); |
|
1315 |
if (call_read_method) |
if (call_read_method) |
1316 |
{ |
{ |
|
// DEBUGln (" call_read_method is true"); |
|
1317 |
fieldsAlreadyRead = false; |
fieldsAlreadyRead = false; |
1318 |
boolean oldmode = setBlockDataMode (true); |
boolean oldmode = setBlockDataMode (true); |
1319 |
callReadMethod (obj, stream_osc.forClass ()); |
callReadMethod (obj, stream_osc.forClass ()); |
1320 |
setBlockDataMode (oldmode); |
setBlockDataMode (oldmode); |
1321 |
return; |
return; |
1322 |
} |
} |
1323 |
|
|
1324 |
ObjectStreamField[] real_fields = |
ObjectStreamField[] real_fields = |
1325 |
ObjectStreamClass.lookup (stream_osc.forClass ()).fields; |
ObjectStreamClass.lookup (stream_osc.forClass ()).fields; |
1326 |
|
|
1327 |
boolean default_initialize, set_value; |
boolean default_initialize, set_value; |
1328 |
String field_name = null; |
String field_name = null; |
1329 |
Class type = null; |
Class type = null; |
1331 |
ObjectStreamField real_field = null; |
ObjectStreamField real_field = null; |
1332 |
int stream_idx = 0; |
int stream_idx = 0; |
1333 |
int real_idx = 0; |
int real_idx = 0; |
1334 |
|
|
1335 |
while (stream_idx < stream_fields.length |
while (stream_idx < stream_fields.length |
1336 |
&& real_idx < real_fields.length) |
&& real_idx < real_fields.length) |
1337 |
{ |
{ |
1338 |
default_initialize = false; |
default_initialize = false; |
1339 |
set_value = true; |
set_value = true; |
1340 |
|
|
1341 |
if (stream_idx == stream_fields.length) |
if (stream_idx == stream_fields.length) |
1342 |
default_initialize = true; |
default_initialize = true; |
1343 |
else |
else |
1345 |
stream_field = stream_fields[stream_idx]; |
stream_field = stream_fields[stream_idx]; |
1346 |
type = stream_field.getType (); |
type = stream_field.getType (); |
1347 |
} |
} |
1348 |
|
|
1349 |
if (real_idx == real_fields.length) |
if (real_idx == real_fields.length) |
1350 |
set_value = false; |
set_value = false; |
1351 |
else |
else |
1354 |
type = real_field.getType (); |
type = real_field.getType (); |
1355 |
field_name = real_field.getName (); |
field_name = real_field.getName (); |
1356 |
} |
} |
1357 |
|
|
1358 |
if (set_value && !default_initialize) |
if (set_value && !default_initialize) |
1359 |
{ |
{ |
1360 |
int comp_val = |
int comp_val = |
1361 |
real_field.compareTo (stream_field); |
real_field.compareTo (stream_field); |
1362 |
|
|
1363 |
if (comp_val < 0) |
if (comp_val < 0) |
1364 |
{ |
{ |
1365 |
default_initialize = true; |
default_initialize = true; |
1376 |
stream_idx++; |
stream_idx++; |
1377 |
} |
} |
1378 |
} |
} |
1379 |
|
|
1380 |
try |
try |
1381 |
{ |
{ |
1382 |
if (type == Boolean.TYPE) |
if (type == Boolean.TYPE) |
1383 |
{ |
{ |
1470 |
// Toggles writing primitive data to block-data buffer. |
// Toggles writing primitive data to block-data buffer. |
1471 |
private boolean setBlockDataMode (boolean on) |
private boolean setBlockDataMode (boolean on) |
1472 |
{ |
{ |
|
// DEBUGln ("Setting block data mode to " + on); |
|
1473 |
boolean oldmode = this.readDataFromBlock; |
boolean oldmode = this.readDataFromBlock; |
1474 |
this.readDataFromBlock = on; |
this.readDataFromBlock = on; |
1475 |
|
|
1486 |
private Object newObject (Class real_class, Class constructor_class) |
private Object newObject (Class real_class, Class constructor_class) |
1487 |
{ |
{ |
1488 |
try |
try |
1489 |
{ |
{ |
1490 |
Object obj = allocateObject (real_class); |
Object obj = allocateObject (real_class); |
1491 |
callConstructor (constructor_class, obj); |
callConstructor (constructor_class, obj); |
1492 |
return obj; |
return obj; |
1493 |
} |
} |
1494 |
catch (InstantiationException e) |
catch (InstantiationException e) |
1495 |
{ |
{ |
1496 |
return null; |
return null; |
1497 |
} |
} |
1498 |
} |
} |
1499 |
|
|
1500 |
|
|
1507 |
Arrays.sort (validators); |
Arrays.sort (validators); |
1508 |
|
|
1509 |
try |
try |
1510 |
{ |
{ |
1511 |
for (int i=0; i < validators.length; i++) |
for (int i=0; i < validators.length; i++) |
1512 |
((ObjectInputValidation)validators[i]).validateObject (); |
((ObjectInputValidation)validators[i]).validateObject (); |
1513 |
} |
} |
1514 |
finally |
finally |
1515 |
{ |
{ |
1516 |
this.validators.removeAllElements (); |
this.validators.removeAllElements (); |
1517 |
} |
} |
1518 |
} |
} |
1519 |
|
|
1520 |
|
|
1585 |
} |
} |
1586 |
|
|
1587 |
private void setByteField (Object obj, String field_name, |
private void setByteField (Object obj, String field_name, |
1588 |
byte val) |
byte val) |
1589 |
{ |
{ |
1590 |
try |
try |
1591 |
{ |
{ |
1645 |
} |
} |
1646 |
|
|
1647 |
private void setIntField (Object obj, String field_name, |
private void setIntField (Object obj, String field_name, |
1648 |
int val) |
int val) |
1649 |
{ |
{ |
1650 |
try |
try |
1651 |
{ |
{ |
1661 |
|
|
1662 |
|
|
1663 |
private void setLongField (Object obj, String field_name, |
private void setLongField (Object obj, String field_name, |
1664 |
long val) |
long val) |
1665 |
{ |
{ |
1666 |
try |
try |
1667 |
{ |
{ |
1728 |
private boolean fieldsAlreadyRead; |
private boolean fieldsAlreadyRead; |
1729 |
private Vector validators; |
private Vector validators; |
1730 |
|
|
1731 |
private static boolean dump = false; |
private static boolean dump; |
1732 |
|
|
1733 |
private void dumpElement (String msg) |
private void dumpElement (String msg) |
1734 |
{ |
{ |
1746 |
{ |
{ |
1747 |
if (Configuration.INIT_LOAD_LIBRARY) |
if (Configuration.INIT_LOAD_LIBRARY) |
1748 |
{ |
{ |
1749 |
System.loadLibrary ("javaio"); |
System.loadLibrary ("javaio"); |
1750 |
} |
} |
1751 |
} |
} |
|
|
|
|
private void DEBUG (String msg) |
|
|
{ |
|
|
System.out.print (msg); |
|
|
} |
|
|
|
|
|
|
|
|
private void DEBUGln (String msg) |
|
|
{ |
|
|
System.out.println (msg); |
|
|
} |
|
1752 |
} |
} |
1753 |
|
|
1754 |
|
|