Module ibm.jzos
Package com.ibm.jzos

Class PdsDirectory

java.lang.Object
com.ibm.jzos.PdsDirectory
All Implemented Interfaces:
AutoCloseable

public class PdsDirectory extends Object implements AutoCloseable
A class for opening a PDS directory using ZFile and iterating over its members. This class also supports PDSE directories processed in compatibility mode.

Note: this class does not support reading concatenated partitioned dataset directories, since the C I/O library seems to return "EOF" after the first directory is read.

The class implements AutoCloseable. It can be used with the AutoCloseable with a try-with-resources block or without, as shown in the two examples below: Example 1: Allocate and close a ZFile when a try-with-resources block is not used. The an explicit call to the close() close the ZFile object and release the associated resources. The close() method is called in a finally block to assure that the close is performed after the try block completes.


    ZFile zfile = new  new ZFile(fileName, options);
    try {
        byte[] recBuf = new byte[lrecl];
        // read the records sequentially
        while (zfile.read(recBuf) != -1) {
            String record = new String(recBuf);
            System.out.println("Record=" + record);
        }
    }
    finally {
      zfile.close();
    }
   
Example 2: Allocate a ZFile when a try-with-resources block is used. The method close() is not needed. Upon exiting a try-with-resources block, the AutoCloseable will automatically call the close() method which will lose the ZFile object and release the associated resources.

    try (ZFile zfile = new  new ZFile(fileName, options)) {
        byte[] recBuf = new byte[lrecl];
        // read the records sequentially
        while (zfile.read(recBuf) != -1) {
            String record = new String(recBuf);
            System.out.println("Record=" + record);
        }
    }
    ...
   
Note: this class is not thread-safe; access from multiple threads must be serialized.
  • Constructor Details

  • Method Details

    • close

      public void close() throws IOException
      Close the underlying ZFile on the PDS directory
      Specified by:
      close in interface AutoCloseable
      Throws:
      IOException - as possibly thrown from ZFile.close()
    • iterator

      public Iterator<PdsDirectory.MemberInfo> iterator()
      Answer an Iterator over the PDS directory, which returns a PdsDirectory.MemberInfo object for each entry in the directory.

      The returned Iterator does not support the optional remove() method specified by java.util.Iterator. It cannot be used to delete members from the PDS directory.

      Returns:
      java.util.Iterator over PdsDirectory.MemberInfo objects