Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.ibm.jzos
Class DfSort

    java.lang.Object
      com.ibm.jzos.DfSort

    public class DfSort

extends java.lang.Object

This class provides a Java wrapper around the DFSORT utility.

DFSORT is useful for performing high-volume sort and merge operations. When invoked from Java, either the input can be taken from existing datasets or produced directly from Java. Likewise, the output from DFSORT can be written to a dataset or read directly back into Java. When writing from or reading into Java, java.io InputStreams and OutputStreams may be used to read and write data from the Java application to DFSORT.

For more information, see the following:

- The JZOS samples provided in package `com.ibm.jzos.sample.dfsort`
- DFSORT: Getting Started SC26-7527
- DFSORT Application Programming Guide SC26-7523
- DFSORT Website
- Smart DFSORT Tricks
- Ask Professor Sort

DFSORT DD allocations can be specified via `addAllocation(String)`

DFSORT control statements are specified via `addControlStatement(String)`.

Constructor Summary
`DfSort()`

Method Summary
`void` | `addAllocation(java.lang.String allocation)` Add an allocation request to be sent to the DFSORT invocation.
`void` | `addControlStatement(java.lang.String controlStatement)` Add a control statement to be sent to the DFSORT invocation.
`void` | `disableInputStream()` Indicate that the records to DFSORT are to be provided via the SORTIN DD and not from Java.
`void` | `disableOutputStream()` Indicate that the output records from DFSORT are to be sent to the SORTOUT DD and not to Java.
`void` | `execute()` Run the jdfsort child process, which is a z/OS Java USS binary command wrapper for invoking DFSORT.
`java.io.OutputStream` | `getChildStdinStream()` Returns a java.io.OutputStream that can be used to send records to the child DFSORT process.
`java.io.InputStream` | `getChildStdoutStream()` Returns a java.io.InputStream that can be used to read output records from the child DFSORT process.
`int` | `getReturnCode()` Wait for DFSORT to complete.
`java.util.List` | `getStderrLines()` Return a list of stderr output lines (Strings) from the spawned DfSort process.
`boolean` | `isSameAddressSpace()` Answer true if the child jdfsort process will be spawned in the same address space that is running the Java JVM.
`void` | `setInputStreamHasRdws()` Indicate that the records to be sent as input to DFSORT are variable length, and that each record will prefixed by a 4 byte (big endian) RDW.
`void` | `setInputStreamRecLen(int reclen)` Set a fixed record length for the records that will be sent as input to DFSORT.
`void` | `setOutputStreamHasRdws()` Indicate that the records sent from DFSORT to java are variable length, and that each record will prefixed by a 4 byte (big endian) RDW.
`void` | `setOutputStreamRecLen(int reclen)` Set a fixed record length for the records that will be received from DFSORT.
`void` | `setSameAddressSpace(boolean separateAddressSpace)` If false, run the DFSORT child invocation process in the same address space as the JVM.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### DfSort

    public DfSort()

Method Detail

### addAllocation

    public void addAllocation(java.lang.String allocation)

  Add an allocation request to be sent to the DFSORT invocation.

  The allocation strings are expected to be in the syntax required by BPXWDYN.

  Typically, DFSORT may have allocations for the following DDs:

  - SORTIN - Where DFSORT gets sort/merge input.
  - SORTOUT - Where DFSORT writes sort/merge output
  Example:

  `DfSort dfSort = new DfSort(); dfSort.addAllocation("alloc fi(sortin) da('HLQ.MY.DATASET') reuse shr msg(2)");`

### addControlStatement

    public void addControlStatement(java.lang.String controlStatement)

  Add a control statement to be sent to the DFSORT invocation. Example:

  `DfSort dfSort = new DfSort(); dfSort.addControlStatement("SORT FIELDS=(1,80,CH,A)");`

### setInputStreamRecLen

    public void setInputStreamRecLen(int reclen)

  Set a fixed record length for the records that will be sent as input to DFSORT. This length must match the record length expected by DFSORT as specified by the RECORD control statement.

  This method is mutually exclusive with `setInputStreamHasRdws()` and `disableInputStream()`.

  Parameters:
    `reclen` - int the input record length for fixed records
  See Also:
    `getChildStdinStream()`, `addControlStatement(String)`

### setInputStreamHasRdws

    public void setInputStreamHasRdws()

  Indicate that the records to be sent as input to DFSORT are variable length, and that each record will prefixed by a 4 byte (big endian) RDW. This RDW value must be less than or equal to the maximum record length expected by DFSORT as specified by the RECORD control statement. The RECORD control statement must indicate that DFSORT is to expect variable length records.

  This method is mutually exclusive with `setInputStreamRecLen(int)` and `disableInputStream()`.

  See Also:
    `getChildStdinStream()`, `addControlStatement(String)`

