
588
|
Chapter 9: Information Processing Techniques
Java Text Stream Handling
is section provides example code for handling text streams in Java through the under-
lying use of the standard (but private) ByteToCharConverter and CharToByteConverter
classes found in the java.io package. ese algorithms fall into two basic types:
Non-Unicode to Unicode (considered a text “import”)•
Unicode to non-Unicode (considered a text “export”)•
None of these text stream conversion types require any special handling, such as the prop-
er handling of designator sequences, escape sequences, or shiing characters as used in
ISO-2022 encoding.
Before Java, keeping track of the current n-byte-per-character mode and current charac-
ter set was very important when dealing with ISO-2022–encoded data. Java performs the
following tasks for you:
Recognize and remove redundant escape sequences•
Ensure that lines terminate in one-byte mode•
Ensure that the le terminates in one-byte mode•
is list may not seem very important to you now, but as you begin to encounter ISO-
2022–encoded les with redundant or missing escape sequences, you will soon appreciate
it.
Non-Unicode to Unicode conversion—import
Converting a text stream from a non-Unicode encoding to Unicode is greatly simplied
in Java through its text stream classes. Non-Unicode encodings are treated as raw data by
Java. e following three lines of Java ...