- All Implemented Interfaces:
AutoCloseable
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.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA static inner class ofPdsDirectorywhich defines/maps a member directory entry. -
Constructor Summary
ConstructorsConstructorDescriptionPdsDirectory(String pdsName) Open a ZFile with the given name as a PDS directory. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close the underlying ZFile on the PDS directoryiterator()Answer anIteratorover the PDS directory, which returns aPdsDirectory.MemberInfoobject for each entry in the directory.
-
Constructor Details
-
PdsDirectory
Open a ZFile with the given name as a PDS directory.- Parameters:
pdsName- the name given to open the ZFile- Throws:
IOException- if the PDS can't be opened with RECFM=U,BLKSIZE=256, or if its DSORG is not PDS_DIR.- See Also:
-
-
Method Details
-
close
Close the underlying ZFile on the PDS directory- Specified by:
closein interfaceAutoCloseable- Throws:
IOException- as possibly thrown from ZFile.close()
-
iterator
Answer anIteratorover the PDS directory, which returns aPdsDirectory.MemberInfoobject 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
-