The output streams of type java.io.PrintStream are not modified as the default option in the BS2000 port, but are mentioned here because they can cause special difficulties.
Methods of the java.io.PrintStream class
In accordance with the Java API specification some methods in the class java.io.PrintStream convert their outputs into the default code set (value of the system property file.encoding), whereas others do not. With this class it is therefore extremely easy to write programs which apparently function in an ASCII world but do not deliver the expected results in BS2000. The following simple example will illustrate this point:
Example
... PrintStream out = new PrintStream(new FileOutputStream("test")); ... out.print("This is a text."); out.write('\n'); ...
In an ASCII-based system the content of file test will then be a line ending with newline and containing the above text. In BS2000 the file would contain an EBCDIC-encoded version of the text, however the line would not end with newline but would contain a “smudge” as the last character.
This example shows clearly how important it is for the input/output of text in a new implementation of Java code to use the new read and write classes (i.e. InputStreamReader and OutputStreamWriter).
In BS2000 an additional option is available which changes the behavior of PrintStream so that no conversion is performed by any method any more. This can be achieved if Java is called via -Djava.localized.print=False. With this setting, the class PrintStream no longer behaves in accordance with the specification; however, this can actually be useful for existing applications.
For the sake of completeness, mention should be made of the fact that the use of “Localized Streams” as the basis for PrintStreams or the localization of a PrintStream does not result in multiple conversions. However, for PrintStreams handled in this way it is of course then the case that all methods convert.
Interaction between the readLine() and println() methods
It is often assumed that data written with println() to a PrintStream could be reread by the readLine() methods of some InputStream classes. In BS2000, however, this assumption may result in an error. This is due to the fact that although data will be converted to the native code set (OSD_EBCDIC_DF04_1 in BS2000) during output to a PrintStream, this is not carried out by any of the readLine() methods of the InputStream classes during a read operation. Instead, you should use the new Reader and Writer classes or use “Localized Streams” for input.