ObjectStreamConstants.java revision 15740:fc037e62b9a4
1/* 2 * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26package java.io; 27 28/** 29 * Constants written into the Object Serialization Stream. 30 * 31 * @author unascribed 32 * @since 1.1 33 */ 34public interface ObjectStreamConstants { 35 36 /** 37 * Magic number that is written to the stream header. 38 */ 39 static final short STREAM_MAGIC = (short)0xaced; 40 41 /** 42 * Version number that is written to the stream header. 43 */ 44 static final short STREAM_VERSION = 5; 45 46 /* Each item in the stream is preceded by a tag 47 */ 48 49 /** 50 * First tag value. 51 */ 52 static final byte TC_BASE = 0x70; 53 54 /** 55 * Null object reference. 56 */ 57 static final byte TC_NULL = (byte)0x70; 58 59 /** 60 * Reference to an object already written into the stream. 61 */ 62 static final byte TC_REFERENCE = (byte)0x71; 63 64 /** 65 * new Class Descriptor. 66 */ 67 static final byte TC_CLASSDESC = (byte)0x72; 68 69 /** 70 * new Object. 71 */ 72 static final byte TC_OBJECT = (byte)0x73; 73 74 /** 75 * new String. 76 */ 77 static final byte TC_STRING = (byte)0x74; 78 79 /** 80 * new Array. 81 */ 82 static final byte TC_ARRAY = (byte)0x75; 83 84 /** 85 * Reference to Class. 86 */ 87 static final byte TC_CLASS = (byte)0x76; 88 89 /** 90 * Block of optional data. Byte following tag indicates number 91 * of bytes in this block data. 92 */ 93 static final byte TC_BLOCKDATA = (byte)0x77; 94 95 /** 96 * End of optional block data blocks for an object. 97 */ 98 static final byte TC_ENDBLOCKDATA = (byte)0x78; 99 100 /** 101 * Reset stream context. All handles written into stream are reset. 102 */ 103 static final byte TC_RESET = (byte)0x79; 104 105 /** 106 * long Block data. The long following the tag indicates the 107 * number of bytes in this block data. 108 */ 109 static final byte TC_BLOCKDATALONG= (byte)0x7A; 110 111 /** 112 * Exception during write. 113 */ 114 static final byte TC_EXCEPTION = (byte)0x7B; 115 116 /** 117 * Long string. 118 */ 119 static final byte TC_LONGSTRING = (byte)0x7C; 120 121 /** 122 * new Proxy Class Descriptor. 123 */ 124 static final byte TC_PROXYCLASSDESC = (byte)0x7D; 125 126 /** 127 * new Enum constant. 128 * @since 1.5 129 */ 130 static final byte TC_ENUM = (byte)0x7E; 131 132 /** 133 * Last tag value. 134 */ 135 static final byte TC_MAX = (byte)0x7E; 136 137 /** 138 * First wire handle to be assigned. 139 */ 140 static final int baseWireHandle = 0x7e0000; 141 142 143 /******************************************************/ 144 /* Bit masks for ObjectStreamClass flag.*/ 145 146 /** 147 * Bit mask for ObjectStreamClass flag. Indicates a Serializable class 148 * defines its own writeObject method. 149 */ 150 static final byte SC_WRITE_METHOD = 0x01; 151 152 /** 153 * Bit mask for ObjectStreamClass flag. Indicates Externalizable data 154 * written in Block Data mode. 155 * Added for PROTOCOL_VERSION_2. 156 * 157 * @see #PROTOCOL_VERSION_2 158 * @since 1.2 159 */ 160 static final byte SC_BLOCK_DATA = 0x08; 161 162 /** 163 * Bit mask for ObjectStreamClass flag. Indicates class is Serializable. 164 */ 165 static final byte SC_SERIALIZABLE = 0x02; 166 167 /** 168 * Bit mask for ObjectStreamClass flag. Indicates class is Externalizable. 169 */ 170 static final byte SC_EXTERNALIZABLE = 0x04; 171 172 /** 173 * Bit mask for ObjectStreamClass flag. Indicates class is an enum type. 174 * @since 1.5 175 */ 176 static final byte SC_ENUM = 0x10; 177 178 179 /* *******************************************************************/ 180 /* Security permissions */ 181 182 /** 183 * Enable substitution of one object for another during 184 * serialization/deserialization. 185 * 186 * @see java.io.ObjectOutputStream#enableReplaceObject(boolean) 187 * @see java.io.ObjectInputStream#enableResolveObject(boolean) 188 * @since 1.2 189 */ 190 static final SerializablePermission SUBSTITUTION_PERMISSION = 191 new SerializablePermission("enableSubstitution"); 192 193 /** 194 * Enable overriding of readObject and writeObject. 195 * 196 * @see java.io.ObjectOutputStream#writeObjectOverride(Object) 197 * @see java.io.ObjectInputStream#readObjectOverride() 198 * @since 1.2 199 */ 200 static final SerializablePermission SUBCLASS_IMPLEMENTATION_PERMISSION = 201 new SerializablePermission("enableSubclassImplementation"); 202 203 /** 204 * Enable setting the process-wide serial filter. 205 * 206 * @see java.io.ObjectInputFilter.Config#setSerialFilter(ObjectInputFilter) 207 * @since 9 208 */ 209 static final SerializablePermission SERIAL_FILTER_PERMISSION = 210 new SerializablePermission("serialFilter"); 211 212 /** 213 * A Stream Protocol Version. <p> 214 * 215 * All externalizable data is written in JDK 1.1 external data 216 * format after calling this method. This version is needed to write 217 * streams containing Externalizable data that can be read by 218 * pre-JDK 1.1.6 JVMs. 219 * 220 * @see java.io.ObjectOutputStream#useProtocolVersion(int) 221 * @since 1.2 222 */ 223 public static final int PROTOCOL_VERSION_1 = 1; 224 225 226 /** 227 * A Stream Protocol Version. <p> 228 * 229 * This protocol is written by JVM 1.2. 230 * 231 * Externalizable data is written in block data mode and is 232 * terminated with TC_ENDBLOCKDATA. Externalizable class descriptor 233 * flags has SC_BLOCK_DATA enabled. JVM 1.1.6 and greater can 234 * read this format change. 235 * 236 * Enables writing a nonSerializable class descriptor into the 237 * stream. The serialVersionUID of a nonSerializable class is 238 * set to 0L. 239 * 240 * @see java.io.ObjectOutputStream#useProtocolVersion(int) 241 * @see #SC_BLOCK_DATA 242 * @since 1.2 243 */ 244 public static final int PROTOCOL_VERSION_2 = 2; 245} 246