Sunday, 10 March 2013

writeChars(String)



writeChars(String)

Declaration:
public void writeChars(java.lang.String s)
throws IOException
Description:
Writes every character in the string s, to the output stream, in order, two bytes per character. If s is null,
a NullPointerException is thrown. If s.length is 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].
For each character, two bytes are actually written, high-order byte first, in exactly the manner of the
writeChar method.
Parameters:
s - the string value to be written.
Throws:
IOException - if an I/O error occurs.
writeUTF(String)
Declaration:
public void writeUTF(java.lang.String s)
throws IOException
Description:
Writes two bytes of length information to the output stream, followed by the Java modified UTF
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.
If a character c is in the range \u0001 through \u007f, it is represented by one byte:
(byte)c
If a character c is \u0000 or is in the range \u0080 through \u07ff, then it is
represented by two bytes, to be written in the order shown:
(byte)(0xc0 | (0x1f & (c >> 6)))
(byte)(0x80 | (0x3f & c))
If a character c is in the range \u0800 through 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))
First, the total number of bytes needed to represent all the characters of s is calculated. If this number is
larger than 65535, then a UTFDataFormatError is thrown. Otherwise, this length is written to the
output stream in exactly the manner of the writeShort method; after this, the one-, two-, or three-byte
representation of each character in the string s is written.
The bytes written by this method may be read by the readUTF method of interface DataInput, which
will then return a String equal to s.
Parameters:
s - the string value to be written.
Throws:
IOException - if an I/O error occurs.

No comments:

Post a Comment