Spread the love

Abstract Interface DataInput in Java

Spread the love

Abstract Interface DataInput in Java

DataInput interface defines the methods required for streams that can read Java primitive data types in a machine-independent binary format. It is implemented by DataInputStream and RandomAccessFile.

The DataInput interface defines methods for reading primitive data types and lines of text from an input stream in a machine-independent manner.

All multibyte quantities are assumed to be in a format that stores the most significant byte as the first byte and the least significant byte as the last byte.

The abstract interface structure of DataInput in Java is given as

public abstract interface java.io.DataInput{
// Public Instance Methods
public abstract boolean readBoolean() throws IOException;
public abstract byte readByte() throws IOException;
public abstract char readChar() throws IOException;
public abstract double readDouble() throws IOException;
public abstract float readFloat() throws IOException;
public abstract void readFully(byte[] b) throws IOException;
public abstract void readFully(byte[] b, int off, int len) throws IOException;
public abstract int readInt() throws IOException;
public abstract String readLine() throws IOException;
public abstract long readLong() throws IOException;
public abstract short readShort() throws IOException;
public abstract String readUTF() throws IOException;
public abstract int readUnsignedByte() throws IOException;
public abstract int readUnsignedShort() throws IOException;
public abstract int skipBytes(int n) throws IOException;
}

The details of the class structure are given as follows:

public abstract boolean readBoolean();

public abstract boolean readBoolean() method reads a byte as a boolean value. A byte that contains a zero is read as false; that which contains a nonzero is read as true.

READ  Abstract Interface CharacterIterator in java

This method returns the boolean value read from the stream.

public abstract byte readByte();

public abstract byte readByte() method reads a signed 8-bit byte.

READ  Hashmap Concept Simplified in Java

This method returns the byte value read from the stream.

public abstract char readChar();

public abstract char readChar() method reads a 16-bit char.

This method returns the char value read from the stream.

public abstract double readDouble();

public abstract double readDouble() method reads a 64-bit double quantity.

This method returns the double value read from the stream.

public abstract float readFloat();

public abstract float readFloat() method reads a 32-bit float quantity.

This method returns the float value read from the stream.

public abstract void readFully(byte[] b);

public abstract void readFully(byte[] b) method reads bytes into the given array b until the array is full.

Parameter
b – The array to fill.

public abstract void readFully(byte[] b, int off, int len);

public abstract void readFully(byte[] b, int off, int len) method reads len bytes into the given array, starting at offset off.

Parameter
b – The array to fill.
off – An offset into the array.
len – The number of bytes to read.

public abstract int readInt();

public abstract int readInt() method reads a 32-bit int quantity.

This method returns the int value read from the stream.

public abstract String readLine();

public abstract String readLine() method reads a String from the current position through the next line terminator. Implementations of this method should take care to look for any line terminator: “\n”, “\r”, or “\r\n”.

READ  Class ByteArrayInputStream in Java

This method returns a String that contains the line read from the stream.

public abstract long readLong();

public abstract long readLong() method reads a 64-bit long quantity.

This method returns the long value read from the stream.

public abstract short readShort();

public abstract short readShort() method reads a 16-bit short quantity.

READ  Abstract Interface CharacterIterator in java

This method returns the short value read from the stream.

public abstract int readUnsignedByte();

public abstract int readUnsignedByte() method reads an 8-bit byte as an unsigned quantity.

This method returns The unsigned byte value read from the stream.

public abstract int readUnsignedShort();

public abstract int readUnsignedShort() method reads a 16-bit short as an unsigned quantity.

This method returns the unsigned short value read from the stream.

public abstract String readUTF();

public abstract String readUTF() method This method reads a UTF-8 format String.

This method returns the String read from the stream.

public abstract int skipBytes(int n);

public abstract int skipBytes(int n) method skips over n bytes.

This method returns the actual number of skipped bytes.
Parameter
n – The number of bytes to skip.




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