Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Nested Classes](https://developer.android.com/reference/java/io/ObjectInputStream#nestedclasses) \| [Inherited Constants](https://developer.android.com/reference/java/io/ObjectInputStream#inhconstants) \| [Inherited Fields](https://developer.android.com/reference/java/io/ObjectInputStream#inhfields) \| [Ctors](https://developer.android.com/reference/java/io/ObjectInputStream#pubctors) \| [Protected Ctors](https://developer.android.com/reference/java/io/ObjectInputStream#proctors) \| [Methods](https://developer.android.com/reference/java/io/ObjectInputStream#pubmethods) \| [Protected Methods](https://developer.android.com/reference/java/io/ObjectInputStream#promethods) \| [Inherited Methods](https://developer.android.com/reference/java/io/ObjectInputStream#inhmethods)

# ObjectInputStream


`
public


class
ObjectInputStream
`


`


`

`

extends https://developer.android.com/reference/java/io/InputStream


`

`


implements

https://developer.android.com/reference/java/io/ObjectInput,

https://developer.android.com/reference/java/io/ObjectStreamConstants


`

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) |||
| ↳ | [java.io.InputStream](https://developer.android.com/reference/java/io/InputStream) ||
|   | ↳ | java.io.ObjectInputStream |

<br />

*** ** * ** ***

An ObjectInputStream deserializes primitive data and objects previously
written using an ObjectOutputStream.

ObjectOutputStream and ObjectInputStream can provide an application with
persistent storage for graphs of objects when used with a FileOutputStream
and FileInputStream respectively. ObjectInputStream is used to recover
those objects previously serialized. Other uses include passing objects
between hosts using a socket stream or for marshaling and unmarshaling
arguments and parameters in a remote communication system.

ObjectInputStream ensures that the types of all objects in the graph
created from the stream match the classes present in the Java Virtual
Machine. Classes are loaded as required using the standard mechanisms.

Only objects that support the java.io.Serializable or
java.io.Externalizable interface can be read from streams.

The method `readObject` is used to read an object from the
stream. Java's safe casting should be used to get the desired type. In
Java, strings and arrays are objects and are treated as objects during
serialization. When read they need to be cast to the expected type.

Primitive data types can be read from the stream using the appropriate
method on DataInput.

The default deserialization mechanism for objects restores the contents
of each field to the value and type it had when it was written. Fields
declared as transient or static are ignored by the deserialization process.
References to other objects cause those objects to be read from the stream
as necessary. Graphs of objects are restored correctly using a reference
sharing mechanism. New objects are always allocated when deserializing,
which prevents existing objects from being overwritten.

Reading an object is analogous to running the constructors of a new
object. Memory is allocated for the object and initialized to zero (NULL).
No-arg constructors are invoked for the non-serializable classes and then
the fields of the serializable classes are restored from the stream starting
with the serializable class closest to java.lang.object and finishing with
the object's most specific class.

For example to read from a stream as written by the example in
ObjectOutputStream:


```
      FileInputStream fis = new FileInputStream("t.tmp");
      ObjectInputStream ois = new ObjectInputStream(fis);

      int i = ois.readInt();
      String today = (String) ois.readObject();
      Date date = (Date) ois.readObject();

      ois.close();
 
```

Classes control how they are serialized by implementing either the
java.io.Serializable or java.io.Externalizable interfaces.

Implementing the Serializable interface allows object serialization to
save and restore the entire state of the object and it allows classes to
evolve between the time the stream is written and the time it is read. It
automatically traverses references between objects, saving and restoring
entire graphs.

Serializable classes that require special handling during the
serialization and deserialization process should implement the following
methods:

```
 private void writeObject(java.io.ObjectOutputStream stream)
     throws IOException;
 private void readObject(java.io.ObjectInputStream stream)
     throws IOException, ClassNotFoundException;
 private void readObjectNoData()
     throws ObjectStreamException;
 
```

The readObject method is responsible for reading and restoring the state
of the object for its particular class using data written to the stream by
the corresponding writeObject method. The method does not need to concern
itself with the state belonging to its superclasses or subclasses. State is
restored by reading data from the ObjectInputStream for the individual
fields and making assignments to the appropriate fields of the object.
Reading primitive data types is supported by DataInput.

Any attempt to read object data which exceeds the boundaries of the
custom data written by the corresponding writeObject method will cause an
OptionalDataException to be thrown with an eof field value of true.
Non-object reads which exceed the end of the allotted data will reflect the
end of data in the same way that they would indicate the end of the stream:
bytewise reads will return -1 as the byte read or number of bytes read, and
primitive reads will throw EOFExceptions. If there is no corresponding
writeObject method, then the end of default serialized data marks the end of
the allotted data.

Primitive and object read calls issued from within a readExternal method
behave in the same manner--if the stream is already positioned at the end of
data written by the corresponding writeExternal method, object reads will
throw OptionalDataExceptions with eof set to true, bytewise reads will
return -1, and primitive reads will throw EOFExceptions. Note that this
behavior does not hold for streams written with the old
`ObjectStreamConstants.PROTOCOL_VERSION_1` protocol, in which the
end of data written by writeExternal methods is not demarcated, and hence
cannot be detected.

The readObjectNoData method is responsible for initializing the state of
the object for its particular class in the event that the serialization
stream does not list the given class as a superclass of the object being
deserialized. This may occur in cases where the receiving party uses a
different version of the deserialized instance's class than the sending
party, and the receiver's version extends classes that are not extended by
the sender's version. This may also occur if the serialization stream has
been tampered; hence, readObjectNoData is useful for initializing
deserialized objects properly despite a "hostile" or incomplete source
stream.

Serialization does not read or assign values to the fields of any object
that does not implement the java.io.Serializable interface. Subclasses of
Objects that are not serializable can be serializable. In this case the
non-serializable class must have a no-arg constructor to allow its fields to
be initialized. In this case it is the responsibility of the subclass to
save and restore the state of the non-serializable class. It is frequently
the case that the fields of that class are accessible (public, package, or
protected) or that there are get and set methods that can be used to restore
the state.

Any exception that occurs while deserializing an object will be caught by
the ObjectInputStream and abort the reading process.

Implementing the Externalizable interface allows the object to assume
complete control over the contents and format of the object's serialized
form. The methods of the Externalizable interface, writeExternal and
readExternal, are called to save and restore the objects state. When
implemented by a class they can write and read their own state using all of
the methods of ObjectOutput and ObjectInput. It is the responsibility of
the objects to handle any versioning that occurs.

Enum constants are deserialized differently than ordinary serializable or
externalizable objects. The serialized form of an enum constant consists
solely of its name; field values of the constant are not transmitted. To
deserialize an enum constant, ObjectInputStream reads the constant name from
the stream; the deserialized constant is then obtained by calling the static
method `Enum.valueOf(Class, String)` with the enum constant's
base type and the received constant name as arguments. Like other
serializable or externalizable objects, enum constants can function as the
targets of back references appearing subsequently in the serialization
stream. The process by which enum constants are deserialized cannot be
customized: any class-specific readObject, readObjectNoData, and readResolve
methods defined by enum types are ignored during deserialization.
Similarly, any serialPersistentFields or serialVersionUID field declarations
are also ignored--all enum types have a fixed serialVersionUID of 0L.
**See also:**

- `https://developer.android.com/reference/java/io/DataInput`
- `https://developer.android.com/reference/java/io/ObjectOutputStream`
- `https://developer.android.com/reference/java/io/Serializable`
- [Object Serialization Specification, Section 3, Object Input Classes](https://docs.oracle.com/javase/8/docs/platform/serialization/spec/input.html)

## Summary

| ### Nested classes ||
|---|---|
| ` class` | `https://developer.android.com/reference/java/io/ObjectInputStream.GetField` Provide access to the persistent fields read from the input stream. |

| ### Inherited constants |
|---|
| From interface `https://developer.android.com/reference/java/io/ObjectStreamConstants` |---|---| | `int` | `https://developer.android.com/reference/java/io/ObjectStreamConstants#PROTOCOL_VERSION_1` A Stream Protocol Version. | | `int` | `https://developer.android.com/reference/java/io/ObjectStreamConstants#PROTOCOL_VERSION_2` A Stream Protocol Version. | | `byte` | `https://developer.android.com/reference/java/io/ObjectStreamConstants#SC_BLOCK_DATA` Bit mask for ObjectStreamClass flag. | | `byte` | `https://developer.android.com/reference/java/io/ObjectStreamConstants#SC_ENUM` Bit mask for ObjectStreamClass flag. | | `byte` | `https://developer.android.com/reference/java/io/ObjectStreamConstants#SC_EXTERNALIZABLE` Bit mask for ObjectStreamClass flag. | | `byte` | `https://developer.android.com/reference/java/io/ObjectStreamConstants#SC_SERIALIZABLE` Bit mask for ObjectStreamClass flag. | | `byte` | `https://developer.android.com/reference/java/io/ObjectStreamConstants#SC_WRITE_METHOD` Bit mask for ObjectStreamClass flag. | | `short` | `https://developer.android.com/reference/java/io/ObjectStreamConstants#STREAM_MAGIC` Magic number that is written to the stream header. | | `short` | `https://developer.android.com/reference/java/io/ObjectStreamConstants#STREAM_VERSION` Version number that is written to the stream header. | | `byte` | `https://developer.android.com/reference/java/io/ObjectStreamConstants#TC_ARRAY` new Array. | | `byte` | `https://developer.android.com/reference/java/io/ObjectStreamConstants#TC_BASE` First tag value. | | `byte` | `https://developer.android.com/reference/java/io/ObjectStreamConstants#TC_BLOCKDATA` Block of optional data. | | `byte` | `https://developer.android.com/reference/java/io/ObjectStreamConstants#TC_BLOCKDATALONG` long Block data. | | `byte` | `https://developer.android.com/reference/java/io/ObjectStreamConstants#TC_CLASS` Reference to Class. | | `byte` | `https://developer.android.com/reference/java/io/ObjectStreamConstants#TC_CLASSDESC` new Class Descriptor. | | `byte` | `https://developer.android.com/reference/java/io/ObjectStreamConstants#TC_ENDBLOCKDATA` End of optional block data blocks for an object. | | `byte` | `https://developer.android.com/reference/java/io/ObjectStreamConstants#TC_ENUM` new Enum constant. | | `byte` | `https://developer.android.com/reference/java/io/ObjectStreamConstants#TC_EXCEPTION` Exception during write. | | `byte` | `https://developer.android.com/reference/java/io/ObjectStreamConstants#TC_LONGSTRING` Long string. | | `byte` | `https://developer.android.com/reference/java/io/ObjectStreamConstants#TC_MAX` Last tag value. | | `byte` | `https://developer.android.com/reference/java/io/ObjectStreamConstants#TC_NULL` Null object reference. | | `byte` | `https://developer.android.com/reference/java/io/ObjectStreamConstants#TC_OBJECT` new Object. | | `byte` | `https://developer.android.com/reference/java/io/ObjectStreamConstants#TC_PROXYCLASSDESC` new Proxy Class Descriptor. | | `byte` | `https://developer.android.com/reference/java/io/ObjectStreamConstants#TC_REFERENCE` Reference to an object already written into the stream. | | `byte` | `https://developer.android.com/reference/java/io/ObjectStreamConstants#TC_RESET` Reset stream context. | | `byte` | `https://developer.android.com/reference/java/io/ObjectStreamConstants#TC_STRING` new String. | | `int` | `https://developer.android.com/reference/java/io/ObjectStreamConstants#baseWireHandle` First wire handle to be assigned. | |

| ### Inherited fields |
|---|
| From interface `https://developer.android.com/reference/java/io/ObjectStreamConstants` |---|---| | ` public static final https://developer.android.com/reference/java/io/SerializablePermission` | `https://developer.android.com/reference/java/io/ObjectStreamConstants#SUBCLASS_IMPLEMENTATION_PERMISSION` Enable overriding of readObject and writeObject. | | ` public static final https://developer.android.com/reference/java/io/SerializablePermission` | `https://developer.android.com/reference/java/io/ObjectStreamConstants#SUBSTITUTION_PERMISSION` Enable substitution of one object for another during serialization/deserialization. | |

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/java/io/ObjectInputStream#ObjectInputStream(java.io.InputStream)(https://developer.android.com/reference/java/io/InputStream in) ` Creates an ObjectInputStream that reads from the specified InputStream. |

| ### Protected constructors ||
|---|---|
| ` https://developer.android.com/reference/java/io/ObjectInputStream#ObjectInputStream()() ` Provide a way for subclasses that are completely reimplementing ObjectInputStream to not have to allocate private data just used by this implementation of ObjectInputStream. |

| ### Public methods ||
|---|---|
| ` int` | ` https://developer.android.com/reference/java/io/ObjectInputStream#available()() ` Returns the number of bytes that can be read without blocking. |
| ` void` | ` https://developer.android.com/reference/java/io/ObjectInputStream#close()() ` Closes the input stream. |
| ` void` | ` https://developer.android.com/reference/java/io/ObjectInputStream#defaultReadObject()() ` Read the non-static and non-transient fields of the current class from this stream. |
| ` int` | ` https://developer.android.com/reference/java/io/ObjectInputStream#read()() ` Reads a byte of data. |
| ` int` | ` https://developer.android.com/reference/java/io/ObjectInputStream#read(byte[],%20int,%20int)(byte[] buf, int off, int len) ` Reads into an array of bytes. |
| ` boolean` | ` https://developer.android.com/reference/java/io/ObjectInputStream#readBoolean()() ` Reads in a boolean. |
| ` byte` | ` https://developer.android.com/reference/java/io/ObjectInputStream#readByte()() ` Reads an 8 bit byte. |
| ` char` | ` https://developer.android.com/reference/java/io/ObjectInputStream#readChar()() ` Reads a 16 bit char. |
| ` double` | ` https://developer.android.com/reference/java/io/ObjectInputStream#readDouble()() ` Reads a 64 bit double. |
| ` https://developer.android.com/reference/java/io/ObjectInputStream.GetField` | ` https://developer.android.com/reference/java/io/ObjectInputStream#readFields()() ` Reads the persistent fields from the stream and makes them available by name. |
| ` float` | ` https://developer.android.com/reference/java/io/ObjectInputStream#readFloat()() ` Reads a 32 bit float. |
| ` void` | ` https://developer.android.com/reference/java/io/ObjectInputStream#readFully(byte[])(byte[] buf) ` Reads bytes, blocking until all bytes are read. |
| ` void` | ` https://developer.android.com/reference/java/io/ObjectInputStream#readFully(byte[],%20int,%20int)(byte[] buf, int off, int len) ` Reads bytes, blocking until all bytes are read. |
| ` int` | ` https://developer.android.com/reference/java/io/ObjectInputStream#readInt()() ` Reads a 32 bit int. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/io/ObjectInputStream#readLine()() ` *This method is deprecated. This method does not properly convert bytes to characters. see DataInputStream for the details and alternatives.* |
| ` long` | ` https://developer.android.com/reference/java/io/ObjectInputStream#readLong()() ` Reads a 64 bit long. |
| ` final https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/io/ObjectInputStream#readObject()() ` Read an object from the ObjectInputStream. |
| ` short` | ` https://developer.android.com/reference/java/io/ObjectInputStream#readShort()() ` Reads a 16 bit short. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/io/ObjectInputStream#readUTF()() ` Reads a String in [modified UTF-8](https://developer.android.com/reference/java/io/DataInput#modified-utf-8) format. |
| ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/io/ObjectInputStream#readUnshared()() ` Reads an "unshared" object from the ObjectInputStream. |
| ` int` | ` https://developer.android.com/reference/java/io/ObjectInputStream#readUnsignedByte()() ` Reads an unsigned 8 bit byte. |
| ` int` | ` https://developer.android.com/reference/java/io/ObjectInputStream#readUnsignedShort()() ` Reads an unsigned 16 bit short. |
| ` void` | ` https://developer.android.com/reference/java/io/ObjectInputStream#registerValidation(java.io.ObjectInputValidation,%20int)(https://developer.android.com/reference/java/io/ObjectInputValidation obj, int prio) ` Register an object to be validated before the graph is returned. |
| ` int` | ` https://developer.android.com/reference/java/io/ObjectInputStream#skipBytes(int)(int len) ` Skips bytes. |

| ### Protected methods ||
|---|---|
| ` boolean` | ` https://developer.android.com/reference/java/io/ObjectInputStream#enableResolveObject(boolean)(boolean enable) ` Enable the stream to allow objects read from the stream to be replaced. |
| ` https://developer.android.com/reference/java/io/ObjectStreamClass` | ` https://developer.android.com/reference/java/io/ObjectInputStream#readClassDescriptor()() ` Read a class descriptor from the serialization stream. |
| ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/io/ObjectInputStream#readObjectOverride()() ` This method is called by trusted subclasses of ObjectOutputStream that constructed ObjectOutputStream using the protected no-arg constructor. |
| ` void` | ` https://developer.android.com/reference/java/io/ObjectInputStream#readStreamHeader()() ` The readStreamHeader method is provided to allow subclasses to read and verify their own stream headers. |
| ` https://developer.android.com/reference/java/lang/Class<?>` | ` https://developer.android.com/reference/java/io/ObjectInputStream#resolveClass(java.io.ObjectStreamClass)(https://developer.android.com/reference/java/io/ObjectStreamClass desc) ` Load the local class equivalent of the specified stream class description. |
| ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/io/ObjectInputStream#resolveObject(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) ` This method will allow trusted subclasses of ObjectInputStream to substitute one object for another during deserialization. |
| ` https://developer.android.com/reference/java/lang/Class<?>` | ` https://developer.android.com/reference/java/io/ObjectInputStream#resolveProxyClass(java.lang.String[])(https://developer.android.com/reference/java/lang/String interfaces) ` Returns a proxy class that implements the interfaces named in a proxy class descriptor; subclasses may implement this method to read custom data from the stream along with the descriptors for dynamic proxy classes, allowing them to use an alternate loading mechanism for the interfaces and the proxy class. |

| ### Inherited methods |
|---|---|
| From class ` https://developer.android.com/reference/java/io/InputStream ` |---|---| | ` int` | ` https://developer.android.com/reference/java/io/InputStream#available()() ` Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking, which may be 0, or 0 when end of stream is detected. | | ` void` | ` https://developer.android.com/reference/java/io/InputStream#close()() ` Closes this input stream and releases any system resources associated with the stream. | | ` void` | ` https://developer.android.com/reference/java/io/InputStream#mark(int)(int readlimit) ` Marks the current position in this input stream. | | ` boolean` | ` https://developer.android.com/reference/java/io/InputStream#markSupported()() ` Tests if this input stream supports the `mark` and `reset` methods. | | ` static https://developer.android.com/reference/java/io/InputStream` | ` https://developer.android.com/reference/java/io/InputStream#nullInputStream()() ` Returns a new `InputStream` that reads no bytes. | | ` int` | ` https://developer.android.com/reference/java/io/InputStream#read(byte[])(byte[] b) ` Reads some number of bytes from the input stream and stores them into the buffer array `b`. | | ` abstract int` | ` https://developer.android.com/reference/java/io/InputStream#read()() ` Reads the next byte of data from the input stream. | | ` int` | ` https://developer.android.com/reference/java/io/InputStream#read(byte[],%20int,%20int)(byte[] b, int off, int len) ` Reads up to `len` bytes of data from the input stream into an array of bytes. | | ` byte[]` | ` https://developer.android.com/reference/java/io/InputStream#readAllBytes()() ` Reads all remaining bytes from the input stream. | | ` int` | ` https://developer.android.com/reference/java/io/InputStream#readNBytes(byte[],%20int,%20int)(byte[] b, int off, int len) ` Reads the requested number of bytes from the input stream into the given byte array. | | ` byte[]` | ` https://developer.android.com/reference/java/io/InputStream#readNBytes(int)(int len) ` Reads up to a specified number of bytes from the input stream. | | ` void` | ` https://developer.android.com/reference/java/io/InputStream#reset()() ` Repositions this stream to the position at the time the `mark` method was last called on this input stream. | | ` long` | ` https://developer.android.com/reference/java/io/InputStream#skip(long)(long n) ` Skips over and discards `n` bytes of data from this input stream. | | ` void` | ` https://developer.android.com/reference/java/io/InputStream#skipNBytes(long)(long n) ` Skips over and discards exactly `n` bytes of data from this input stream. | | ` long` | ` https://developer.android.com/reference/java/io/InputStream#transferTo(java.io.OutputStream)(https://developer.android.com/reference/java/io/OutputStream out) ` Reads all bytes from this input stream and writes the bytes to the given output stream in the order that they are read. | ||
| From class ` https://developer.android.com/reference/java/lang/Object ` |---|---| | ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/lang/Object#clone()() ` Creates and returns a copy of this object. | | ` boolean` | ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) ` Indicates whether some other object is "equal to" this one. | | ` void` | ` https://developer.android.com/reference/java/lang/Object#finalize()() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. | | ` final https://developer.android.com/reference/java/lang/Class<?>` | ` https://developer.android.com/reference/java/lang/Object#getClass()() ` Returns the runtime class of this `Object`. | | ` int` | ` https://developer.android.com/reference/java/lang/Object#hashCode()() ` Returns a hash code value for the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notify()() ` Wakes up a single thread that is waiting on this object's monitor. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notifyAll()() ` Wakes up all threads that are waiting on this object's monitor. | | ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/lang/Object#toString()() ` Returns a string representation of the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait()() ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*. | ||
| From interface ` https://developer.android.com/reference/java/io/Closeable ` |---|---| | ` abstract void` | ` https://developer.android.com/reference/java/io/Closeable#close()() ` Closes this stream and releases any system resources associated with it. | ||
| From interface ` https://developer.android.com/reference/java/io/ObjectInput ` |---|---| | ` abstract int` | ` https://developer.android.com/reference/java/io/ObjectInput#available()() ` Returns the number of bytes that can be read without blocking. | | ` abstract void` | ` https://developer.android.com/reference/java/io/ObjectInput#close()() ` Closes the input stream. | | ` abstract int` | ` https://developer.android.com/reference/java/io/ObjectInput#read()() ` Reads a byte of data. | | ` abstract int` | ` https://developer.android.com/reference/java/io/ObjectInput#read(byte[],%20int,%20int)(byte[] b, int off, int len) ` Reads into an array of bytes. | | ` abstract int` | ` https://developer.android.com/reference/java/io/ObjectInput#read(byte[])(byte[] b) ` Reads into an array of bytes. | | ` abstract https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/io/ObjectInput#readObject()() ` Read and return an object. | | ` abstract long` | ` https://developer.android.com/reference/java/io/ObjectInput#skip(long)(long n) ` Skips n bytes of input. | ||
| From interface ` https://developer.android.com/reference/java/lang/AutoCloseable ` |---|---| | ` abstract void` | ` https://developer.android.com/reference/java/lang/AutoCloseable#close()() ` Closes this resource, relinquishing any underlying resources. | ||
| From interface ` https://developer.android.com/reference/java/io/DataInput ` |---|---| | ` abstract boolean` | ` https://developer.android.com/reference/java/io/DataInput#readBoolean()() ` Reads one input byte and returns `true` if that byte is nonzero, `false` if that byte is zero. | | ` abstract byte` | ` https://developer.android.com/reference/java/io/DataInput#readByte()() ` Reads and returns one input byte. | | ` abstract char` | ` https://developer.android.com/reference/java/io/DataInput#readChar()() ` Reads two input bytes and returns a `char` value. | | ` abstract double` | ` https://developer.android.com/reference/java/io/DataInput#readDouble()() ` Reads eight input bytes and returns a `double` value. | | ` abstract float` | ` https://developer.android.com/reference/java/io/DataInput#readFloat()() ` Reads four input bytes and returns a `float` value. | | ` abstract void` | ` https://developer.android.com/reference/java/io/DataInput#readFully(byte[])(byte[] b) ` Reads some bytes from an input stream and stores them into the buffer array `b`. | | ` abstract void` | ` https://developer.android.com/reference/java/io/DataInput#readFully(byte[],%20int,%20int)(byte[] b, int off, int len) ` Reads `len` bytes from an input stream. | | ` abstract int` | ` https://developer.android.com/reference/java/io/DataInput#readInt()() ` Reads four input bytes and returns an `int` value. | | ` abstract https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/io/DataInput#readLine()() ` Reads the next line of text from the input stream. | | ` abstract long` | ` https://developer.android.com/reference/java/io/DataInput#readLong()() ` Reads eight input bytes and returns a `long` value. | | ` abstract short` | ` https://developer.android.com/reference/java/io/DataInput#readShort()() ` Reads two input bytes and returns a `short` value. | | ` abstract https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/io/DataInput#readUTF()() ` Reads in a string that has been encoded using a [modified UTF-8](https://developer.android.com/reference/java/io/ObjectInputStream#modified-utf-8) format. | | ` abstract int` | ` https://developer.android.com/reference/java/io/DataInput#readUnsignedByte()() ` Reads one input byte, zero-extends it to type `int`, and returns the result, which is therefore in the range `0` through `255`. | | ` abstract int` | ` https://developer.android.com/reference/java/io/DataInput#readUnsignedShort()() ` Reads two input bytes and returns an `int` value in the range `0` through `65535`. | | ` abstract int` | ` https://developer.android.com/reference/java/io/DataInput#skipBytes(int)(int n) ` Makes an attempt to skip over `n` bytes of data from the input stream, discarding the skipped bytes. | ||

## Public constructors

### ObjectInputStream

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public ObjectInputStream (InputStream in)
```

Creates an ObjectInputStream that reads from the specified InputStream.
A serialization stream header is read from the stream and verified.
This constructor will block until the corresponding ObjectOutputStream
has written and flushed the header.

If a security manager is installed, this constructor will check for
the "enableSubclassImplementation" SerializablePermission when invoked
directly or indirectly by the constructor of a subclass which overrides
the ObjectInputStream.readFields or ObjectInputStream.readUnshared
methods.

<br />

| Parameters ||
|---|---|
| `in` | `InputStream`: input stream to read from <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | if an I/O error occurs while reading stream header |
| `https://developer.android.com/reference/java/io/StreamCorruptedException` | if the stream header is incorrect |
| `https://developer.android.com/reference/java/lang/NullPointerException` | if `in` is `null` |
| `https://developer.android.com/reference/java/lang/SecurityException` | if untrusted subclass illegally overrides security-sensitive methods |

**See also:**

- `https://developer.android.com/reference/java/io/ObjectInputStream#ObjectInputStream()`
- `https://developer.android.com/reference/java/io/ObjectInputStream#readFields()`
- `https://developer.android.com/reference/java/io/ObjectOutputStream#ObjectOutputStream(java.io.OutputStream)`

## Protected constructors

### ObjectInputStream

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected ObjectInputStream ()
```

Provide a way for subclasses that are completely reimplementing
ObjectInputStream to not have to allocate private data just used by this
implementation of ObjectInputStream.

If there is a security manager installed, this method first calls the
security manager's `checkPermission` method with the
`SerializablePermission("enableSubclassImplementation")`
permission to ensure it's ok to enable subclassing.

<br />

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | if an I/O error occurs while creating this stream |
| `https://developer.android.com/reference/java/lang/SecurityException` | if a security manager exists and its `checkPermission` method denies enabling subclassing. |

**See also:**

- `https://developer.android.com/reference/java/lang/SecurityManager#checkPermission(java.security.Permission)`
- `https://developer.android.com/reference/java/io/SerializablePermission`

## Public methods

### available

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int available ()
```

Returns the number of bytes that can be read without blocking.

<br />

| Returns ||
|---|---|
| `int` | the number of available bytes. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | if there are I/O errors while reading from the underlying `InputStream` |

### close

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void close ()
```

Closes the input stream. Must be called to release any resources
associated with the stream.

<br />

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | If an I/O error has occurred. |

### defaultReadObject

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void defaultReadObject ()
```

Read the non-static and non-transient fields of the current class from
this stream. This may only be called from the readObject method of the
class being deserialized. It will throw the NotActiveException if it is
called otherwise.

<br />

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | if an I/O error occurs. |
| `https://developer.android.com/reference/java/io/NotActiveException` | if the stream is not currently reading objects. |
| `https://developer.android.com/reference/java/lang/ClassNotFoundException` | if the class of a serialized object could not be found. |

### read

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int read ()
```

Reads a byte of data. This method will block if no input is available.

<br />

| Returns ||
|---|---|
| `int` | the byte read, or -1 if the end of the stream is reached. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | If an I/O error has occurred. |

### read

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int read (byte[] buf, 
                int off, 
                int len)
```

Reads into an array of bytes. This method will block until some input
is available. Consider using java.io.DataInputStream.readFully to read
exactly 'length' bytes.

<br />

| Parameters ||
|---|---|
| `buf` | `byte`: the buffer into which the data is read <br /> |
| `off` | `int`: the start offset of the data <br /> |
| `len` | `int`: the maximum number of bytes read <br /> |

| Returns ||
|---|---|
| `int` | the actual number of bytes read, -1 is returned when the end of the stream is reached. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | If an I/O error has occurred. |

**See also:**

- `https://developer.android.com/reference/java/io/DataInputStream#readFully(byte[],%20int,%20int)`

### readBoolean

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean readBoolean ()
```

Reads in a boolean.

<br />

| Returns ||
|---|---|
| `boolean` | the boolean read. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/EOFException` | If end of file is reached. |
| `https://developer.android.com/reference/java/io/IOException` | If other I/O error has occurred. |

### readByte

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public byte readByte ()
```

Reads an 8 bit byte.

<br />

| Returns ||
|---|---|
| `byte` | the 8 bit byte read. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/EOFException` | If end of file is reached. |
| `https://developer.android.com/reference/java/io/IOException` | If other I/O error has occurred. |

### readChar

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public char readChar ()
```

Reads a 16 bit char.

<br />

| Returns ||
|---|---|
| `char` | the 16 bit char read. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/EOFException` | If end of file is reached. |
| `https://developer.android.com/reference/java/io/IOException` | If other I/O error has occurred. |

### readDouble

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public double readDouble ()
```

Reads a 64 bit double.

<br />

| Returns ||
|---|---|
| `double` | the 64 bit double read. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/EOFException` | If end of file is reached. |
| `https://developer.android.com/reference/java/io/IOException` | If other I/O error has occurred. |

### readFields

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public ObjectInputStream.GetField readFields ()
```

Reads the persistent fields from the stream and makes them available by
name.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/io/ObjectInputStream.GetField` | the `GetField` object representing the persistent fields of the object being deserialized <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | if an I/O error occurs. |
| `https://developer.android.com/reference/java/io/NotActiveException` | if the stream is not currently reading objects. |
| `https://developer.android.com/reference/java/lang/ClassNotFoundException` | if the class of a serialized object could not be found. |

### readFloat

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public float readFloat ()
```

Reads a 32 bit float.

<br />

| Returns ||
|---|---|
| `float` | the 32 bit float read. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/EOFException` | If end of file is reached. |
| `https://developer.android.com/reference/java/io/IOException` | If other I/O error has occurred. |

### readFully

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void readFully (byte[] buf)
```

Reads bytes, blocking until all bytes are read.

<br />

| Parameters ||
|---|---|
| `buf` | `byte`: the buffer into which the data is read <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/EOFException` | If end of file is reached. |
| `https://developer.android.com/reference/java/io/IOException` | If other I/O error has occurred. |

### readFully

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void readFully (byte[] buf, 
                int off, 
                int len)
```

Reads bytes, blocking until all bytes are read.

<br />

| Parameters ||
|---|---|
| `buf` | `byte`: the buffer into which the data is read <br /> |
| `off` | `int`: the start offset of the data <br /> |
| `len` | `int`: the maximum number of bytes to read <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/EOFException` | If end of file is reached. |
| `https://developer.android.com/reference/java/io/IOException` | If other I/O error has occurred. |

### readInt

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int readInt ()
```

Reads a 32 bit int.

<br />

| Returns ||
|---|---|
| `int` | the 32 bit integer read. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/EOFException` | If end of file is reached. |
| `https://developer.android.com/reference/java/io/IOException` | If other I/O error has occurred. |

### readLine

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String readLine ()
```


**This method is deprecated.**   

This method does not properly convert bytes to characters.
see DataInputStream for the details and alternatives.

Reads in a line that has been terminated by a \\n, \\r, \\r\\n or EOF.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | a String copy of the line. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | if there are I/O errors while reading from the underlying `InputStream` |

### readLong

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public long readLong ()
```

Reads a 64 bit long.

<br />

| Returns ||
|---|---|
| `long` | the read 64 bit long. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/EOFException` | If end of file is reached. |
| `https://developer.android.com/reference/java/io/IOException` | If other I/O error has occurred. |

### readObject

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public final Object readObject ()
```

Read an object from the ObjectInputStream. The class of the object, the
signature of the class, and the values of the non-transient and
non-static fields of the class and all of its supertypes are read.
Default deserializing for a class can be overridden using the writeObject
and readObject methods. Objects referenced by this object are read
transitively so that a complete equivalent graph of objects is
reconstructed by readObject.

The root object is completely restored when all of its fields and the
objects it references are completely restored. At this point the object
validation callbacks are executed in order based on their registered
priorities. The callbacks are registered by objects (in the readObject
special methods) as they are individually restored.

Exceptions are thrown for problems with the InputStream and for
classes that should not be deserialized. All exceptions are fatal to
the InputStream and leave it in an indeterminate state; it is up to the
caller to ignore or recover the stream state.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/Object` | the object read from the stream <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | Any of the usual Input/Output related exceptions. |
| `https://developer.android.com/reference/java/io/InvalidClassException` | Something is wrong with a class used by serialization. |
| `https://developer.android.com/reference/java/io/OptionalDataException` | Primitive data was found in the stream instead of objects. |
| `https://developer.android.com/reference/java/io/StreamCorruptedException` | Control information in the stream is inconsistent. |
| `https://developer.android.com/reference/java/lang/ClassNotFoundException` | Class of a serialized object cannot be found. |

### readShort

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public short readShort ()
```

Reads a 16 bit short.

<br />

| Returns ||
|---|---|
| `short` | the 16 bit short read. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/EOFException` | If end of file is reached. |
| `https://developer.android.com/reference/java/io/IOException` | If other I/O error has occurred. |

### readUTF

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String readUTF ()
```

Reads a String in
[modified UTF-8](https://developer.android.com/reference/java/io/DataInput#modified-utf-8)
format.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | the String. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | if there are I/O errors while reading from the underlying `InputStream` |
| `https://developer.android.com/reference/java/io/UTFDataFormatException` | if read bytes do not represent a valid modified UTF-8 encoding of a string |

### readUnshared

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Object readUnshared ()
```

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:

- 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.
- 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.

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.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/Object` | reference to deserialized object <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | if an I/O error occurs during deserialization |
| `https://developer.android.com/reference/java/io/ObjectStreamException` | if object to deserialize has already appeared in stream |
| `https://developer.android.com/reference/java/io/OptionalDataException` | if primitive data is next in stream |
| `https://developer.android.com/reference/java/io/StreamCorruptedException` | if control information in the stream is inconsistent |
| `https://developer.android.com/reference/java/lang/ClassNotFoundException` | if class of an object to deserialize cannot be found |

### readUnsignedByte

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int readUnsignedByte ()
```

Reads an unsigned 8 bit byte.

<br />

| Returns ||
|---|---|
| `int` | the 8 bit byte read. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/EOFException` | If end of file is reached. |
| `https://developer.android.com/reference/java/io/IOException` | If other I/O error has occurred. |

### readUnsignedShort

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int readUnsignedShort ()
```

Reads an unsigned 16 bit short.

<br />

| Returns ||
|---|---|
| `int` | the 16 bit short read. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/EOFException` | If end of file is reached. |
| `https://developer.android.com/reference/java/io/IOException` | If other I/O error has occurred. |

### registerValidation

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void registerValidation (ObjectInputValidation obj, 
                int prio)
```

Register an object to be validated before the graph is returned. While
similar to resolveObject these validations are called after the entire
graph has been reconstituted. Typically, a readObject method will
register the object with the stream so that when all of the objects are
restored a final set of validations can be performed.

<br />

| Parameters ||
|---|---|
| `obj` | `ObjectInputValidation`: the object to receive the validation callback. <br /> |
| `prio` | `int`: controls the order of callbacks;zero is a good default. Use higher numbers to be called back earlier, lower numbers for later callbacks. Within a priority, callbacks are processed in no particular order. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/InvalidObjectException` | The validation object is null. |
| `https://developer.android.com/reference/java/io/NotActiveException` | The stream is not currently reading objects so it is invalid to register a callback. |

### skipBytes

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int skipBytes (int len)
```

Skips bytes.

<br />

| Parameters ||
|---|---|
| `len` | `int`: the number of bytes to be skipped <br /> |

| Returns ||
|---|---|
| `int` | the actual number of bytes skipped. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | If an I/O error has occurred. |

## Protected methods

### enableResolveObject

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected boolean enableResolveObject (boolean enable)
```

Enable the stream to allow objects read from the stream to be replaced.
When enabled, the resolveObject method is called for every object being
deserialized.

If *enable* is true, and there is a security manager installed,
this method first calls the security manager's
`checkPermission` method with the
`SerializablePermission("enableSubstitution")` permission to
ensure it's ok to enable the stream to allow objects read from the
stream to be replaced.

<br />

| Parameters ||
|---|---|
| `enable` | `boolean`: true for enabling use of `resolveObject` for every object being deserialized <br /> |

| Returns ||
|---|---|
| `boolean` | the previous setting before this method was invoked <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/SecurityException` | if a security manager exists and its `checkPermission` method denies enabling the stream to allow objects read from the stream to be replaced. |

**See also:**

- `https://developer.android.com/reference/java/lang/SecurityManager#checkPermission(java.security.Permission)`
- `https://developer.android.com/reference/java/io/SerializablePermission`

### readClassDescriptor

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected ObjectStreamClass readClassDescriptor ()
```

Read a class descriptor from the serialization stream. This method is
called when the ObjectInputStream expects a class descriptor as the next
item in the serialization stream. Subclasses of ObjectInputStream may
override this method to read in class descriptors that have been written
in non-standard formats (by subclasses of ObjectOutputStream which have
overridden the `writeClassDescriptor` method). By default,
this method reads class descriptors according to the format defined in
the Object Serialization specification.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/io/ObjectStreamClass` | the class descriptor read <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | If an I/O error has occurred. |
| `https://developer.android.com/reference/java/lang/ClassNotFoundException` | If the Class of a serialized object used in the class descriptor representation cannot be found |

**See also:**

- `https://developer.android.com/reference/java/io/ObjectOutputStream#writeClassDescriptor(java.io.ObjectStreamClass)`

### readObjectOverride

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected Object readObjectOverride ()
```

This method is called by trusted subclasses of ObjectOutputStream that
constructed ObjectOutputStream using the protected no-arg constructor.
The subclass is expected to provide an override method with the modifier
"final".

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/Object` | the Object read from the stream. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | if I/O errors occurred while reading from the underlying stream |
| `https://developer.android.com/reference/java/io/OptionalDataException` | Primitive data was found in the stream instead of objects. |
| `https://developer.android.com/reference/java/lang/ClassNotFoundException` | Class definition of a serialized object cannot be found. |

**See also:**

- `https://developer.android.com/reference/java/io/ObjectInputStream#ObjectInputStream()`
- `https://developer.android.com/reference/java/io/ObjectInputStream#readObject()`

### readStreamHeader

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected void readStreamHeader ()
```

The readStreamHeader method is provided to allow subclasses to read and
verify their own stream headers. It reads and verifies the magic number
and version number.

<br />

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | if there are I/O errors while reading from the underlying `InputStream` |
| `https://developer.android.com/reference/java/io/StreamCorruptedException` | if control information in the stream is inconsistent |

### resolveClass

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected Class<?> resolveClass (ObjectStreamClass desc)
```

Load the local class equivalent of the specified stream class
description. Subclasses may implement this method to allow classes to
be fetched from an alternate source.

The corresponding method in `ObjectOutputStream` is
`annotateClass`. This method will be invoked only once for
each unique class in the stream. This method can be implemented by
subclasses to use an alternate loading mechanism but must return a
`Class` object. Once returned, if the class is not an array
class, its serialVersionUID is compared to the serialVersionUID of the
serialized class, and if there is a mismatch, the deserialization fails
and an `https://developer.android.com/reference/java/io/InvalidClassException` is thrown.

The default implementation of this method in
`ObjectInputStream` returns the result of calling

```
     Class.forName(desc.getName(), false, loader)
 
```
where `loader` is determined as follows: if there is a method on the current thread's stack whose declaring class was defined by a user-defined class loader (and was not a generated to implement reflective invocations), then `loader` is class loader corresponding to the closest such method to the currently executing frame; otherwise, `loader` is `null`. If this call results in a `ClassNotFoundException` and the name of the passed `ObjectStreamClass` instance is the Java language keyword for a primitive type or void, then the `Class` object representing that primitive type or void will be returned (e.g., an `ObjectStreamClass` with the name `"int"` will be resolved to `Integer.TYPE`). Otherwise, the `ClassNotFoundException` will be thrown to the caller of this method.

<br />

<br />

| Parameters ||
|---|---|
| `desc` | `ObjectStreamClass`: an instance of class `ObjectStreamClass` <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/Class<?>` | a `Class` object corresponding to `desc` <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | any of the usual Input/Output exceptions. |
| `https://developer.android.com/reference/java/lang/ClassNotFoundException` | if class of a serialized object cannot be found. |

### resolveObject

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected Object resolveObject (Object obj)
```

This method will allow trusted subclasses of ObjectInputStream to
substitute one object for another during deserialization. Replacing
objects is disabled until enableResolveObject is called. The
enableResolveObject method checks that the stream requesting to resolve
object can be trusted. Every reference to serializable objects is passed
to resolveObject. To insure that the private state of objects is not
unintentionally exposed only trusted streams may use resolveObject.

This method is called after an object has been read but before it is
returned from readObject. The default resolveObject method just returns
the same object.

When a subclass is replacing objects it must insure that the
substituted object is compatible with every field where the reference
will be stored. Objects whose type is not a subclass of the type of the
field or array element abort the serialization by raising an exception
and the object is not be stored.

This method is called only once when each object is first
encountered. All subsequent references to the object will be redirected
to the new object.

<br />

| Parameters ||
|---|---|
| `obj` | `Object`: object to be substituted <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/Object` | the substituted object <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | Any of the usual Input/Output exceptions. |

### resolveProxyClass

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected Class<?> resolveProxyClass (String[] interfaces)
```

Returns a proxy class that implements the interfaces named in a proxy
class descriptor; subclasses may implement this method to read custom
data from the stream along with the descriptors for dynamic proxy
classes, allowing them to use an alternate loading mechanism for the
interfaces and the proxy class.

This method is called exactly once for each unique proxy class
descriptor in the stream.

The corresponding method in `ObjectOutputStream` is
`annotateProxyClass`. For a given subclass of
`ObjectInputStream` that overrides this method, the
`annotateProxyClass` method in the corresponding subclass of
`ObjectOutputStream` must write any data or objects read by
this method.

The default implementation of this method in
`ObjectInputStream` returns the result of calling
`Proxy.getProxyClass` with the list of `Class`
objects for the interfaces that are named in the `interfaces`
parameter. The `Class` object for each interface name
`i` is the value returned by calling

```
     Class.forName(i, false, loader)
 
```
where `loader` is that of the first non-`null` class loader up the execution stack, or `null` if no non-`null` class loaders are on the stack (the same class loader choice used by the `resolveClass` method). Unless any of the resolved interfaces are non-public, this same value of `loader` is also the class loader passed to `Proxy.getProxyClass`; if non-public interfaces are present, their class loader is passed instead (if more than one non-public interface class loader is encountered, an `IllegalAccessError` is thrown). If `Proxy.getProxyClass` throws an `IllegalArgumentException`, `resolveProxyClass` will throw a `ClassNotFoundException` containing the `IllegalArgumentException`.

<br />

<br />

| Parameters ||
|---|---|
| `interfaces` | `String`: the list of interface names that were deserialized in the proxy class descriptor <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/Class<?>` | a proxy class for the specified interfaces <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | any exception thrown by the underlying `InputStream` |
| `https://developer.android.com/reference/java/lang/ClassNotFoundException` | if the proxy class or any of the named interfaces could not be found |

**See also:**

- `https://developer.android.com/reference/java/io/ObjectOutputStream#annotateProxyClass(java.lang.Class<?>)`