Writing/reading user-defined data to/from a z/OS user program

A java.io.OutputStream is used to write user-defined data to a z/OS user program. A java.io.InputStream is used to read user-defined data from a z/OS user program.

To send byte data to a z/OS user program:

IZOSUserProgramConnection zosUserProgramConnection = ...
byte[] data = ...

try {
    // get the z/OS user program's output stream
    // Note: a z/OS user program must be executing before calling this method
    OutputStream outputStream = zosUserProgramConnection.getOutputStream();

    // use any of the output stream's "write" methods to write data
    outputStream.write(data);
} catch (IOException e) {
    // an IO error occurred getting the input stream or reading its data
    ...
}

To send text data to a z/OS user program:

IZOSUserProgramConnection zosUserProgramConnection = ...
String data = ...

try {
    // get the z/OS user program's output stream
    // Note: a z/OS user program must be executing before calling this method
    OutputStream outputStream = zosUserProgramConnection.getOutputStream();

    // wrap the z/OS user program's output stream in a buffered writer
    // Note: this code assumes the z/OS user program is decoding received
    // data using UTF-8
    BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
            outputStream, "UTF-8"));

    // use any of the writer's "write" methods to write text to the z/OS user
    // program
    writer.write(data);

    // flush the writer to ensure the data gets sent to the z/OS user program
    writer.flush();
} catch (IOException e) {
    // an IO error occurred getting the input stream or reading its data
    ...
}

To read byte data from a z/OS user program:

IZOSUserProgramConnection zosUserProgramConnection = ...
byte[] buffer = ...

try {
    // get the z/OS user program's input stream
    // Note: a z/OS user program must be executing before calling this method
    InputStream inputStream = zosUserProgramConnection.getInputStream();

    // use any of the input stream's "read" methods to read data
    int numBytesRead = inputStream.read(buffer);
} catch (IOException e) {
    // an IO error occurred getting the input stream or reading its data
    ...
}

To read text data from a z/OS user program:

IZOSUserProgramConnection zosUserProgramConnection = ...

try {
    // get the z/OS user program's input stream
    // Note: a z/OS user program must be executing before calling this method
    InputStream inputStream = zosUserProgramConnection.getInputStream();

    // wrap the z/OS user program's input stream in a buffered reader
    // Note: this code assumes the z/OS user program is encoding its data
    // using UTF-8
    BufferedReader reader = new BufferedReader(new InputStreamReader(
            inputStream, "UTF-8"));

    // use the any of the reader's "read" methods to read text from the
    // z/OS user program
    String data = reader.readLine();
} catch (IOException e) {
    // an IO error occurred getting the input stream or reading its data
    ...
}
Was this page helpful? Yes No Submitting... Thank you

Comments