Share via


ObjectOutputStream.WriteUnshared(Object) Method

Definition

Writes an "unshared" object to the ObjectOutputStream.

[Android.Runtime.Register("writeUnshared", "(Ljava/lang/Object;)V", "GetWriteUnshared_Ljava_lang_Object_Handler")]
public virtual void WriteUnshared (Java.Lang.Object? obj);
[<Android.Runtime.Register("writeUnshared", "(Ljava/lang/Object;)V", "GetWriteUnshared_Ljava_lang_Object_Handler")>]
abstract member WriteUnshared : Java.Lang.Object -> unit
override this.WriteUnshared : Java.Lang.Object -> unit

Parameters

obj
Object

object to write to stream

Attributes

Exceptions

if an error occurs while writing to the target stream.

Remarks

Writes an "unshared" object to the ObjectOutputStream. This method is identical to writeObject, except that it always writes the given object as a new, unique object in the stream (as opposed to a back-reference pointing to a previously serialized instance). Specifically: <ul> <li>An object written via writeUnshared is always serialized in the same manner as a newly appearing object (an object that has not been written to the stream yet), regardless of whether or not the object has been written previously.

<li>If writeObject is used to write an object that has been previously written with writeUnshared, the previous writeUnshared operation is treated as if it were a write of a separate object. In other words, ObjectOutputStream will never generate back-references to object data written by calls to writeUnshared. </ul> While writing an object via writeUnshared does not in itself guarantee a unique reference to the object when it is deserialized, it allows a single object to be defined multiple times in a stream, so that multiple calls to readUnshared by the receiver will not conflict. Note that the rules described above only apply to the base-level object written with writeUnshared, and not to any transitively referenced sub-objects in the object graph to be serialized.

ObjectOutputStream subclasses which override this method can only be constructed in security contexts possessing the "enableSubclassImplementation" SerializablePermission; any attempt to instantiate such a subclass without this permission will cause a SecurityException to be thrown.

Added in 1.4.

Java documentation for java.io.ObjectOutputStream.writeUnshared(java.lang.Object).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

See also