Writes two bytes of length information to the output stream in
network byte order, 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.
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
UTFDataFormatException
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 current byte order setting is ignored.
If the bit offset within the stream is non-zero, the
remainder of the current byte is padded with 0s
and written out first. The bit offset will be 0 after the
write.
Note: This method should not be used in
the implementation of image formats that use standard UTF-8,
because the modified UTF-8 used here is incompatible with
standard UTF-8.
Parameters:
- s - a String
containing the value to be
written.
Throws:
- NullPointerException - if s
is
null
.
- UTFDataFormatException - if the modified UTF-8
representation of s
requires more than 65536 bytes.
- IOException - if an I/O error occurs.