148 * block-data mode. Calls to the ObjectOutputStream methods writeObject,
149 * defaultWriteObject and writeFields initially terminate any existing
150 * block-data record.
151 *
152 * @author Mike Warres
153 * @author Roger Riggs
154 * @see java.io.DataOutput
155 * @see java.io.ObjectInputStream
156 * @see java.io.Serializable
157 * @see java.io.Externalizable
158 * @see <a href="../../../platform/serialization/spec/output.html">Object Serialization Specification, Section 2, Object Output Classes</a>
159 * @since JDK1.1
160 */
161 public class ObjectOutputStream
162 extends OutputStream implements ObjectOutput, ObjectStreamConstants
163 {
164
165 private static class Caches {
166 /** cache of subclass security audit results */
167 static final ConcurrentMap<WeakClassKey,Boolean> subclassAudits =
168 new ConcurrentHashMap<WeakClassKey,Boolean>();
169
170 /** queue for WeakReferences to audited subclasses */
171 static final ReferenceQueue<Class<?>> subclassAuditsQueue =
172 new ReferenceQueue<Class<?>>();
173 }
174
175 /** filter stream for handling block data conversion */
176 private final BlockDataOutputStream bout;
177 /** obj -> wire handle map */
178 private final HandleTable handles;
179 /** obj -> replacement obj map */
180 private final ReplaceTable subs;
181 /** stream protocol version */
182 private int protocol = PROTOCOL_VERSION_2;
183 /** recursion depth */
184 private int depth;
185
186 /** buffer for writing primitive field values */
187 private byte[] primVals;
188
189 /** if true, invoke writeObjectOverride() instead of writeObject() */
190 private final boolean enableOverride;
191 /** if true, invoke replaceObject() */
192 private boolean enableReplace;
2396 }
2397
2398 /**
2399 * Increases table capacity.
2400 */
2401 private void grow() {
2402 Object[] newReps = new Object[(reps.length << 1) + 1];
2403 System.arraycopy(reps, 0, newReps, 0, reps.length);
2404 reps = newReps;
2405 }
2406 }
2407
2408 /**
2409 * Stack to keep debug information about the state of the
2410 * serialization process, for embedding in exception messages.
2411 */
2412 private static class DebugTraceInfoStack {
2413 private final List<String> stack;
2414
2415 DebugTraceInfoStack() {
2416 stack = new ArrayList<String>();
2417 }
2418
2419 /**
2420 * Removes all of the elements from enclosed list.
2421 */
2422 void clear() {
2423 stack.clear();
2424 }
2425
2426 /**
2427 * Removes the object at the top of enclosed list.
2428 */
2429 void pop() {
2430 stack.remove(stack.size()-1);
2431 }
2432
2433 /**
2434 * Pushes a String onto the top of enclosed list.
2435 */
2436 void push(String entry) {
|
148 * block-data mode. Calls to the ObjectOutputStream methods writeObject,
149 * defaultWriteObject and writeFields initially terminate any existing
150 * block-data record.
151 *
152 * @author Mike Warres
153 * @author Roger Riggs
154 * @see java.io.DataOutput
155 * @see java.io.ObjectInputStream
156 * @see java.io.Serializable
157 * @see java.io.Externalizable
158 * @see <a href="../../../platform/serialization/spec/output.html">Object Serialization Specification, Section 2, Object Output Classes</a>
159 * @since JDK1.1
160 */
161 public class ObjectOutputStream
162 extends OutputStream implements ObjectOutput, ObjectStreamConstants
163 {
164
165 private static class Caches {
166 /** cache of subclass security audit results */
167 static final ConcurrentMap<WeakClassKey,Boolean> subclassAudits =
168 new ConcurrentHashMap<>();
169
170 /** queue for WeakReferences to audited subclasses */
171 static final ReferenceQueue<Class<?>> subclassAuditsQueue =
172 new ReferenceQueue<>();
173 }
174
175 /** filter stream for handling block data conversion */
176 private final BlockDataOutputStream bout;
177 /** obj -> wire handle map */
178 private final HandleTable handles;
179 /** obj -> replacement obj map */
180 private final ReplaceTable subs;
181 /** stream protocol version */
182 private int protocol = PROTOCOL_VERSION_2;
183 /** recursion depth */
184 private int depth;
185
186 /** buffer for writing primitive field values */
187 private byte[] primVals;
188
189 /** if true, invoke writeObjectOverride() instead of writeObject() */
190 private final boolean enableOverride;
191 /** if true, invoke replaceObject() */
192 private boolean enableReplace;
2396 }
2397
2398 /**
2399 * Increases table capacity.
2400 */
2401 private void grow() {
2402 Object[] newReps = new Object[(reps.length << 1) + 1];
2403 System.arraycopy(reps, 0, newReps, 0, reps.length);
2404 reps = newReps;
2405 }
2406 }
2407
2408 /**
2409 * Stack to keep debug information about the state of the
2410 * serialization process, for embedding in exception messages.
2411 */
2412 private static class DebugTraceInfoStack {
2413 private final List<String> stack;
2414
2415 DebugTraceInfoStack() {
2416 stack = new ArrayList<>();
2417 }
2418
2419 /**
2420 * Removes all of the elements from enclosed list.
2421 */
2422 void clear() {
2423 stack.clear();
2424 }
2425
2426 /**
2427 * Removes the object at the top of enclosed list.
2428 */
2429 void pop() {
2430 stack.remove(stack.size()-1);
2431 }
2432
2433 /**
2434 * Pushes a String onto the top of enclosed list.
2435 */
2436 void push(String entry) {
|