The class java.lang.System provides three standard streams in, out, and err. By analogy to the solution in OS/390, these standard streams are “Localized Streams” in JENV. This means that normal text input and output is possible in BS2000 via these streams.
This can be set selectively for each of the three streams if the following system properties are defined when the program is started:
System.in -Djava.localized.in=... System.out -Djava.localized.out=... System.err -Djava.localized.err=...
These streams are not modified if the extension for “Localized Streams” is deactivated (-Djava.localized.streams=False). Setting or amending these system properties later on has no effect on the currently defined standard streams either.
The following values can be specified:
Default
The original streams (which are set when the program is started) are localized. This is the default value.
Full
Both the original streams and also the standard streams which are set later on using setIn() etc. are localized.
None
The standard streams are not modified.
If an application uses the methods setIn(), setOut(), or setErr() in order to assign its own streams, there are two options for guaranteeing correct operation: either you must ensure that all standard streams are “Localized Streams” (i.e. text streams), or see to it that a clear distinction is made between text and binary input/output when using standard streams. The following example shows both options.
The second option is the preferred solution, and should be applied as a matter of principle when working with standard streams. However, the first option may be necessary if you are working with existing Java classes which have not been implemented in a portable fashion.
Example
The following code (similar examples of which can be found in the JavaSoft demo programs) would lead to a binary input/output via these streams, with the result that the output files would be unreadable or the input might be misinterpreted if text input/output was really intended.
... public static String read_write() { StringBuffer buf = new StringBuffer(80); int c; try { while ((c = System.in.read()) != -1) { char ch = (char) c; System.out.write(c); if (ch == '\n') break; buf.append(ch); } } catch (IOException e) { System.err.println(e); } return (buf.toString()); } ... System.setIn(new FileInputStream("myinputfile")); System.setOut(new PrintStream(new FileOutputStream("myoutputfile"))); ... line = read_write(); ...
The following program fragment shows the first option, where all standard streams are “Localized Streams” (i.e. text streams). This solution would have to be implemented by the calling program.
... System.setIn(com.fujitsu.ts.java.io.LocalizedInputStream. localize (new FileInputStream("myinputfile"))); System.setOut(com.fujitsu.ts.java.io.LocalizedPrintStream. localize (new FileOutputStream("myoutputfile"))); ... line = read_write(); ...
The code fragment for the second solution could look like this and would have to be implemented by the user of the standard streams. It involves making a clear distinction between text and binary input/output when using standard streams.
... public static String read_write() { StringBuffer buf = new StringBuffer(80); int c; InputStreamReader in = new InputStreamReader(System.in); OutputStreamWriter out = new OutputStreamWriter(System.out); try { while ((c = in.read()) != -1) { char ch = (char) c; out.write(c); if (ch == '\n') break; buf.append(ch); } } catch (IOException e) { System.err.println(e); } return (buf.toString()); } ...