ObjectInputStream.ReadUnshared Method

Definition

Reads an "unshared" object from the ObjectInputStream.

[Android.Runtime.Register("readUnshared", "()Ljava/lang/Object;", "GetReadUnsharedHandler")]
public virtual Java.Lang.Object? ReadUnshared ();
[<Android.Runtime.Register("readUnshared", "()Ljava/lang/Object;", "GetReadUnsharedHandler")>]
abstract member ReadUnshared : unit -> Java.Lang.Object
override this.ReadUnshared : unit -> Java.Lang.Object

Returns

reference to deserialized object

Attributes

Exceptions

if the class of one of the objects in the object graph cannot be found.

if an error occurs while reading from the source stream.

Remarks

Reads an "unshared" object from the ObjectInputStream. This method is identical to readObject, except that it prevents subsequent calls to readObject and readUnshared from returning additional references to the deserialized instance obtained via this call. Specifically: <ul> <li>If readUnshared is called to deserialize a back-reference (the stream representation of an object which has been written previously to the stream), an ObjectStreamException will be thrown.

<li>If readUnshared returns successfully, then any subsequent attempts to deserialize back-references to the stream handle deserialized by readUnshared will cause an ObjectStreamException to be thrown. </ul> Deserializing an object via readUnshared invalidates the stream handle associated with the returned object. Note that this in itself does not always guarantee that the reference returned by readUnshared is unique; the deserialized object may define a readResolve method which returns an object visible to other parties, or readUnshared may return a Class object or enum constant obtainable elsewhere in the stream or through external means. If the deserialized object defines a readResolve method and the invocation of that method returns an array, then readUnshared returns a shallow clone of that array; this guarantees that the returned array object is unique and cannot be obtained a second time from an invocation of readObject or readUnshared on the ObjectInputStream, even if the underlying data stream has been manipulated.

ObjectInputStream 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.ObjectInputStream.readUnshared().

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