Abstract Interface DataOutput in Java

digitization, transformation, binary

Abstract Interface DataOutput in Java

DataOutput interface defines the methods required for streams that can write character data or Java primitive data types in a machine-independent binary format. It is implemented by DataOutputStream and RandomAccessFile.

The DataOutput interface defines methods for writing primitive data types to an output stream in a machine-independent manner. All multibyte quantities are written in a format that stores the most significant byte as the first byte and the least significant byte as the last byte.

Ads code goes here

The interface structure of DataOutput in Java is given as

public abstract interface java.io.DataOutput{
// Public Instance Methods
public abstract void write(int b) throws IOException;
public abstract void write(byte[] b) throws IOException;
public abstract void write(byte[] b, int off, int len) throws IOException;
public abstract void writeBoolean(boolean v) throws IOException;
public abstract void writeByte(int v) throws IOException;
public abstract void writeBytes(String s) throws IOException;
public abstract void writeChar(int v) throws IOException;
public abstract void writeChars(String s) throws IOException;
public abstract void writeDouble(double v) throws IOException;
public abstract void writeFloat(float v) throws IOException;
public abstract void writeInt(int v) throws IOException;
public abstract void writeLong(long v) throws IOException;
public abstract void writeShort(int v) throws IOException;
public abstract void writeUTF(String str) throws IOException;
}

The details of the class structure are given as follows:

public abstract void write(int b);

public abstract void write(int b) method writes the low-order eight bits of the given integer b.

Parameter
b – The value to write.

public abstract void write(byte[] b);

public abstract void write(byte[] b) method writes all of the 8-bit bytes in the given array.

READ  Abstract Class FilterWriter in Java

Parameter
b – The array of values to write.

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

public abstract void write(byte[] b, int off, int len) method writes len bytes from the given array, starting off elements from the beginning of the array.

Parameter
b -An array of bytes to write.
off – An offset into the byte array.
len – The number of bytes to write.

public abstract void writeBoolean(boolean v);

public abstract void writeBoolean(boolean v) method writes a byte (if v is true) that contains the value 1. If v is false, the method writes a byte that contains the value 0.

Parameter
v – The boolean value to write.

public abstract void writeByte(int v);

public abstract void writeByte(int v) method writes an 8-bit, using the low-order eight bits of the given integer v.

Parameter
v – The value to write.

public abstract void writeBytes(String s);

public abstract void writeBytes(String s) method writes the characters in the given String as a sequence of 8-bit bytes. The high-order bytes of the characters in the string are ignored.

Parameter
s – The String to write.

public abstract void writeChar(int v);

public abstract void writeChar(int v) method writes a 16-bit char, using the low-order 16 bits of the given integer v.

Parameter
v – The value to write.

public abstract void writeChars(String s);

public abstract void writeChars(String s) method writes the characters in the given String object as a sequence of 16-bit characters.

Parameter
s -The String to write.

public abstract void writeDouble(double v);

public abstract void writeDouble(double v) method writes a 64-bit double.

Parameter
v -The double value to write.

public abstract void writeFloat(float v);

public abstract void writeFloat(float v) method writes a 32-bit float.

READ  Class DatagramSocket in Java

Parameter
v -The float value to write.

public abstract void writeInt(int v);

public abstract void writeInt(int v) method writes a 32-bit int.

Parameter
v – The int value to write.

public abstract void writeLong(long v);

public abstract void writeLong(long v) method writes a 64-bit long.

Parameter
v -The long value to write.

public abstract void writeShort(int v);

public abstract void writeShort(int v) method writes a 16-bit short.

Parameter
v -The value to write.

public abstract void writeUTF(String str);

public abstract void writeUTF(String str) method writes the given String using the UTF-8 encoding.

Parameter
str – The string to write.

Share and Enjoy !

Leave a Comment

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