使用 Java 程序顺序读取大型机数据集

Sequential read of a mainframe dataset using Java program

我正在尝试使用 Java 程序读取大型机顺序数据集。

我的Java代码:

import java.io.IOException;
import com.ibm.recordio.*;

public class Sequential {

    public static void main(String[] args) {

                try {
                    IRecordFile file = RecordFile.getInstanceOf("//" + args[0]);
                    IRandomAccessRecordFile randomFile = RandomAccessRecordFile.getInstanceOf(file, IConstants.JRIO_READ_MODE);
                    readSequentially(randomFile);
                } catch (Exception e) {
                    e.printStackTrace();
                    System.exit(8);
                }
            }

            // Reads the randomly accessible file sequentially.
            private static void readSequentially(IRandomAccessRecordFile randomFile) throws IOException {
                byte[] buffer = new byte[randomFile.getRecordLength()];
                // Position at the beginning of the file.
                randomFile.positionFirst();
                while (randomFile.read(buffer) != -1) {
                    // Read bytes into buffer. Do something...
                    System.out.println(new String(buffer));
                }
            }


}

我尝试使用以下 JCL 编译此代码。

//DMKSAMP1 JOB ('3000-000000-00-Z-00000000000'),
//            'P19314881-090817-0-S',REGION=0M,
//            CLASS=G,MSGCLASS=H,NOTIFY=&SYSUID
/*JOBPARM LINECT=0,ROOM=ZZZZ
/*ROUTE PRINT PARSIP0
//BPXBATCH EXEC PGM=BPXBATCH,
//         PARM='SH javac /u/dmksn/Sequential.java',
//         REGION=0M
//STDOUT   DD   SYSOUT=*
//STDERR   DD   SYSOUT=*
//STDENV DD DUMMY

我收到一个错误 - package com.ibm.recordio does not exist。我需要做什么才能成功编译程序?

com.ibm.recordio 是 IBM Java Record I/O (JRIO) 的一部分,大约十年前从 IBM Java SDK 6.0.1 开始被弃用写作.

IBM recommends 迁移到 IBM JZOS 工具包。这是您的 z/OS 系统程序员会安装的东西。

如前所述,JRIO 已被弃用,谢天谢地,因为它很糟糕 API!要读取顺序数据集,您绝对应该使用 JZOS RecordReader class。它使用 BSAM 重叠 I/O 并且比常规 ZFile 快得多,后者是 C stdio 上的简单 JNI 包装器。

 String ddname = ZFile.allocDummyDDName();
 String cmd = "alloc fi("+ddname+") da(HLQ.MYDATA) reuse shr msg(2)";
 ZFile.bpxwdyn(cmd);
 RecordReader reader = null;
 try {
   reader = RecordReader.newReaderForDD(ddname);
   byte[] recordBuf = new byte[reader.getLrecl()];
   while ((bytesRead = reader.read(recordBuf)) >= 0) {
     ...
   }
 } finally {
   if (reader != null) {
     try {
       reader.close(); 
     } catch (ZFileException zfe) {
       zfe.printStackTrace();  // but continue
     } 
   }
   try {
     ZFile.bpxwdyn("free fi(" + ddname + ") msg(2)");
   } catch (RcException rce) {
     rce.printStackTrace();  // but continue
   }
 }