java.io.DataOutput
The DataOutput interface provides for converting data from any of the Java primitive types to a series of bytes and writing these bytes to a binary stream. There is also a facility for converting a String into a modified UTF-8 format and writing the resulting series of bytes. For all the methods in this interface that write bytes, it is generally true that if a byte cannot be written for any reason, an IOException is thrown.
Sub Interfaces:
ImageOutputStream, ObjectOutput
Implementing Classes:
DataOutputStream, FileCacheImageOutputStream, FileImageOutputStream, ImageOutputStreamImpl, MemoryCacheImageOutputStream, ObjectOutputStream, RandomAccessFile
Declaration
public interface DataOutput {void write(int b) throws IOException;void write(byte b[]) throws IOException;void write(byte b[], int off, int len)throws IOException;void writeBoolean(boolean v) throws IOException;void writeByte(int v) throws IOException;void writeShort(int v) throws IOException;void writeChar(int v) throws IOException;void writeInt(int v) throws IOException;void writeLong(long v) throws IOException;void writeFloat(float v) throws IOException;void writeDouble(double v) throws IOException;void writeBytes(String s) throws IOException;void writeChars(String s) throws IOException;void writeUTF(String s) throws IOException;}
Methods of DataOutput
1. write(int b)
void java.io.DataOutput.write(int b) throws IOException
Writes to the output stream the eight low-order bits of the argument b. The 24 high-order bits of bare ignored. Parameters:b the byte to be written.
Throws:
IOException - if an I/O error occurs.
2. write(byte[] b)
void java.io.DataOutput.write(byte[] b) throws IOException
Writes to the output stream all the bytes in array b. If b is null, a NullPointerException is thrown. If b.length is zero, then no bytes are written. Otherwise, the byte b[0] is written first, then b[1], and so on; the last byte written is b[b.length-1].
Parameters:
b: the data.
Throws:
IOException - if an I/O error occurs.
3. write(byte[] b, int off, int len)
void java.io.DataOutput.write(byte[] b, int off, int len) throws IOException
Writes len bytes from array b, in order, to the output stream. If b is null, a NullPointerExceptionis has thrown. If off is negative, or len is negative, or off+len is greater than the length of the array b, then an IndexOutOfBoundsExceptionis has been thrown. If len is zero, then no bytes are written. Otherwise, the byte b[off] is written first, then b[off+1], and so on; the last byte written is b[off+len-1].
Parameters:
b: the data.
off: the start offset in the data.
len: the number of bytes to write.
Throws:
IOException - if an I/O error occurs.
4. writeBoolean(boolean v)
void java.io.DataOutput.writeBoolean(boolean v) throws IOException
Writes a boolean value to this output stream. If the argument v is true, the value (byte) 1 is written; if v is false, the value (byte)0 is written.
Parameters:
v: the boolean to be written.
Throws:
IOException - if an I/O error occurs.
5. writeByte(int v)
writeByte(int v)void java.io.DataOutput.writeByte(int v) throws IOException
Writes to the output stream the eight low-order bits of the argument v.The 24 high-order bits of v are ignored.
Parameters:
v: the byte value to be written.
Throws:
IOException - if an I/O error occurs.
6. writeShort(int v)
void java.io.DataOutput.writeShort(int v) throws IOException
Writes two bytes to the output stream to represent the value of the argument.
The byte values to be written, in the order shown, are: (byte)(0xff & (v >> 8)) (byte)(0xff & v)
Parameters:
v: the short value to be written.
Throws:
IOException - if an I/O error occurs.
7. writeChar(int v)
void java.io.DataOutput.writeChar(int v) throws IOException
Writes a char value, which is comprised of two bytes, to the output stream. The byte values to be written, in the order shown, are: (byte)(0xff & (v >> 8)) (byte)(0xff & v).
Parameters:
v: the char value to be written.
Throws:
IOException - if an I/O error occurs.
8. writeInt(int v)
void java.io.DataOutput.writeInt(int v) throws IOException
Writes an int value, which is comprised of four bytes, to the output stream. The byte values to be written, in the order shown, are: (byte)(0xff & (v >> 24)) (byte)(0xff & (v >> 16)) (byte)(0xff & (v >> 8)) (byte)(0xff & v).
Parameters:
v: the int value to be written.
Throws:
IOException - if an I/O error occurs.
9. writeLong(long v)
void java.io.DataOutput.writeLong(long v) throws IOException
Writes a long value, which is comprised of eight bytes, to the output stream.
The byte values to be written, in the order shown, are: (byte)(0xff & (v >> 56)) (byte)(0xff & (v >> 48)) (byte)(0xff & (v >> 40)) (byte)(0xff & (v >> 32)) (byte)(0xff & (v >> 24)) (byte)(0xff & (v >> 16)) (byte)(0xff & (v >> 8)) (byte)(0xff & v).
Parameters:
v: the long value to be written.
Throws:
IOException - if an I/O error occurs.
10. writeFloat(float v)
void java.io.DataOutput.writeFloat(float v) throws IOException
Writes a float value, which is comprised of four bytes, to the output stream.
Parameters:
v: the float value to be written.
Throws:
IOException - if an I/O error occurs.
11. writeDouble(double v)
void java.io.DataOutput.writeDouble(double v) throws IOException
Writes a double value, which is comprised of eight bytes, to the output stream.
Parameters:
v: the double value to be written.
Throws:
IOException - if an I/O error occurs.
12. writeBytes(String s)
void java.io.DataOutput.writeBytes(String s) throws IOException
Writes a string to the output stream. For every character in the string s, taken in order, one byte is written to the output stream. If s is null, a NullPointerExceptionis has thrown. If s.length is zero, then no bytes are written. Otherwise, the character s[0] is written first, then s[1], and so on; the last character written is s[s.length-1].
Parameters:
s: the string of bytes to be written.
Throws:
IOException - if an I/O error occurs.
13. writeChars(String s)
void java.io.DataOutput.writeChars(String s) throws IOException
Writes every character in the string s, to the output stream, in order, of two bytes per character. If s is null, a NullPointerExceptionis has thrown. If s.lengthis zero, then no characters are written. Otherwise, the character s[0] is written first, then s[1], and so on; the last character written is s[s.length-1].
Parameters:
s: the string value to be written.
Throws:
IOException - if an I/O error occurs.
14. writeUTF(String s)
void java.io.DataOutput.writeUTF(String s) throws IOException
Writes two bytes of length information to the output stream, followed by the modified UTF-8 representation of every character in the string s. If s is null, a NullPointerException is thrown. Each character in the string s is converted to a group of one, two, or three bytes, depending on the value of the character.
Note:
1. If a character c is in the range \u0001 through \u007f, it is represented by one byte: (byte) c.
2. If a character c is \u0000or is in the range \u0080through \u07ff, then it is represented by two bytes, to be written in the order shown: (byte)(0xc0 | (0x1f & (c >> 6))) (byte)(0x80 | (0x3f & c)).
3. If a character c is in the range \u0800through uffff, then it is represented by three bytes, to be written in the order shown: (byte)(0xe0 | (0x0f & (c >> 12))) (byte)(0x80 | (0x3f & (c >> 6))) (byte)(0x80 | (0x3f & c)).
Parameters:
s: the string value to be written.
Throws:
IOException - if an I/O error occurs.
Externalizable interface in Java
FilenameFilter interface in Java
Externalizable interface in Java
Serializable interface in Java
ObjectInputValidation interface in Java
ObjectInputFilter interface in Java
No comments:
Post a Comment