Class ZFileRecordReader
- All Implemented Interfaces:
ZFileConstants, AutoCloseable
RecordReader.
In order to provide more efficient dataset record mode read performance, it is often beneficial to read a block, rather than a record, at a time from the underlying dataset. This class wraps an instance of ZFile, re-opens it with RECFM=U, and provides an interface for reading a record at a time. The underlying ZFile must have been opened with the following options:
- type=record
- read mode, either text or binary ("r", "rb" or "rt")
Reading the dataset a block at a time limits the number of calls to the C library fread() function and also reduces the number of JNI calls that need to be made. The z/OS XL C/C++ Programming Guide SC09-4765 (Chapter 34 - I/O Performance considerations) recommends taking this approach to increase performance when possible.
All record formats are supported, however performance gains will only be realized when the average record lengths are significantly less than the average block size. 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);
}
}
...
- Since:
- 2.3.0
- See Also:
-
Field Summary
Fields inherited from interface ZFileConstants
DEFAULT_EBCDIC_CODE_PAGE, DEVICE_DISK, DEVICE_DUMMY, DEVICE_HFS, DEVICE_HIPERSPACE, DEVICE_MEMORY, DEVICE_MSGFILE, DEVICE_OTHER, DEVICE_PRINTER, DEVICE_TAPE, DEVICE_TDQ, DEVICE_TERMINAL, DSORG_CONCAT, DSORG_HFS, DSORG_HIPER, DSORG_MEM, DSORG_PDS_DIR, DSORG_PDS_MEM, DSORG_PDSE, DSORG_PO, DSORG_PS, DSORG_TEMP, DSORG_VSAM, ERRNO_E_ABEND, ERRNO_E_DEFINEFILE, ERRNO_E_READERR, ERRNO_E_WRITEERR, ERRNO_EACCES, ERRNO_EILSEQ, ERRNO_EINVAL, ERRNO_EIO, ERRNO_EPERM, FLAG_DISP_MOD, FLAG_DISP_OLD, FLAG_DISP_SHR, FLAG_PDS_ENQ, LAST_OP_BSAM_BLDL, LAST_OP_BSAM_CLOSE, LAST_OP_BSAM_CLOSE_T, LAST_OP_BSAM_NOTE, LAST_OP_BSAM_OPEN, LAST_OP_BSAM_POINT, LAST_OP_BSAM_READ, LAST_OP_BSAM_STOW, LAST_OP_BSAM_WRITE, LAST_OP_C_CANNOT_EXTEND, LAST_OP_C_DBCS_SI_TRUNCATE, LAST_OP_C_DBCS_SO_TRUNCATE, LAST_OP_C_DBCS_TRUNCATE, LAST_OP_C_DBCS_UNEVEN, LAST_OP_C_FCBCHECK, LAST_OP_C_TRUNCATE, LAST_OP_HSP_CREATE, LAST_OP_HSP_DELETE, LAST_OP_HSP_EXTEND, LAST_OP_HSP_READ, LAST_OP_HSP_WRITE, LAST_OP_IO_CATALOG, LAST_OP_IO_DEVTYPE, LAST_OP_IO_LOCATE, LAST_OP_IO_OBTAIN, LAST_OP_IO_RDJFCB, LAST_OP_IO_RENAME, LAST_OP_IO_SCRATCH, LAST_OP_IO_SWAREQ, LAST_OP_IO_TRKCALC, LAST_OP_IO_UNCATALOG, LAST_OP_QSAM_FREEPOOL, LAST_OP_QSAM_GET, LAST_OP_QSAM_PUT, LAST_OP_QSAM_RELSE, LAST_OP_QSAM_TRUNC, LAST_OP_SVC99_ALLOC, LAST_OP_SVC99_ALLOC_NEW, LAST_OP_SVC99_UNALLOC, LAST_OP_TGET_READ, LAST_OP_TGET_WRITE, LAST_OP_VSAM_CLOSE, LAST_OP_VSAM_ENDREQ, LAST_OP_VSAM_ERASE, LAST_OP_VSAM_GENCB, LAST_OP_VSAM_GET, LAST_OP_VSAM_MODCB, LAST_OP_VSAM_OPEN_ESDS, LAST_OP_VSAM_OPEN_ESDS_PATH, LAST_OP_VSAM_OPEN_FAIL, LAST_OP_VSAM_OPEN_KSDS, LAST_OP_VSAM_OPEN_KSDS_PATH, LAST_OP_VSAM_OPEN_RRDS, LAST_OP_VSAM_POINT, LAST_OP_VSAM_PUT, LAST_OP_VSAM_SHOWCB, LAST_OP_VSAM_TESTCB, LOCATE_KEY_EQ, LOCATE_KEY_EQ_BWD, LOCATE_KEY_FIRST, LOCATE_KEY_GE, LOCATE_KEY_LAST, LOCATE_RBA_EQ, LOCATE_RBA_EQ_BWD, MODE_FLAG_APPEND, MODE_FLAG_READ, MODE_FLAG_UPDATE, MODE_FLAG_WRITE, OPEN_MODE_BINARY, OPEN_MODE_RECORD, OPEN_MODE_TEXT, RECFM_A, RECFM_B, RECFM_F, RECFM_M, RECFM_S, RECFM_U, RECFM_V, S_IRGRP, S_IROTH, S_IRUSR, S_IRWXG, S_IRWXO, S_IRWXU, S_ISGID, S_ISUID, S_ISVTX, S_IWGRP, S_IWOTH, S_IWUSR, S_IXGRP, S_IXOTH, S_IXUSR, SEEK_CUR, SEEK_END, SEEK_SET, VSAM_TYPE_ESDS, VSAM_TYPE_ESDS_PATH, VSAM_TYPE_KSDS, VSAM_TYPE_KSDS_PATH, VSAM_TYPE_NOTVSAM, VSAM_TYPE_RRDS -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close the reader and underlying ZFile.intAnswer the BLKSIZE, which is the maximum block length supported by the dataset.Answers the DD name used to open the underlying dataset.getDsn()Answers the native dataset's absolute name, or name(member) if the native dataset is a member of a PDS.intgetLrecl()Answer the LRECL, which is the maximum record length for variable length files.getRecfm()Get the native file's record format.intAnswer the RECFM bitsstatic ZFileRecordReaderDeprecated.This method no longer provides the most efficient way to perform dataset I/O.intread(byte[] buf) Read a record from the native file into a buffer.intread(byte[] buf, int offset, int len) Read a record from the native file into a buffer.Methods inherited from class RecordReader
getAutoFree, newReader, newReaderForDD, setAutoFree
-
Method Details
-
newReader
Deprecated.This method no longer provides the most efficient way to perform dataset I/O.Construct a new ZFileRecordReader on the given ZFile, which must have been opened in read, record mode.- Throws:
ZFileException- See Also:
-
read
Read a record from the native file into a buffer.- Specified by:
readin classRecordReader- Parameters:
buf- the byte array into which the bytes will be read- Returns:
- the number of bytes read, -1 if EOF encountered.
- Throws:
ZFileException- if the native call fails
-
read
Read a record from the native file into a buffer.- Specified by:
readin classRecordReader- Parameters:
buf- the byte array into which the bytes will be readoffset- the offset, inclusive in buf to start reading byteslen- the number of bytes to read- Returns:
- the number of bytes read, -1 if EOF encountered.
- Throws:
ZFileException- if the native call fails
-
close
Close the reader and underlying ZFile.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein classRecordReader- Throws:
ZFileException- if the native call fails
-
getBlksize
public int getBlksize()Description copied from class:RecordReaderAnswer the BLKSIZE, which is the maximum block length supported by the dataset.- Specified by:
getBlksizein classRecordReader
-
getDDName
Answers the DD name used to open the underlying dataset. Returns null unless this instance was created byRecordReader.newReaderForDD(String)- Specified by:
getDDNamein classRecordReader- Returns:
- String ddname
-
getDsn
Description copied from class:RecordReaderAnswers the native dataset's absolute name, or name(member) if the native dataset is a member of a PDS.- Specified by:
getDsnin classRecordReader- Returns:
- String dataset name
-
getLrecl
public int getLrecl()Description copied from class:RecordReaderAnswer the LRECL, which is the maximum record length for variable length files.- Specified by:
getLreclin classRecordReader
-
getRecfm
Description copied from class:RecordReaderGet the native file's record format.- Specified by:
getRecfmin classRecordReader- See Also:
-
getRecfmBits
public int getRecfmBits()Description copied from class:RecordReaderAnswer the RECFM bits- Specified by:
getRecfmBitsin classRecordReader- See Also:
-