### disableInputStream

    public void disableInputStream()

  Indicate that the records to DFSORT are to be provided via the SORTIN DD and not from Java.

  This method is mutually exclusive with `setInputStreamRecLen(int)` and `setInputStreamHasRdws()`.

### setOutputStreamRecLen

    public void setOutputStreamRecLen(int reclen)

  Set a fixed record length for the records that will be received from DFSORT. This length must match the record length produced by DFSORT as specified by the RECORD control statement.

  This method is mutually exclusive with `setOutputStreamHasRdws()` and `disableOutputStream()`.

  Parameters:
    `reclen` - int the output record length for fixed records
  See Also:
    `getChildStdoutStream()`, `addControlStatement(String)`

### setOutputStreamHasRdws

    public void setOutputStreamHasRdws()

  Indicate that the records sent from DFSORT to java are variable length, and that each record will prefixed by a 4 byte (big endian) RDW. This RDW value will be less than or equal to the maximum record length as specified by the RECORD control statement. The RECORD control statement must indicate that DFSORT is to produce variable length records.

  This method is mutually exclusive with `setOutputStreamRecLen(int)` and `disableOutputStream()`.

  See Also:
    `getChildStdoutStream()`, `addControlStatement(String)`

### disableOutputStream

    public void disableOutputStream()

  Indicate that the output records from DFSORT are to be sent to the SORTOUT DD and not to Java.

  This method is mutually exclusive with `setOutputStreamRecLen(int)` and `setOutputStreamHasRdws()`.

### getChildStdinStream

    public java.io.OutputStream getChildStdinStream()

  Returns a java.io.OutputStream that can be used to send records to the child DFSORT process. This data stream is used to provide input to DFSORT via a sort input exit as an alternative to DD:SORTIN.

  The data sent to this stream should be fixed length records if `setInputStreamRecLen(int)()` has been used, or RDW-prefixed records if `setInputStreamHasRdws()` has been used. If however, `disableInputStream()` was set (the default), then this stream has no use, as input to DFSORT will come from DD:SORTIN.

  For best performance, this OutputStream should be wrapped in a BufferedOutputStream. To write RDW-prefixed records, see `RDWOutputRecordStream`.

  Returns:
    java.io.OutputStream
  Throws:
    `java.lang.IllegalStateException` - if called before `execute()`

### getChildStdoutStream

    public java.io.InputStream getChildStdoutStream()

  Returns a java.io.InputStream that can be used to read output records from the child DFSORT process. This data stream will contain sorted output data from DFSORT via a sort output exit as an alternative to DD:SORTOUT.

  The data sent to this stream should be fixed length records if `setOutputStreamRecLen(int)()` has been used, or RDW-prefixed records if `setOutputStreamHasRdws()` has been used. If however, `disableOutputStream()` was set (the default), then this stream has no use, as output from DFSORT will go to DD:SORTOUT.

  For best performance, this InputStream should be wrapped in a BufferedInputStream. To read RDW-prefixed records, see `RDWInputRecordStream`.

  Returns:
    java.io.InputStream
  Throws:
    `java.lang.IllegalStateException` - if called before `execute()`

### execute

    public void execute()
                 throws ErrnoException

  Run the jdfsort child process, which is a z/OS Java USS binary command wrapper for invoking DFSORT. Passed as arguments to jdfsort are the allocation commands, control statement commands, input/output stream settings.

  Throws:
    `ErrnoException` - if there is a failure launching the child process

### getReturnCode

    public int getReturnCode()

  Wait for DFSORT to complete. This method should be called after I/O from the child's stdin and/or stdout has been processed.

  Returns:
    int the DFSORT return code
  Throws:
    `RcException` - if the child process terminates abnormally without a return code

### getStderrLines

    public java.util.List getStderrLines()

  Return a list of stderr output lines (Strings) from the spawned DfSort process. This method only applies if `isSameAddressSpace()` = false. Otherwise, DFSORT messages will be written to java's stderr.

  Returns:
    List a list of strings

### isSameAddressSpace

    public boolean isSameAddressSpace()

  Answer true if the child jdfsort process will be spawned in the same address space that is running the Java JVM. Answer false if the child process will be spawned in a separate/new BPX address space. Reusing the same address space involves less overhead, but has limitations since only one DFSORT process should be active at a given time in a given address space, since the same DD names are used.

  See Also:
    `setSameAddressSpace(boolean)`

### setSameAddressSpace

    public void setSameAddressSpace(boolean separateAddressSpace)

  If false, run the DFSORT child invocation process in the same address space as the JVM. If true, spawn a new address space.

  See Also:
    `isSameAddressSpace()`

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD