Spread the love

Abstract interface ObjectInput in Java

Spread the love

Abstract interface ObjectInput in Java

ObjectInput interface extends the DataInput interface and adds methods for serialization and deserializing objects along with reading bytes and arrays of bytes.
While DataInput defines methods for reading primitive types from a stream, ObjectInput defines methods for reading objects and arrays of bytes.

The structure of the ObjectInput interface is given as

public abstract interface java.io.ObjectInput extends java.io.DataInput{
// Public Instance Methods
public abstract int available() throws IOException;
public abstract void close() throws IOException;
public abstract int read() throws IOException;
public abstract int read(byte [ ] b) throws IOException;
public abstract int read(byte [ ] b, int off, int len) throws IOException;
public abstract Object readObject() throws ClassNotFoundException,IOException;
public abstract long skip(long n) throws IOException;
}

The details of the methods are given as:

public abstract int available() throws IOException;

public abstract int available() throws IOException method returns the number of bytes that can be read from the stream without accessing a physical device, like a disk or a network.

This method returns the number of bytes that can be read without blocking.

public abstract void close() throws IOException;

public abstract void close() throws IOException method closes the stream and releases any system resources associated with it.

public abstract int read() throws IOException;

public abstract int read() throws IOException method returns the next byte of data from the stream. The method blocks until the byte are read, the end of the stream is detected, or an exception is thrown.

READ  Class ConnectException in Java

This method returns the next byte of data or -1 if the end of the stream is encountered.

public abstract int read(byte [ ] b) throws IOException;

public abstract int read(byte [ ] b) throws IOException method reads bytes from the stream to fill the given array.

READ  Class ConnectException in Java

The method blocks until some data are available.

This method returns the actual number of bytes read or -1 if the end of the stream is encountered immediately.
Parameter
b- An array of bytes to be filled from the stream.

public abstract int read(byte [ ] b, int off, int len) throws IOException;

public abstract int read(byte [ ] b, int off, int len) throws IOException method reads up to len bytes of input into the given array starting at index off.

The method blocks until some data are available.

This method returns the actual number of bytes read or -1 if the end of the stream is encountered immediately.
Parameter
b– An array of bytes to be filled from the stream.
off– An offset into the array.
len– The number of bytes to read.

public abstract Object readObject() throws ClassNotFoundException,IOException;

public abstract Object readObject() throws ClassNotFoundException, IOException method reads and returns an object instance from the stream; in other words, it deserializes an object from the stream. The class that implements this interface determines exactly how the object is to be read.

This method returns an Object that has been deserialized from the stream.

public abstract long skip(long n) throws IOException;

public abstract long skip(long n) throws IOException method skips n bytes of input.

READ  Set Concept Simplified In Java

This method returns the actual number of bytes skipped.
Parameter
n-The number of bytes to skip.
Apart from these methods ObjectInput interface also has inherited methods from DataInput. They are as follows:

  • readBoolean()
  • readChar()
  • readFloat(byte[])
  • readFully(byte[], int, int)
  • readLine()
  • readShort()
  • readUnsignedChar()
  • skipBytes(int)
  • readByte()
  • readDouble()
  • readFully(byte[])
  • readInt()
  • readLong()
  • readUnsignedByte()
  • readUTF()
READ  Class MuiticastSocket in Java




Spread the love
Animesh Chatterjeehttps://techtravelhub.com/
I am the founder and owner of the blog - TechTravelHub.com, always love to share knowledge on test automation,tools,techniques and tips.I am a passionate coder of Java and VBScript.I also publish articles on Travel ideas and great honeymoon destinations.Apart from these, I am a gear-head,love to drive across India. I have shared lots of articles here on How to travel several parts of India.Customization of cars aka car modification is my another hobby.Get in touch with me on ani01104@gamil.com

Related Articles

Learn How to Use Jacoco Java code Coverage

Introduction to Jacoco Jacoco provides a wide range of coverage(analysis of instructions,...

Comments

Recent Posts

Learn Quickly About DevOps Tools in a Fast and Efficient Manner

Introduction to DevOps tools DevOps tools are a collection of...

How to Collaborate between Development and Operations Team Fast and Effectively

Collaborate between Development and Operations Teams are the key...

Learn How to Use Jacoco Java code Coverage

Introduction to Jacoco Jacoco provides a wide range of coverage(analysis...

EDITOR PICKS


Spread the love