Java Reference
In-Depth Information
and you must supply a
charset
argument to tell the writer how to convert to the tar-
get byte-oriented text encoding. When you use an
InputStreamReader
, the target
encoding is always Unicode. You must supply the source text encoding as an argument
so that the reader understands how to convert the text.
Note
The Java platform's
String
represents characters in the UTF-16 encoding of
Unicode. Unicode can have several encodings, including UTF-16, UTF-8, and even
UTF-32. Converting to Unicode in this discussion always means converting to UTF-16.
Converting to a byte-oriented encoding usually means to a legacy non-Unicode
char-
set
encoding. However, a common byte-oriented encoding is UTF-8, and it is entirely
reasonable to convert Java's “native” UTF-16 Unicode characters to or from UTF-8 us-
ing the
InputStreamReader
or
OutputStreamWriter
class.
Yet another way to perform encoding conversions is to use the
CharsetEn-
coder
and
CharsetDecoder
classes. A
CharsetEncoder
will encode your
Unicode
CharBuffer
instances to
ByteBuffer
instances. A
CharsetDecoder
will decode
ByteBuffer
instances into
CharBuffer
instances. In either case, you
must provide a
charset
argument.
A
charset
represents a character set encoding defined in the IANA Charset Re-
gistry. When creating a
charset
instance, you should use the canonical or alias
Remember that your Java implementation will not necessarily support all the IANA
charset
names. However, all implementations are required to support at least those
shown in Recipe 12-7 of this chapter.
12-9. Setting the Search Order of Locale-
Sensitive Services
Problem
You want to designate a specified search order for locale-sensitive services within the
Java runtime environment.