| CONTENTS | PREV | NEXT | Java Object Serialization Specification |
The following symbols injava.io.ObjectStreamConstantsdefine the terminal and constant values expected in a stream.final static short STREAM_MAGIC = (short)0xaced; final static short STREAM_VERSION = 5; final static byte TC_NULL = (byte)0x70; final static byte TC_REFERENCE = (byte)0x71; final static byte TC_CLASSDESC = (byte)0x72; final static byte TC_OBJECT = (byte)0x73; final static byte TC_STRING = (byte)0x74; final static byte TC_ARRAY = (byte)0x75; final static byte TC_CLASS = (byte)0x76; final static byte TC_BLOCKDATA = (byte)0x77; final static byte TC_ENDBLOCKDATA = (byte)0x78; final static byte TC_RESET = (byte)0x79; final static byte TC_BLOCKDATALONG = (byte)0x7A; final static byte TC_EXCEPTION = (byte)0x7B; final static int baseWireHandle = 0x7E0000;The flag byte classDescFlags may include values offinal static byte SC_WRITE_METHOD = 0x01; //if SC_SERIALIZABLE final static byte SC_BLOCK_DATA = 0x08; //if SC_EXTERNALIZABLE final static byte SC_SERIALIZABLE = 0x02; final static byte SC_EXTERNALIZABLE = 0x04;The flagSC_WRITE_METHODis set if the Serializable class writing the stream had awriteObjectmethod that may have written additional data to the stream. In this case aTC_ENDBLOCKDATAmarker is always expected to terminate the data for that class.The flag
SC_BLOCKDATAis set if theExternalizableclass is written into the stream usingSTREAM_PROTOCOL_2. By default, this is the protocol used to writeExternalizableobjects into the stream in JDKTM 1.2. JDKTM 1.1 writesSTREAM_PROTOCOL_1.The flag
SC_SERIALIZABLEis set if the class that wrote the stream extendedjava.io.Serializablebut notjava.io.Externalizable, the class reading the stream must also extendjava.io.Serializableand the default serialization mechanism is to be used.The flag
SC_EXTERNALIZABLEis set if the class that wrote the stream extendedjava.io.Externalizable, the class reading the data must also extendExternalizableand the data will be read using itswriteExternalandreadExternalmethods.
Consider the case of an original class and two instances in a linked list:class List implements java.io.Serializable { int value; List next; public static void main(String[] args) { try { List list1 = new List(); List list2 = new List(); list1.value = 17; list1.next = list2; list2.value = 19; list2.next = null; ByteArrayOutputStream o = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(o); out.writeObject(list1); out.writeObject(list2); out.flush(); ... } catch (Exception ex) { ex.printStackTrace(); } } }The resulting stream contains:00: ac ed 00 05 73 72 00 04 4c 69 73 74 69 c8 8a 15 >....sr..Listi...<10: 40 16 ae 68 02 00 02 49 00 05 76 61 6c 75 65 4c >Z......I..valueL<20: 00 04 6e 65 78 74 74 00 06 4c 4c 69 73 74 3b 78 >..nextt..LList;x<30: 70 00 00 00 11 73 71 00 7e 00 00 00 00 00 13 70 >p....sq.~......p<40: 71 00 7e 00 03 >q.~..<