CHAPTER 22: The Package java.io |
![]() Previous |
![]() Java Language |
![]() Index |
![]() Next |
A data output stream provides facilities for converting data of diverse types into character sequence of specific formats that are then sent to some output stream.
public class DataOutputStream extends FilterOutputStream implements DataOutput { protected int written; public DataOutputStream(OutputStream out); public void write(int b) throws IOException; public void write(byte[] b, int off, int len) throws IOException, NullPointerException, IndexOutOfBoundsException; public void flush() throws IOException; public final void writeBoolean(boolean v) throws IOException; public final void writeByte(int v) throws IOException; public final void writeShort(int v) throws IOException; public final void writeChar(int v) throws IOException; public final void writeInt(int v) throws IOException; public final void writeLong(long v) throws IOException; public final void writeFloat(float v) throws IOException; public final void writeDouble(double v) throws IOException; public final void writeBytes(String s) throws IOException, NullPointerException; public final void writeChars(String s) throws IOException, NullPointerException; public final void writeUTF(String str) throws IOException, NullPointerException; public final int size(); }
protected int written;
This field contains the number of bytes written to the stream so far.
public DataOutputStream(OutputStream out)
This constructor initializes a newly created DataOutputStream by saving its argument, the output stream out, for later use. The counter written is set to zero.
public void write(int b) throws IOException
The byte for this operation (the low eight bits of the argument b) is written to the contained output stream. If no exception is thrown, the counter written is incremented by 1.
Implements the write method of OutputStream (S22.15.1).
public void write(byte[] b, int off, int len) throws IOException, NullPointerException, IndexOutOfBoundsException
Bytes for this operation are written to the contained output stream. If no exception is thrown, the counter written is incremented by len.
Overrides the write method of OutputStream (S22.15.3).
public void flush() throws IOException
The contained output stream is flushed.
Overrides the flush method of OutputStream (S22.15.4).
public final void writeBoolean(boolean v) throws IOException
See the general contract of the writeBoolean method of DataOutput (S22.2.4).
The byte for this operation is written to the contained output stream. If no exception is thrown, the counter written is incremented by 1.
public final void writeByte(int v) throws IOException
See the general contract of the writeByte method of DataOutput (S22.2.5).
The byte for this operation is written to the contained output stream. If no exception is thrown, the counter written is incremented by 1.
public final void writeShort(int v) throws IOException
See the general contract of the writeShort method of DataOutput (S22.2.6).
Bytes for this operation are written to the contained output stream. If no exception is thrown, the counter written is incremented by 2.
public final void writeChar(int v) throws IOException
See the general contract of the writeChar method of DataOutput (S22.2.7).
Bytes for this operation are written to the contained output stream. If no exception is thrown, the counter written is incremented by 2.
public final void writeInt(int v) throws IOException
See the general contract of the writeInt method of DataOutput (S22.2.8).
Bytes for this operation are written to the contained output stream. If no exception is thrown, the counter written is incremented by 4.
public final void writeLong(long v) throws IOException
See the general contract of the writeLong method of DataOutput (S22.2.9).
Bytes for this operation are written to the contained output stream. If no exception is thrown, the counter written is incremented by 8.
public final void writeFloat(float v) throws IOException
See the general contract of the writeFloat method of DataOutput (S22.2.10).
Bytes for this operation are written to the contained output stream. If no exception is thrown, the counter written is incremented by 4.
public final void writeDouble(double v) throws IOException
See the general contract of the writeDouble method of DataOutput (S22.2.11).
Bytes for this operation are written to the contained output stream. If no exception is thrown, the counter written is incremented by 8.
public final void writeBytes(String s) throws IOException, NullPointerException, IndexOutOfBoundsException
See the general contract of the writeBytes method of DataOutput (S22.2.12).
Bytes for this operation are written to the contained output stream. If no exception is thrown, the counter written is incremented by the length of s.
public final void writeChars(String s) throws IOException, NullPointerException, IndexOutOfBoundsException
See the general contract of the writeChars method of DataOutput (S22.2.13).
Bytes for this operation are written to the contained output stream. If no exception is thrown, the counter written is incremented by twice the length of s.
public final void writeUTF(String str) throws IOException, NullPointerException, IndexOutOfBoundsException
See the general contract of the writeUTF method of DataOutput (S22.2.14).
Bytes for this operation are written to the contained output stream. If no exception is thrown, the counter written is incremented by the total number of bytes written to the output stream. This will be at least two plus the length of s, and at most two plus thrice the length of s.
public final int size()
The size method returns the current value of the counter written, the number of bytes written to the stream so far.