ObjectInputStream 

Introduction

The Java.io.ObjectInputStream class deserializes primitive data and objects previously written using an ObjectOutputStream. Following are the important points about BufferedInputStream −

  • It is used to recover those objects previously serialized. It 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.

Class declaration

Following is the declaration for Java.io.ObjectInputStream class −

public class ObjectInputStream
   extends InputStream
      implements ObjectInput, ObjectStreamConstants

Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.

Class constructors

Sr.No.Constructor & Description
1protected ObjectInputStream()This provide a way for subclasses that are completely reimplementing ObjectInputStream to not have to allocate private data just used by this implementation of ObjectInputStream.
2ObjectInputStream(InputStream in)This creates an ObjectInputStream that reads from the specified InputStream.

Class methods

Sr.No.Method & Description
1int available()This method returns the number of bytes that can be read without blocking.
2void close()This method closes the input stream.
3void defaultReadObject()This method reads the non-static and non-transient fields of the current class from this stream.
4protected boolean enableResolveObject(boolean enable)This method enables the stream to allow objects read from the stream to be replaced.
5int read()This method reads a byte of data.
6int read(byte[] buf, int off, int len)This method reads into an array of bytes.
7boolean readBoolean()This method reads in a boolean.
8byte readByte()This method reads an 8 bit byte.
9char readChar()This method r a 16 bit char.
10protected ObjectStreamClass readClassDescriptor()This method read a class descriptor from the serialization stream.
11double readDouble()This method reads a 64 bit double.
12ObjectInputStream.GetField readFields()This method reads the persistent fields from the stream and makes them available by name.
13float readFloat()This method reads a 32 bit float.
14void readFully(byte[] buf)This method reads bytes, blocking until all bytes are read.
15void readFully(byte[] buf, int off, int len)This method reads bytes, blocking until all bytes are read.
16int readInt()This method reads a 32 bit int.
17long readLong()This method reads a 64 bit long.
18Object readObject()This method reads an object from the ObjectInputStream.
19protected Object readObjectOverride()This method is called by trusted subclasses of ObjectOutputStream that constructed ObjectOutputStream using the protected no-arg constructor.
20short readShort()This method reads a 16 bit short.
21protected void readStreamHeader()This method is provided to allow subclasses to read and verify their own stream headers.
22Object readUnshared()This method reads an “unshared” object from the ObjectInputStream.
23int readUnsignedByte()This method reads an unsigned 8 bit byte.
24int readUnsignedShort()This method reads an unsigned 16 bit short.
25String readUTF()This method reads a String in modified UTF-8 format.
26void registerValidation(ObjectInputValidation obj, int prio)This method register an object to be validated before the graph is returned.
27protected Class<?> resolveClass(ObjectStreamClass desc)This method loads the local class equivalent of the specified stream class description.
28protected Object resolveObject(Object obj)This method will allow trusted subclasses of ObjectInputStream to substitute one object for another during deserialization.
29protected Class<?> resolveProxyClass(String[] interfaces)This method 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.
30int skipBytes(int len)This method skips bytes.

Methods inherited

This class inherits methods from the following classes −

  • Java.io.InputStream
  • Java.io.Object
  • Java.io.ObjectInput

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *