From 8ed39c9664f0abe79b2d4e86f3d01bc249a08d57 Mon Sep 17 00:00:00 2001 From: qiuqiuqiu Date: Tue, 8 Sep 2026 22:26:17 +0800 Subject: [PATCH] fix(core): byte-accurate A-group (ConvUtil padRight/safeSub), B-group FileIo convergence, E1 HIGH sentinels (ZAN03/04/05, KYU09), E3 NUL guard; sync docs (trans-rule/test-rule/checklist) --- JavaSrc/doc/Java测试基准说明.md | 6 +-- JavaSrc/doc/转换基准.md | 8 ++-- JavaSrc/src/FileIo.java | 4 +- JavaSrc/src/FileSample.java | 27 ++++++------- JavaSrc/src/Kin01InpMain.java | 37 +++++++++-------- JavaSrc/src/Kin02UpdMain.java | 27 ++++++------- JavaSrc/src/Kin03ExpMain.java | 22 +++++----- JavaSrc/src/Kin04ChkMain.java | 37 +++++++++-------- JavaSrc/src/Kin05MatMain.java | 28 ++++++------- JavaSrc/src/Kin06CldMain.java | 6 +-- JavaSrc/src/Kin07DaiMain.java | 20 +++------- JavaSrc/src/Kin08DbuMain.java | 14 ++----- JavaSrc/src/Kin09CsvMain.java | 20 ++-------- JavaSrc/src/Kyu01CvtMain.java | 43 ++++++++++---------- JavaSrc/src/Kyu02RegMain.java | 26 ++++++------ JavaSrc/src/Kyu03AggMain.java | 31 +++++++------- JavaSrc/src/Kyu04CalMain.java | 41 +++++++++---------- JavaSrc/src/Kyu05DedMain.java | 38 +++++++++--------- JavaSrc/src/Kyu06UpdMain.java | 26 ++++++------ JavaSrc/src/Kyu07DivMain.java | 41 +++++++++---------- JavaSrc/src/Kyu08PriMain.java | 45 ++++++++++++--------- JavaSrc/src/Kyu09MrgMain.java | 40 ++++++++++--------- JavaSrc/src/Zan01ChkMain.java | 9 +---- JavaSrc/src/Zan02ChkMain.java | 11 +++-- JavaSrc/src/Zan03ChkMain.java | 71 +++++++++++---------------------- JavaSrc/src/Zan04MatMain.java | 31 ++++++-------- JavaSrc/src/Zan05CalMain.java | 46 +++++---------------- JavaSrc/src/Zan06UpdMain.java | 10 +++-- JavaSrc/src/dto/Kin01Rec.java | 21 +++++----- JavaSrc/src/dto/Kin02Rec.java | 17 ++++---- JavaSrc/src/dto/Kin04Rec.java | 15 +++---- JavaSrc/src/dto/Kyu04Rec.java | 34 ++++++---------- JavaSrc/src/util/ConvUtil.java | 34 ++++++++++++---- 33 files changed, 405 insertions(+), 481 deletions(-) diff --git a/JavaSrc/doc/Java测试基准说明.md b/JavaSrc/doc/Java测试基准说明.md index 1fe218e..0f9e333 100644 --- a/JavaSrc/doc/Java测试基准说明.md +++ b/JavaSrc/doc/Java测试基准说明.md @@ -47,10 +47,10 @@ | J1 | 退出码 | 有两条ABEND路径:① 文件I/O异常(IOException)→UncheckedIOException→JVM默认退出码1;② 业务逻辑ABEND(SUB01DAT失败等)→abendPara()→System.exit(999)→Windows实际231 | 路径①期望退出码1;路径②期望231+ABEND CODE消息 | | J2 | 行分隔符 | println在Windows输出CRLF(\\r\\n) | 期望文件须同方式生成后fc比对 | | J3 | BOM | OutputStreamWriter("UTF-8")不写BOM | fc /b首字节应为记录内容 | -| J4 | 字符vs字节 | Java substring/padRight按char计;PIC X(n)按byte计 | 全角混入时定长记录字节数会变(数据限半角方针;VF-A002单独验证行为) | +| J4 | 字符vs字节 | A组收敛后 ConvUtil.padRight/safeSub 按 UTF-8 字节计数(对齐 COBOL PIC X(n) 字节宽):截断回退到完整字界并以空格字节补足,定长记录输出恒等于 len 字节;外部 0xFF(ÿ) 等合法多字节字节直接透传(E1 已把排序哨兵由 \u00FF 改 \uFFFF,不再误当 EOF);仅在 safeSub 读取被切开的多字节字符时产生 U+FFFD(异常输入残余);记录内嵌 \r 会被 BufferedReader.readLine() 提前断行(数据限半角方针,禁止内容含 CR) | 全角混入时定长记录仍保持 len 字节;VF-A002单验 | | J5 | 数值溢出 | int溢出静默绕回≠COBOL高位截断 | NP-A004必测 | | J6 | SIZE ERROR | Java无自动ON SIZE ERROR分支,转换时须显式实现 | NP-N003必查实现存在性 | -| J7 | WRITE异常 | PrintWriter吞IOException(checkError) | 磁盘满等异常无法检测→COM-A005不适用理由之一 | +| J7 | WRITE异常 | (历史)PrintWriter吞IOException(checkError);B组FileIo收敛后全程序写句柄统一 BufferedWriter,写异常→UncheckedIOException | 磁盘满等写异常现可检测(COM-A005适用性以现状为准) | | J8 | 输出覆盖 | FileOutputStream已有输出时覆盖写入 | 幂等性RR-N001天然满足;主机侧再执行需先删文件 | | J9 | BigDecimal精度 | BigDecimal运算的scale/precision须与式样书指定的PIC(n)V9(m)完全一致 | NP-N002必查:scale=m、intLen=n、ROUNDING=HALF_UP,三者缺一不可 | @@ -283,7 +283,7 @@ | 编号 | 区分 | 项目 | 内容 | 优先级 | 适用 | Java确认方法 | |---|---|---|---|---|---|---| -| J-K004 | 异常 | 全角/半角混用 | 混用数据处理 | ◎ | ✅ | 结合J4:全角占2-3字节,定长记录字节数超长;须明确转换语义 | +| J-K004 | 异常 | 全角/半角混用 | 混用数据处理 | ◎ | ✅ | 结合J4:输入全角字节>字段宽时按字节截断回退完整字界+空格补齐,输出严格 len 字节(内容可能被截断) | | J-S001 | 正常 | 全角空格TRIM | TRIM对全角空格 | ◎ | ⚠️ | Java trim()仅去半角空格;全角空格须正则替换(转换规则决定) | | J-D001~004 | 正常 | Shift-JIS 5C/7C | 特殊字节处理 | ◎ | ➖ | 本工程统一UTF-8无SJIS处理 | | J-X系列 | 正常/异常 | EBCDIC↔SJIS转换 | 编码转换 | ◎ | ➖ | 本工程统一UTF-8 | diff --git a/JavaSrc/doc/转换基准.md b/JavaSrc/doc/转换基准.md index cdf8e1f..9dc98d8 100644 --- a/JavaSrc/doc/转换基准.md +++ b/JavaSrc/doc/转换基准.md @@ -70,11 +70,11 @@ | COBOL | Java | |---|---| -| PIC X(n) | String(padRight 定长化) | +| PIC X(n) | String(padRight 定长化;A组收敛:padRight/safeSub 均按 UTF-8 字节计数,对齐 COBOL PIC X(n) 字节宽,截断回退完整字界+空格补足) | | PIC 9(n) | int / long(padLeftZero) | | PIC 9(n)V99 | BigDecimal(toDecimal / formatZoned) | | COMPUTE … ROUNDED | setScale(…, RoundingMode.HALF_UP) | -| 固定长记录拆分 | substring(位置注释对应 05 层定义) | +| 固定长记录拆分 | ConvUtil.safeSub(字节边界切片,COBOL 参照変更 WRK(m:n) 相当;位置注释对应 05 层定义) | ### 3.3 语句·结构映射 @@ -90,8 +90,8 @@ | EVALUATE … WHEN OTHER | switch / default | | DISPLAY | System.out.println | | READ … AT END | readLine() == null | -| OPEN / CLOSE | 同段落→try-with-resources;跨段落→字段保持+显式 close(参照标准例 FileSample) | -| WRITE | writer.println / write | +| OPEN / CLOSE | 统一经 FileIo.openReader/openWriter(B组收敛;UTF-8 BufferedReader/BufferedWriter);同段落→try-with-resources;跨段落→字段保持+显式 close(参照标准例 FileSample) | +| WRITE | writer.write(x) + newLine()(统一 BufferedWriter,IOException→UncheckedIOException) | | CALL 子程序 | 子程序独立类的方法调用(参数按引用→返回值或可变对象承载) | | EXEC SQL(游标/单行/COMMIT/ROLLBACK/WHENEVER SQLERROR) | JDBC PreparedStatement / commit / rollback / try-catch(见 DbSample) | | OCCURS | 数组 / List | diff --git a/JavaSrc/src/FileIo.java b/JavaSrc/src/FileIo.java index acdaf86..801f895 100644 --- a/JavaSrc/src/FileIo.java +++ b/JavaSrc/src/FileIo.java @@ -13,7 +13,9 @@ import java.nio.charset.StandardCharsets; * ============================================================ * JDK8 は FileReader/FileWriter の (String, Charset) コンストラクタを持たないため、 * InputStreamReader/OutputStreamWriter 経由で UTF-8 固定長処理を提供する。 - * デフォルトパッケージに配置し、各 ZAN メインから import 不要で利用可能。 + * デフォルトパッケージに配置し、全メイン(FileSample / Kin* / Kyu* / Zan*)から + * import 不要で利用可能。各メインが直書きしていた同型構築をここへ統一した + * (B 組:内联 OPEN 收敛。読み書き内容・バイト出力は変更なし)。 */ public final class FileIo { diff --git a/JavaSrc/src/FileSample.java b/JavaSrc/src/FileSample.java index bc343c2..c9644d8 100644 --- a/JavaSrc/src/FileSample.java +++ b/JavaSrc/src/FileSample.java @@ -1,10 +1,6 @@ import java.io.BufferedReader; -import java.io.FileInputStream; -import java.io.FileOutputStream; +import java.io.BufferedWriter; import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.io.PrintWriter; import java.io.UncheckedIOException; import java.math.BigDecimal; import java.util.ArrayList; @@ -20,11 +16,11 @@ import util.ConvUtil; * COBOL 与 Java 的对应关系: * SELECT EMPFILE ASSIGN TO SYS001 → 文件路径常量 INP_FILE * FD EMPFILE. 01 EMPREC. → EmpRec DTO + substring 拆分 - * OPEN INPUT EMPFILE → new BufferedReader(...) + * OPEN INPUT EMPFILE → FileIo.openReader(...) * READ EMPFILE AT END MOVE 'Y' TO EOF-FLG → line = br.readLine(); line == null 即 AT END * CLOSE EMPFILE → try-with-resources 自动 close - * OPEN OUTPUT REPFILE → new PrintWriter(...) - * WRITE REP-REC → pw.println(...) + * OPEN OUTPUT REPFILE → FileIo.openWriter(...)(BufferedWriter) + * WRITE REP-REC → bw.write(...) + bw.newLine() * * 文件编码统一为 UTF-8(原 COBOL 为系统代码页时,转换时需确认)。 */ @@ -50,8 +46,7 @@ public class FileSample { */ private static List readFilePara() { List list = new ArrayList(); - try (BufferedReader br = new BufferedReader( - new InputStreamReader(new FileInputStream(INP_FILE), "UTF-8"))) { + try (BufferedReader br = FileIo.openReader(INP_FILE)) { String line; while ((line = br.readLine()) != null) { // AT END → readLine() == null list.add(parseRec(line)); @@ -91,21 +86,23 @@ public class FileSample { private static void writeFilePara(final List list) { BigDecimal wsTotal = BigDecimal.ZERO; // 05 WS-TOTAL PIC 9(7)V99. int wsCnt = 0; // 05 WS-CNT PIC 9(3). - try (PrintWriter pw = new PrintWriter( - new OutputStreamWriter(new FileOutputStream(OUT_FILE), "UTF-8"))) { - pw.println("*** EMP SALARY REPORT ***"); + try (BufferedWriter bw = FileIo.openWriter(OUT_FILE)) { + bw.write("*** EMP SALARY REPORT ***"); + bw.newLine(); for (EmpRec r : list) { // WRITE REP-REC(PIC 编辑:padRight 对应 X(20) 定长化) - pw.println(ConvUtil.padRight(r.getEmpId(), 6) + bw.write(ConvUtil.padRight(r.getEmpId(), 6) + ConvUtil.padRight(r.getEmpName(), 20) + ConvUtil.padRight(r.getEmpDept(), 4) + r.getEmpSalary().setScale(2).toPlainString()); + bw.newLine(); // ADD EMP-SALARY TO WS-TOTAL. / ADD 1 TO WS-CNT. wsTotal = wsTotal.add(r.getEmpSalary()); wsCnt++; } - pw.println("CNT=" + ConvUtil.padLeftZero(wsCnt, 3) + bw.write("CNT=" + ConvUtil.padLeftZero(wsCnt, 3) + " TOTAL=" + wsTotal.setScale(2).toPlainString()); + bw.newLine(); } catch (IOException e) { throw new UncheckedIOException(e); } diff --git a/JavaSrc/src/Kin01InpMain.java b/JavaSrc/src/Kin01InpMain.java index 695cbf4..a2c9984 100644 --- a/JavaSrc/src/Kin01InpMain.java +++ b/JavaSrc/src/Kin01InpMain.java @@ -1,10 +1,6 @@ import java.io.BufferedReader; -import java.io.FileInputStream; -import java.io.FileOutputStream; +import java.io.BufferedWriter; import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.io.PrintWriter; import java.io.UncheckedIOException; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; @@ -175,8 +171,8 @@ public class Kin01InpMain { // フィールド保持+termPara()で明示 close を採用(OPEN/CLOSE 対応を優先)。 private BufferedReader r01InnFil; - private PrintWriter w01OutFil; - private PrintWriter w02OutFil; + private BufferedWriter w01OutFil; + private BufferedWriter w02OutFil; /** FD R01INNFIL の 01 R01INNREC. 03 R01LINE PIC X(80).(現在レコードバッファ) */ private String r01Line = ""; @@ -600,12 +596,9 @@ public class Kin01InpMain { /** OPEN INPUT R01INNFIL / OUTPUT W01OUTFIL W02OUTFIL. */ private void openFiles() { try { - r01InnFil = new BufferedReader( - new InputStreamReader(new FileInputStream(r01InnFile), "UTF-8")); - w01OutFil = new PrintWriter( - new OutputStreamWriter(new FileOutputStream(W01OUT_FILE), "UTF-8")); - w02OutFil = new PrintWriter( - new OutputStreamWriter(new FileOutputStream(W02OUT_FILE), "UTF-8")); + r01InnFil = FileIo.openReader(r01InnFile); + w01OutFil = FileIo.openWriter(W01OUT_FILE); + w02OutFil = FileIo.openWriter(W02OUT_FILE); } catch (IOException e) { throw new UncheckedIOException(e); // OPEN失敗 ≈ ABEND } @@ -613,13 +606,23 @@ public class Kin01InpMain { /** WRITE W01OUTREC./ADD 1 TO CUN-W01OUT. */ private void writeW01() { - w01OutFil.println(w01.toRecordLine()); + try { + w01OutFil.write(w01.toRecordLine()); + w01OutFil.newLine(); + } catch (IOException e) { + throw new UncheckedIOException(e); + } cunW01Out++; } /** WRITE W02OUTREC./ADD 1 TO CUN-W02OUT. */ private void writeW02() { - w02OutFil.println(w02.toRecordLine()); + try { + w02OutFil.write(w02.toRecordLine()); + w02OutFil.newLine(); + } catch (IOException e) { + throw new UncheckedIOException(e); + } cunW02Out++; } @@ -637,8 +640,8 @@ public class Kin01InpMain { try { if (handle instanceof BufferedReader) { ((BufferedReader) handle).close(); - } else if (handle instanceof PrintWriter) { - ((PrintWriter) handle).close(); + } else if (handle instanceof BufferedWriter) { + ((BufferedWriter) handle).close(); } } catch (IOException e) { // CLOSE異常は無視(原程序もFILE STATUS未管理) diff --git a/JavaSrc/src/Kin02UpdMain.java b/JavaSrc/src/Kin02UpdMain.java index b5216ac..974e143 100644 --- a/JavaSrc/src/Kin02UpdMain.java +++ b/JavaSrc/src/Kin02UpdMain.java @@ -1,10 +1,6 @@ import java.io.BufferedReader; -import java.io.FileInputStream; -import java.io.FileOutputStream; +import java.io.BufferedWriter; import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.io.PrintWriter; import java.io.UncheckedIOException; import java.sql.Connection; import java.sql.DriverManager; @@ -137,7 +133,7 @@ public class Kin02UpdMain { // ==================== ファイル・DBハンドル ==================== private BufferedReader r01InnFil; - private PrintWriter w01OutFil; + private BufferedWriter w01OutFil; private Connection conn; /** FD R01INNFIL の 01 R01INNREC(現在レコードバッファ)。 */ @@ -488,13 +484,11 @@ public class Kin02UpdMain { // ==================== ファイル操作補助(OPEN/CLOSE/WRITE 相当) ==================== - /** OPEN INPUT R01INNFIL / OUTPUT W01OUTFIL.(autoFlush で ABEND 前でも書込が失われない) */ + /** OPEN INPUT R01INNFIL / OUTPUT W01OUTFIL. */ private void openFiles() { try { - r01InnFil = new BufferedReader( - new InputStreamReader(new FileInputStream(r01InnFile), "UTF-8")); - w01OutFil = new PrintWriter( - new OutputStreamWriter(new FileOutputStream(W01OUT_FILE), "UTF-8"), true); + r01InnFil = FileIo.openReader(r01InnFile); + w01OutFil = FileIo.openWriter(W01OUT_FILE); } catch (IOException e) { throw new UncheckedIOException(e); // OPEN失敗 ≈ ABEND } @@ -502,7 +496,12 @@ public class Kin02UpdMain { /** WRITE W01OUTREC./ADD 1 TO CUN-W01OUT. */ private void writeW01() { - w01OutFil.println(w01.toRecordLine()); + try { + w01OutFil.write(w01.toRecordLine()); + w01OutFil.newLine(); + } catch (IOException e) { + throw new UncheckedIOException(e); + } cunW01Out++; } @@ -520,8 +519,8 @@ public class Kin02UpdMain { try { if (handle instanceof BufferedReader) { ((BufferedReader) handle).close(); - } else if (handle instanceof PrintWriter) { - ((PrintWriter) handle).close(); + } else if (handle instanceof BufferedWriter) { + ((BufferedWriter) handle).close(); } else if (handle instanceof Connection) { ((Connection) handle).close(); } diff --git a/JavaSrc/src/Kin03ExpMain.java b/JavaSrc/src/Kin03ExpMain.java index 9b49ad7..c4bfdd0 100644 --- a/JavaSrc/src/Kin03ExpMain.java +++ b/JavaSrc/src/Kin03ExpMain.java @@ -1,10 +1,6 @@ import java.io.BufferedReader; -import java.io.FileInputStream; -import java.io.FileOutputStream; +import java.io.BufferedWriter; import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.io.PrintWriter; import java.io.UncheckedIOException; import java.sql.Connection; import java.sql.DriverManager; @@ -120,7 +116,7 @@ public class Kin03ExpMain { private ResultSet rsC1; private PreparedStatement psC2; private ResultSet rsC2; - private PrintWriter w01OutFil; + private BufferedWriter w01OutFil; // ==================== PROCEDURE DIVISION ==================== @@ -212,8 +208,7 @@ public class Kin03ExpMain { /** W01 OPEN(FILE STATUS 異常時は ABEND 999)。 */ private void openW01() { try { - w01OutFil = new PrintWriter( - new OutputStreamWriter(new FileOutputStream(W01OUT_FILE), "UTF-8"), true); + w01OutFil = FileIo.openWriter(W01OUT_FILE); } catch (IOException e) { abendPara(); // IF WS-W01-STATUS NOT = '00' → ABEND } @@ -379,7 +374,12 @@ public class Kin03ExpMain { /** WRITE W01OUTREC./ADD 1 TO CUN-W01OUT. */ private void writeW01() { - w01OutFil.println(w01.toRecordLine()); + try { + w01OutFil.write(w01.toRecordLine()); + w01OutFil.newLine(); + } catch (IOException e) { + throw new UncheckedIOException(e); + } cunW01Out++; } @@ -405,8 +405,8 @@ public class Kin03ExpMain { ((ResultSet) handle).close(); } else if (handle instanceof PreparedStatement) { ((PreparedStatement) handle).close(); - } else if (handle instanceof PrintWriter) { - ((PrintWriter) handle).close(); + } else if (handle instanceof BufferedWriter) { + ((BufferedWriter) handle).close(); } else if (handle instanceof Connection) { ((Connection) handle).close(); } diff --git a/JavaSrc/src/Kin04ChkMain.java b/JavaSrc/src/Kin04ChkMain.java index e1fdf68..8d26caf 100644 --- a/JavaSrc/src/Kin04ChkMain.java +++ b/JavaSrc/src/Kin04ChkMain.java @@ -1,10 +1,6 @@ import java.io.BufferedReader; -import java.io.FileInputStream; -import java.io.FileOutputStream; +import java.io.BufferedWriter; import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.io.PrintWriter; import java.io.UncheckedIOException; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; @@ -138,8 +134,8 @@ public class Kin04ChkMain { // ==================== ファイルハンドル(OPEN/CLOSE 相当) ==================== private BufferedReader r01InnFil; - private PrintWriter w01OutFil; - private PrintWriter w02OutFil; + private BufferedWriter w01OutFil; + private BufferedWriter w02OutFil; /** FD R01INNFIL の 01 R01INNREC. 03 R01LINE PIC X(80).(現在レコードバッファ) */ private String r01Line = ""; @@ -474,12 +470,9 @@ public class Kin04ChkMain { /** OPEN INPUT R01INNFIL / OUTPUT W01OUTFIL W02OUTFIL. */ private void openFiles() { try { - r01InnFil = new BufferedReader( - new InputStreamReader(new FileInputStream(r01InnFile), "UTF-8")); - w01OutFil = new PrintWriter( - new OutputStreamWriter(new FileOutputStream(W01OUT_FILE), "UTF-8")); - w02OutFil = new PrintWriter( - new OutputStreamWriter(new FileOutputStream(W02OUT_FILE), "UTF-8")); + r01InnFil = FileIo.openReader(r01InnFile); + w01OutFil = FileIo.openWriter(W01OUT_FILE); + w02OutFil = FileIo.openWriter(W02OUT_FILE); } catch (IOException e) { throw new UncheckedIOException(e); // OPEN失敗 ≈ ABEND } @@ -487,13 +480,23 @@ public class Kin04ChkMain { /** WRITE W01OUTREC./ADD 1 TO CUN-W01OUT. */ private void writeW01() { - w01OutFil.println(w01.toRecordLine()); + try { + w01OutFil.write(w01.toRecordLine()); + w01OutFil.newLine(); + } catch (IOException e) { + throw new UncheckedIOException(e); + } cunW01Out++; } /** WRITE W02OUTREC./ADD 1 TO CUN-W02OUT. */ private void writeW02() { - w02OutFil.println(w02.toRecordLine()); + try { + w02OutFil.write(w02.toRecordLine()); + w02OutFil.newLine(); + } catch (IOException e) { + throw new UncheckedIOException(e); + } cunW02Out++; } @@ -511,8 +514,8 @@ public class Kin04ChkMain { try { if (handle instanceof BufferedReader) { ((BufferedReader) handle).close(); - } else if (handle instanceof PrintWriter) { - ((PrintWriter) handle).close(); + } else if (handle instanceof BufferedWriter) { + ((BufferedWriter) handle).close(); } } catch (IOException e) { // CLOSE異常は無視(原程序もFILE STATUS未管理) diff --git a/JavaSrc/src/Kin05MatMain.java b/JavaSrc/src/Kin05MatMain.java index 113eed2..dbb4e6a 100644 --- a/JavaSrc/src/Kin05MatMain.java +++ b/JavaSrc/src/Kin05MatMain.java @@ -1,10 +1,6 @@ import java.io.BufferedReader; -import java.io.FileInputStream; -import java.io.FileOutputStream; +import java.io.BufferedWriter; import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.io.PrintWriter; import java.io.UncheckedIOException; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; @@ -145,7 +141,7 @@ public class Kin05MatMain { private BufferedReader r01InnFil; private BufferedReader r02InnFil; - private PrintWriter w01OutFil; + private BufferedWriter w01OutFil; /** 入力ファイルパス(R01/R02/W01)。引数で上書き可。 */ private final String r01InnFile; @@ -522,12 +518,9 @@ public class Kin05MatMain { /** OPEN INPUT R01INNFIL/R02INNFIL / OUTPUT W01OUTFIL(失敗時は STATUS='99'→ABEND)。 */ private void openFiles() { try { - r01InnFil = new BufferedReader( - new InputStreamReader(new FileInputStream(r01InnFile), "UTF-8")); - r02InnFil = new BufferedReader( - new InputStreamReader(new FileInputStream(r02InnFile), "UTF-8")); - w01OutFil = new PrintWriter( - new OutputStreamWriter(new FileOutputStream(w01OutFile), "UTF-8")); + r01InnFil = FileIo.openReader(r01InnFile); + r02InnFil = FileIo.openReader(r02InnFile); + w01OutFil = FileIo.openWriter(w01OutFile); } catch (IOException e) { // OPEN失敗相当:FILE STATUS ≠ '00'(後続の OPENチェックで ABEND 999) wsR01Status = "99"; @@ -538,7 +531,12 @@ public class Kin05MatMain { /** WRITE W01OUTREC./ADD 1 TO CUN-W01OUT. */ private void writeW01() { - w01OutFil.println(w01.toRecordLine()); + try { + w01OutFil.write(w01.toRecordLine()); + w01OutFil.newLine(); + } catch (IOException e) { + throw new UncheckedIOException(e); + } cunW01Out++; } @@ -556,8 +554,8 @@ public class Kin05MatMain { try { if (handle instanceof BufferedReader) { ((BufferedReader) handle).close(); - } else if (handle instanceof PrintWriter) { - ((PrintWriter) handle).close(); + } else if (handle instanceof BufferedWriter) { + ((BufferedWriter) handle).close(); } } catch (IOException e) { // CLOSE異常は無視(原程序もFILE STATUS未管理) diff --git a/JavaSrc/src/Kin06CldMain.java b/JavaSrc/src/Kin06CldMain.java index c95e0c3..3111bca 100644 --- a/JavaSrc/src/Kin06CldMain.java +++ b/JavaSrc/src/Kin06CldMain.java @@ -4,9 +4,6 @@ import dto.ZanmsgacPar; import util.ConvUtil; import java.io.BufferedWriter; -import java.io.FileOutputStream; -import java.io.OutputStreamWriter; -import java.nio.charset.StandardCharsets; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; @@ -117,8 +114,7 @@ public class Kin06CldMain { // 出力ファイルOPEN try { - outrecFil = new BufferedWriter( - new OutputStreamWriter(new FileOutputStream(OUTREC_FILE), StandardCharsets.UTF_8)); + outrecFil = FileIo.openWriter(OUTREC_FILE); } catch (Exception e) { throw new RuntimeException("出力ファイルOPEN失敗: " + e.getMessage(), e); } diff --git a/JavaSrc/src/Kin07DaiMain.java b/JavaSrc/src/Kin07DaiMain.java index df29765..b869133 100644 --- a/JavaSrc/src/Kin07DaiMain.java +++ b/JavaSrc/src/Kin07DaiMain.java @@ -10,11 +10,6 @@ import util.ConvUtil; import java.io.BufferedReader; import java.io.BufferedWriter; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; @@ -110,16 +105,14 @@ public class Kin07DaiMain { // 出力ファイルOPEN try { - w01OutFil = new BufferedWriter( - new OutputStreamWriter(new FileOutputStream(W01_FILE), StandardCharsets.UTF_8)); + w01OutFil = FileIo.openWriter(W01_FILE); } catch (Exception e) { throw new RuntimeException("出力ファイルOPEN失敗: " + e.getMessage(), e); } // W02(ERROR-LOG) OPEN(設計書使用ファイル一覧 No.5) try { - w02OutFil = new BufferedWriter( - new OutputStreamWriter(new FileOutputStream(W02_FILE), StandardCharsets.UTF_8)); + w02OutFil = FileIo.openWriter(W02_FILE); } catch (Exception e) { throw new RuntimeException("W02出力ファイルOPEN失敗: " + e.getMessage(), e); } @@ -358,8 +351,7 @@ public class Kin07DaiMain { private List readR01() { List list = new ArrayList<>(); - try (BufferedReader br = new BufferedReader( - new InputStreamReader(new FileInputStream(R01_FILE), StandardCharsets.UTF_8))) { + try (BufferedReader br = FileIo.openReader(R01_FILE)) { String line; while ((line = br.readLine()) != null) { if (line.trim().isEmpty()) { @@ -377,8 +369,7 @@ public class Kin07DaiMain { private List readR02() { List list = new ArrayList<>(); - try (BufferedReader br = new BufferedReader( - new InputStreamReader(new FileInputStream(R02_FILE), StandardCharsets.UTF_8))) { + try (BufferedReader br = FileIo.openReader(R02_FILE)) { String line; while ((line = br.readLine()) != null) { if (line.trim().isEmpty()) { @@ -396,8 +387,7 @@ public class Kin07DaiMain { private List readR03() { List list = new ArrayList<>(); - try (BufferedReader br = new BufferedReader( - new InputStreamReader(new FileInputStream(R03_FILE), StandardCharsets.UTF_8))) { + try (BufferedReader br = FileIo.openReader(R03_FILE)) { String line; while ((line = br.readLine()) != null) { if (line.trim().isEmpty()) { diff --git a/JavaSrc/src/Kin08DbuMain.java b/JavaSrc/src/Kin08DbuMain.java index 8aa9f1d..84390bd 100644 --- a/JavaSrc/src/Kin08DbuMain.java +++ b/JavaSrc/src/Kin08DbuMain.java @@ -6,11 +6,6 @@ import util.ConvUtil; import java.io.BufferedReader; import java.io.BufferedWriter; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.nio.charset.StandardCharsets; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; @@ -125,8 +120,7 @@ public class Kin08DbuMain { // 入出力ファイルOPEN try { - w01OutFil = new BufferedWriter( - new OutputStreamWriter(new FileOutputStream(W01_FILE), StandardCharsets.UTF_8)); + w01OutFil = FileIo.openWriter(W01_FILE); } catch (Exception e) { throw new RuntimeException("出力ファイルOPEN失敗: " + e.getMessage(), e); } @@ -136,8 +130,7 @@ public class Kin08DbuMain { // SYSIN 読込・解析(1199-SYSIN-LOOP / 1110/1120/1130) // ***************************************************************** private void readSysin() { - try (BufferedReader br = new BufferedReader( - new InputStreamReader(new FileInputStream(SYSIN_FILE), StandardCharsets.UTF_8))) { + try (BufferedReader br = FileIo.openReader(SYSIN_FILE)) { String line; while ((line = br.readLine()) != null) { if (line.trim().isEmpty()) { @@ -188,8 +181,7 @@ public class Kin08DbuMain { if (resetMode) { resetDelete(); } - try (BufferedReader br = new BufferedReader( - new InputStreamReader(new FileInputStream(R01_FILE), StandardCharsets.UTF_8))) { + try (BufferedReader br = FileIo.openReader(R01_FILE)) { String line; while ((line = br.readLine()) != null) { if (line.trim().isEmpty()) { diff --git a/JavaSrc/src/Kin09CsvMain.java b/JavaSrc/src/Kin09CsvMain.java index baa5632..d4e8203 100644 --- a/JavaSrc/src/Kin09CsvMain.java +++ b/JavaSrc/src/Kin09CsvMain.java @@ -1,10 +1,9 @@ import java.io.BufferedWriter; -import java.io.FileOutputStream; -import java.io.OutputStreamWriter; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; +import util.ConvUtil; public class Kin09CsvMain { @@ -37,8 +36,7 @@ public class Kin09CsvMain { Class.forName("org.sqlite.JDBC"); try (Connection conn = DriverManager.getConnection("jdbc:sqlite:data/kin.db")) { - try (BufferedWriter out = new BufferedWriter( - new OutputStreamWriter(new FileOutputStream(OUTPUT_FILE), "UTF-8"))) { + try (BufferedWriter out = FileIo.openWriter(OUTPUT_FILE)) { long w01out = 0; @@ -193,7 +191,7 @@ public class Kin09CsvMain { } private static void writeRec(BufferedWriter out, String content) throws Exception { - out.write(padRight(content, REC_LEN)); + out.write(ConvUtil.padRight(content, REC_LEN)); out.newLine(); } @@ -203,16 +201,4 @@ public class Kin09CsvMain { } writeRec(out, content); } - - private static String padRight(String s, int len) { - if (s == null) s = ""; - StringBuilder sb = new StringBuilder(s); - while (sb.length() < len) { - sb.append(' '); - } - if (sb.length() > len) { - sb.setLength(len); - } - return sb.toString(); - } } diff --git a/JavaSrc/src/Kyu01CvtMain.java b/JavaSrc/src/Kyu01CvtMain.java index 60cdce7..9f9e84c 100644 --- a/JavaSrc/src/Kyu01CvtMain.java +++ b/JavaSrc/src/Kyu01CvtMain.java @@ -1,10 +1,6 @@ import java.io.BufferedReader; -import java.io.FileInputStream; -import java.io.FileOutputStream; +import java.io.BufferedWriter; import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.io.PrintWriter; import java.io.UncheckedIOException; import java.nio.charset.StandardCharsets; @@ -121,8 +117,8 @@ public class Kyu01CvtMain { // ==================== ファイルハンドル(OPEN/CLOSE 相当) ==================== private BufferedReader r01InnFil; - private PrintWriter w01OutFil; - private PrintWriter w02OutFil; + private BufferedWriter w01OutFil; + private BufferedWriter w02OutFil; /** 入力ファイルパス。デフォルトは SELECT ASSIGN 対応の R01INN_FILE。 */ private final String r01InnFile; @@ -321,8 +317,8 @@ public class Kyu01CvtMain { if (t.isEmpty()) { // 空項目は UNSTRING で受信されなかったのと同等(INITIALIZE 済の SPACE) out[i] = ConvUtil.padRight("", FLD_WIDTH[i]); - } else if (t.length() > FLD_WIDTH[i]) { - out[i] = t.substring(0, FLD_WIDTH[i]); // 受信領域 PIC 幅で切捨 + } else if (t.getBytes(StandardCharsets.UTF_8).length > FLD_WIDTH[i]) { + out[i] = ConvUtil.padRight(t, FLD_WIDTH[i]); // 受信領域 PIC 幅で切捨 } else { out[i] = t; } @@ -361,7 +357,7 @@ public class Kyu01CvtMain { private void errorCsvPara(final String logical) { w02.reset(); w02.setErrCategory("CSV-ERR "); - final String detail = (logical.length() > 80) ? logical.substring(0, 80) : logical; + final String detail = ConvUtil.safeSub(logical, 0, 80); w02.setErrDetail(detail); writeW02(); } @@ -421,12 +417,9 @@ public class Kyu01CvtMain { /** OPEN INPUT R01INNFIL / OUTPUT W01OUTFIL W02OUTFIL. */ private void openFiles() { try { - r01InnFil = new BufferedReader( - new InputStreamReader(new FileInputStream(r01InnFile), StandardCharsets.UTF_8)); - w01OutFil = new PrintWriter( - new OutputStreamWriter(new FileOutputStream(W01OUT_FILE), StandardCharsets.UTF_8)); - w02OutFil = new PrintWriter( - new OutputStreamWriter(new FileOutputStream(W02OUT_FILE), StandardCharsets.UTF_8)); + r01InnFil = FileIo.openReader(r01InnFile); + w01OutFil = FileIo.openWriter(W01OUT_FILE); + w02OutFil = FileIo.openWriter(W02OUT_FILE); } catch (IOException e) { throw new UncheckedIOException(e); // OPEN失敗 ≈ ABEND } @@ -434,13 +427,23 @@ public class Kyu01CvtMain { /** WRITE W01OUTREC./ADD 1 TO CUN-W01OUT. */ private void writeW01() { - w01OutFil.println(w01.toRecordLine()); + try { + w01OutFil.write(w01.toRecordLine()); + w01OutFil.newLine(); + } catch (IOException e) { + throw new UncheckedIOException(e); + } cunW01Out++; } /** WRITE W02OUTREC./ADD 1 TO CUN-W02OUT. */ private void writeW02() { - w02OutFil.println(w02.toRecordLine()); + try { + w02OutFil.write(w02.toRecordLine()); + w02OutFil.newLine(); + } catch (IOException e) { + throw new UncheckedIOException(e); + } cunW02Out++; } @@ -458,8 +461,8 @@ public class Kyu01CvtMain { try { if (handle instanceof BufferedReader) { ((BufferedReader) handle).close(); - } else if (handle instanceof PrintWriter) { - ((PrintWriter) handle).close(); + } else if (handle instanceof BufferedWriter) { + ((BufferedWriter) handle).close(); } } catch (IOException e) { // CLOSE異常は無視(原程序もFILE STATUS未管理) diff --git a/JavaSrc/src/Kyu02RegMain.java b/JavaSrc/src/Kyu02RegMain.java index 70fa04b..7f953e3 100644 --- a/JavaSrc/src/Kyu02RegMain.java +++ b/JavaSrc/src/Kyu02RegMain.java @@ -1,12 +1,7 @@ import java.io.BufferedReader; -import java.io.FileInputStream; -import java.io.FileOutputStream; +import java.io.BufferedWriter; import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.io.PrintWriter; import java.io.UncheckedIOException; -import java.nio.charset.StandardCharsets; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; @@ -152,7 +147,7 @@ public class Kyu02RegMain { /** R02INNFIL 読取ハンドル(OPEN/CLOSE はフィールド保持、finally でクローズ) */ private BufferedReader r02InnFil; /** W03OUTFIL 書込ハンドル(同上) */ - private PrintWriter w03OutFil; + private BufferedWriter w03OutFil; /** DB2 接続(EXEC SQL CONNECT TO … END-EXEC 相当) */ private Connection conn; @@ -295,7 +290,12 @@ public class Kyu02RegMain { w03.reset(); w03.setErrCategory("DB-ERR"); // MOVE 'DB-ERR' TO W03ERR-CATEGORY(PIC X(008)) w03.setErrDetail(dbvEmpId); // MOVE DBV-EMP-ID TO W03ERR-DETAIL(PIC X(192)) - w03OutFil.println(w03.toRecordLine()); + try { + w03OutFil.write(w03.toRecordLine()); + w03OutFil.newLine(); + } catch (IOException e) { + throw new UncheckedIOException(e); + } cunW03Out++; } @@ -437,10 +437,8 @@ public class Kyu02RegMain { /** OPEN INPUT R02INNFIL / OUTPUT W03OUTFIL. */ private void openFiles() { try { - r02InnFil = new BufferedReader( - new InputStreamReader(new FileInputStream(R02INN_FILE), StandardCharsets.UTF_8)); - w03OutFil = new PrintWriter( - new OutputStreamWriter(new FileOutputStream(W03OUT_FILE), StandardCharsets.UTF_8)); + r02InnFil = FileIo.openReader(R02INN_FILE); + w03OutFil = FileIo.openWriter(W03OUT_FILE); } catch (IOException e) { throw new UncheckedIOException(e); // OPEN失敗 ≈ ABEND } @@ -458,8 +456,8 @@ public class Kyu02RegMain { try { if (handle instanceof BufferedReader) { ((BufferedReader) handle).close(); - } else if (handle instanceof PrintWriter) { - ((PrintWriter) handle).close(); + } else if (handle instanceof BufferedWriter) { + ((BufferedWriter) handle).close(); } } catch (IOException e) { // CLOSE異常は無視(原程序も FILE STATUS 未管理) diff --git a/JavaSrc/src/Kyu03AggMain.java b/JavaSrc/src/Kyu03AggMain.java index d9bf698..e157720 100644 --- a/JavaSrc/src/Kyu03AggMain.java +++ b/JavaSrc/src/Kyu03AggMain.java @@ -1,13 +1,8 @@ import java.io.BufferedReader; -import java.io.FileInputStream; -import java.io.FileOutputStream; +import java.io.BufferedWriter; import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.io.PrintWriter; import java.io.UncheckedIOException; import java.math.BigDecimal; -import java.nio.charset.StandardCharsets; import dto.Kyu02Rec; import dto.Kyu99Rec; @@ -134,8 +129,8 @@ public class Kyu03AggMain { // ==================== ファイルハンドル(OPEN/CLOSE 相当) ==================== private BufferedReader r01InnFil; - private PrintWriter w01OutFil; - private PrintWriter w02OutFil; + private BufferedWriter w01OutFil; + private BufferedWriter w02OutFil; /** 入力ファイルパス。デフォルトは SELECT ASSIGN 対応の R01INN_FILE。 */ private final String r01InnFile; @@ -291,7 +286,12 @@ public class Kyu03AggMain { // MOVE WRK-ABSENT-COUNT TO W01ABSENT-COUNT. w01.setAbsentCount(wrkAbsentCount); // WRITE W01OUTREC./ADD 1 TO CUN-W01OUT. - w01OutFil.println(w01.toRecordLine()); + try { + w01OutFil.write(w01.toRecordLine()); + w01OutFil.newLine(); + } catch (IOException e) { + throw new UncheckedIOException(e); + } cunW01Out++; } @@ -352,12 +352,9 @@ public class Kyu03AggMain { /** OPEN INPUT R01INNFIL / OUTPUT W01OUTFIL W02OUTFIL. */ private void openFiles() { try { - r01InnFil = new BufferedReader( - new InputStreamReader(new FileInputStream(r01InnFile), StandardCharsets.UTF_8)); - w01OutFil = new PrintWriter( - new OutputStreamWriter(new FileOutputStream(W01OUT_FILE), StandardCharsets.UTF_8)); - w02OutFil = new PrintWriter( - new OutputStreamWriter(new FileOutputStream(W02OUT_FILE), StandardCharsets.UTF_8)); + r01InnFil = FileIo.openReader(r01InnFile); + w01OutFil = FileIo.openWriter(W01OUT_FILE); + w02OutFil = FileIo.openWriter(W02OUT_FILE); } catch (IOException e) { throw new UncheckedIOException(e); // OPEN失敗 ≈ ABEND } @@ -377,8 +374,8 @@ public class Kyu03AggMain { try { if (handle instanceof BufferedReader) { ((BufferedReader) handle).close(); - } else if (handle instanceof PrintWriter) { - ((PrintWriter) handle).close(); + } else if (handle instanceof BufferedWriter) { + ((BufferedWriter) handle).close(); } } catch (IOException e) { // CLOSE異常は無視(原程序もFILE STATUS未管理) diff --git a/JavaSrc/src/Kyu04CalMain.java b/JavaSrc/src/Kyu04CalMain.java index 00d9ba3..6228df5 100644 --- a/JavaSrc/src/Kyu04CalMain.java +++ b/JavaSrc/src/Kyu04CalMain.java @@ -1,14 +1,9 @@ import java.io.BufferedReader; -import java.io.FileInputStream; -import java.io.FileOutputStream; +import java.io.BufferedWriter; import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.io.PrintWriter; import java.io.UncheckedIOException; import java.math.BigDecimal; import java.math.RoundingMode; -import java.nio.charset.StandardCharsets; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; @@ -203,8 +198,8 @@ public class Kyu04CalMain { // ==================== ファイルハンドル / DB接続(OPEN/CLOSE 相当) ==================== private BufferedReader r02InnFil; - private PrintWriter w03OutFil; - private PrintWriter w04OutFil; + private BufferedWriter w03OutFil; + private BufferedWriter w04OutFil; private Connection conn; // ==================== PROCEDURE DIVISION ==================== @@ -497,7 +492,12 @@ public class Kyu04CalMain { + ConvUtil.padRight(wrkAttendType, 1) // MOVE WRK-ATTEND-TYPE + ConvUtil.padRight(wrkAllowanceType, 3) // MOVE WRK-ALLOWANCE-TYPE + ConvUtil.padRight("", 131); // FILLER X(131) - w03OutFil.println(line); + try { + w03OutFil.write(line); + w03OutFil.newLine(); + } catch (IOException e) { + throw new UncheckedIOException(e); + } cunW03Out++; } @@ -509,7 +509,12 @@ public class Kyu04CalMain { w04.reset(); w04.setErrCategory("DB-ERR"); w04.setErrDetail(r02EmpId); - w04OutFil.println(w04.toRecordLine()); + try { + w04OutFil.write(w04.toRecordLine()); + w04OutFil.newLine(); + } catch (IOException e) { + throw new UncheckedIOException(e); + } cunW04Out++; } @@ -559,12 +564,9 @@ public class Kyu04CalMain { /** OPEN INPUT R02INNFIL / OUTPUT W03OUTFIL W04OUTFIL. */ private void openFiles() { try { - r02InnFil = new BufferedReader( - new InputStreamReader(new FileInputStream(R02INN_FILE), StandardCharsets.UTF_8)); - w03OutFil = new PrintWriter( - new OutputStreamWriter(new FileOutputStream(W03OUT_FILE), StandardCharsets.UTF_8)); - w04OutFil = new PrintWriter( - new OutputStreamWriter(new FileOutputStream(W04OUT_FILE), StandardCharsets.UTF_8)); + r02InnFil = FileIo.openReader(R02INN_FILE); + w03OutFil = FileIo.openWriter(W03OUT_FILE); + w04OutFil = FileIo.openWriter(W04OUT_FILE); } catch (IOException e) { throw new UncheckedIOException(e); // OPEN失敗 ≈ ABEND } @@ -586,8 +588,8 @@ public class Kyu04CalMain { try { if (handle instanceof BufferedReader) { ((BufferedReader) handle).close(); - } else if (handle instanceof PrintWriter) { - ((PrintWriter) handle).close(); + } else if (handle instanceof BufferedWriter) { + ((BufferedWriter) handle).close(); } else if (handle instanceof Connection) { ((Connection) handle).close(); } @@ -598,8 +600,7 @@ public class Kyu04CalMain { /** PAY-PARAM(R03) 読込:OPEN INPUT / READ INTO WRK-PARAM-BASE / CLOSE. */ private void readParam() { - try (BufferedReader r03 = new BufferedReader( - new InputStreamReader(new FileInputStream(R03INN_FILE), StandardCharsets.UTF_8))) { + try (BufferedReader r03 = FileIo.openReader(R03INN_FILE)) { final String line = r03.readLine(); wrkParamBase = (line == null) ? "" : line; } catch (IOException e) { diff --git a/JavaSrc/src/Kyu05DedMain.java b/JavaSrc/src/Kyu05DedMain.java index 187bf0f..4fd8723 100644 --- a/JavaSrc/src/Kyu05DedMain.java +++ b/JavaSrc/src/Kyu05DedMain.java @@ -1,14 +1,9 @@ import java.io.BufferedReader; -import java.io.FileInputStream; -import java.io.FileOutputStream; +import java.io.BufferedWriter; import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.io.PrintWriter; import java.io.UncheckedIOException; import java.math.BigDecimal; import java.math.RoundingMode; -import java.nio.charset.StandardCharsets; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; @@ -174,8 +169,8 @@ public class Kyu05DedMain { // ==================== ファイルハンドル / DB接続(OPEN/CLOSE 相当) ==================== private BufferedReader r01InnFil; - private PrintWriter w01OutFil; - private PrintWriter w02OutFil; + private BufferedWriter w01OutFil; + private BufferedWriter w02OutFil; private Connection conn; /** 入力ファイルパス。デフォルトは SELECT ASSIGN 対応の R01INN_FILE。 */ @@ -492,12 +487,9 @@ public class Kyu05DedMain { /** OPEN INPUT R01INNFIL / OUTPUT W01OUTFIL W02OUTFIL. */ private void openFiles() { try { - r01InnFil = new BufferedReader( - new InputStreamReader(new FileInputStream(r01InnFile), StandardCharsets.UTF_8)); - w01OutFil = new PrintWriter( - new OutputStreamWriter(new FileOutputStream(W01OUT_FILE), StandardCharsets.UTF_8)); - w02OutFil = new PrintWriter( - new OutputStreamWriter(new FileOutputStream(W02OUT_FILE), StandardCharsets.UTF_8)); + r01InnFil = FileIo.openReader(r01InnFile); + w01OutFil = FileIo.openWriter(W01OUT_FILE); + w02OutFil = FileIo.openWriter(W02OUT_FILE); } catch (IOException e) { throw new UncheckedIOException(e); // OPEN失敗 ≈ ABEND } @@ -505,13 +497,23 @@ public class Kyu05DedMain { /** WRITE W01OUTREC./ADD 1 TO CUN-W01OUT. */ private void writeW01() { - w01OutFil.println(w01.toRecordLine()); + try { + w01OutFil.write(w01.toRecordLine()); + w01OutFil.newLine(); + } catch (IOException e) { + throw new UncheckedIOException(e); + } cunW01Out++; } /** WRITE W02OUTREC./ADD 1 TO CUN-W02OUT. */ private void writeW02() { - w02OutFil.println(w02.toRecordLine()); + try { + w02OutFil.write(w02.toRecordLine()); + w02OutFil.newLine(); + } catch (IOException e) { + throw new UncheckedIOException(e); + } cunW02Out++; } @@ -529,8 +531,8 @@ public class Kyu05DedMain { try { if (handle instanceof BufferedReader) { ((BufferedReader) handle).close(); - } else if (handle instanceof PrintWriter) { - ((PrintWriter) handle).close(); + } else if (handle instanceof BufferedWriter) { + ((BufferedWriter) handle).close(); } } catch (IOException e) { // CLOSE異常は無視(原程序も FILE STATUS 未管理) diff --git a/JavaSrc/src/Kyu06UpdMain.java b/JavaSrc/src/Kyu06UpdMain.java index af89c30..c66211d 100644 --- a/JavaSrc/src/Kyu06UpdMain.java +++ b/JavaSrc/src/Kyu06UpdMain.java @@ -1,12 +1,7 @@ import java.io.BufferedReader; -import java.io.FileInputStream; -import java.io.FileOutputStream; +import java.io.BufferedWriter; import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.io.PrintWriter; import java.io.UncheckedIOException; -import java.nio.charset.StandardCharsets; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; @@ -147,7 +142,7 @@ public class Kyu06UpdMain { // ==================== ファイルハンドル(OPEN/CLOSE 相当) ==================== private BufferedReader r02InnFil; - private PrintWriter w03OutFil; + private BufferedWriter w03OutFil; /** EXEC SQL CONNECT で取得したコネクション */ private Connection conn; @@ -411,10 +406,8 @@ public class Kyu06UpdMain { /** OPEN INPUT R02INNFIL / OUTPUT W03OUTFIL. */ private void openFiles() { try { - r02InnFil = new BufferedReader( - new InputStreamReader(new FileInputStream(R02INN_FILE), StandardCharsets.UTF_8)); - w03OutFil = new PrintWriter( - new OutputStreamWriter(new FileOutputStream(W03OUT_FILE), StandardCharsets.UTF_8)); + r02InnFil = FileIo.openReader(R02INN_FILE); + w03OutFil = FileIo.openWriter(W03OUT_FILE); } catch (IOException e) { throw new UncheckedIOException(e); // OPEN失敗 ≈ ABEND } @@ -422,7 +415,12 @@ public class Kyu06UpdMain { /** WRITE W03OUTREC./ADD 1 TO CUN-W03OUT. */ private void writeW03() { - w03OutFil.println(w03.toRecordLine()); + try { + w03OutFil.write(w03.toRecordLine()); + w03OutFil.newLine(); + } catch (IOException e) { + throw new UncheckedIOException(e); + } cunW03Out++; } @@ -438,8 +436,8 @@ public class Kyu06UpdMain { try { if (handle instanceof BufferedReader) { ((BufferedReader) handle).close(); - } else if (handle instanceof PrintWriter) { - ((PrintWriter) handle).close(); + } else if (handle instanceof BufferedWriter) { + ((BufferedWriter) handle).close(); } } catch (IOException e) { // CLOSE異常は無視(原程序もFILE STATUS未管理) diff --git a/JavaSrc/src/Kyu07DivMain.java b/JavaSrc/src/Kyu07DivMain.java index d770945..c0a01d3 100644 --- a/JavaSrc/src/Kyu07DivMain.java +++ b/JavaSrc/src/Kyu07DivMain.java @@ -1,12 +1,7 @@ import java.io.BufferedReader; -import java.io.FileInputStream; -import java.io.FileOutputStream; +import java.io.BufferedWriter; import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.io.PrintWriter; import java.io.UncheckedIOException; -import java.nio.charset.StandardCharsets; import dto.Kyu07R01Rec; import dto.Kyu99Rec; @@ -167,8 +162,8 @@ public class Kyu07DivMain { // ==================== ファイルハンドル(OPEN/CLOSE 相当) ==================== private BufferedReader r01InnFil; - private PrintWriter w99OutFil; - private PrintWriter deptOutFil; + private BufferedWriter w99OutFil; + private BufferedWriter deptOutFil; /** 現在OPEN中の部署コード(1ファイルのみOPENを管理)。 */ private String openDeptCode = ""; @@ -229,10 +224,8 @@ public class Kyu07DivMain { // *** OPEN INPUT R01INNFIL / OPEN OUTPUT W99OUTFIL. try { - r01InnFil = new BufferedReader( - new InputStreamReader(new FileInputStream(r01InnFile), StandardCharsets.UTF_8)); - w99OutFil = new PrintWriter( - new OutputStreamWriter(new FileOutputStream(W99OUT_FILE), StandardCharsets.UTF_8)); + r01InnFil = FileIo.openReader(r01InnFile); + w99OutFil = FileIo.openWriter(W99OUT_FILE); } catch (IOException e) { throw new UncheckedIOException(e); // OPEN失敗 ≈ ABEND } @@ -246,8 +239,7 @@ public class Kyu07DivMain { * OPEN→READ AT END(全部署対象) / カードありは "DEPT=01,02,05,10" 形式をパース。 */ private void sysInPara() { - try (BufferedReader sysIn = new BufferedReader( - new InputStreamReader(new FileInputStream(SYSIN_FILE), StandardCharsets.UTF_8))) { + try (BufferedReader sysIn = FileIo.openReader(SYSIN_FILE)) { final String line = sysIn.readLine(); if (line == null) { // *** AT END: SET WRK-ALL-DEPTS TO TRUE(制御カードなし→全部署対象) @@ -397,8 +389,7 @@ public class Kyu07DivMain { } // *** WHEN '01' 〜 '50': OPEN OUTPUT DEPTnn-FILE try { - deptOutFil = new PrintWriter( - new OutputStreamWriter(new FileOutputStream(getDeptPath(deptCode)), StandardCharsets.UTF_8)); + deptOutFil = FileIo.openWriter(getDeptPath(deptCode)); openDeptCode = deptCode; } catch (IOException e) { throw new UncheckedIOException(e); // OPEN失敗 ≈ ABEND @@ -437,7 +428,12 @@ public class Kyu07DivMain { if (k >= 0) { // *** WHEN '01' 〜 '50': WRITE DEPTnn-REC FROM R01INNREC if (deptOutFil != null) { - deptOutFil.println(r01.toRecordLine()); + try { + deptOutFil.write(r01.toRecordLine()); + deptOutFil.newLine(); + } catch (IOException e) { + throw new UncheckedIOException(e); + } } } // *** ADD 1 TO CUN-DEPT-OUT(WHEN OTHER 含む全レコードをカウント) @@ -520,7 +516,12 @@ public class Kyu07DivMain { /** WRITE W99OUTREC./ADD 1 TO CUN-W99OUT. */ private void writeW99() { - w99OutFil.println(w99.toRecordLine()); + try { + w99OutFil.write(w99.toRecordLine()); + w99OutFil.newLine(); + } catch (IOException e) { + throw new UncheckedIOException(e); + } cunW99Out++; } @@ -539,8 +540,8 @@ public class Kyu07DivMain { try { if (handle instanceof BufferedReader) { ((BufferedReader) handle).close(); - } else if (handle instanceof PrintWriter) { - ((PrintWriter) handle).close(); + } else if (handle instanceof BufferedWriter) { + ((BufferedWriter) handle).close(); } } catch (IOException e) { // CLOSE異常は無視(原程序もFILE STATUS未管理) diff --git a/JavaSrc/src/Kyu08PriMain.java b/JavaSrc/src/Kyu08PriMain.java index 5bc8dc1..04958d3 100644 --- a/JavaSrc/src/Kyu08PriMain.java +++ b/JavaSrc/src/Kyu08PriMain.java @@ -1,12 +1,7 @@ import java.io.BufferedReader; -import java.io.FileInputStream; -import java.io.FileOutputStream; +import java.io.BufferedWriter; import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.io.PrintWriter; import java.io.UncheckedIOException; -import java.nio.charset.StandardCharsets; import dto.Kyu04Rec; import dto.Kyu05Rec; @@ -133,8 +128,8 @@ public class Kyu08PriMain { // ==================== ファイルハンドル(OPEN/CLOSE 相当) ==================== private BufferedReader r01InnFil; - private PrintWriter w01OutFil; - private PrintWriter w02OutFil; + private BufferedWriter w01OutFil; + private BufferedWriter w02OutFil; // ==================== PROCEDURE DIVISION ==================== @@ -241,7 +236,12 @@ public class Kyu08PriMain { // *** ヘッダ出力(BEFORE ADVANCING PAGE) // WRITE W01OUTREC FROM HEADER-LINE BEFORE ADVANCING PAGE. - w01OutFil.println(buildHeaderLine(wrkPageCounter)); + try { + w01OutFil.write(buildHeaderLine(wrkPageCounter)); + w01OutFil.newLine(); + } catch (IOException e) { + throw new UncheckedIOException(e); + } // *** 明細行編集(DETAIL-LINE ≡ KYU05REC 布局:PAGE-TITLE=SPACE) // MOVE R01EMP-ID TO DL-EMP-ID. @@ -258,13 +258,23 @@ public class Kyu08PriMain { // WRITE W01OUTREC FROM DETAIL-LINE BEFORE ADVANCING 1 LINE // AT END-OF-PAGE WRITE W01OUTREC FROM FOOTER-LINE BEFORE ADVANCING PAGE. // (1社員1ページのため AT END-OF-PAGE は発動しない) - w01OutFil.println(w01.toRecordLine()); + try { + w01OutFil.write(w01.toRecordLine()); + w01OutFil.newLine(); + } catch (IOException e) { + throw new UncheckedIOException(e); + } // ADD 1 TO CUN-W01OUT. cunW01Out++; // *** フッタ出力(BEFORE ADVANCING PAGE) // WRITE W01OUTREC FROM FOOTER-LINE BEFORE ADVANCING PAGE. - w01OutFil.println(buildFooterLine()); + try { + w01OutFil.write(buildFooterLine()); + w01OutFil.newLine(); + } catch (IOException e) { + throw new UncheckedIOException(e); + } // *** 次レコード読込(1100R01INNSOR) readR01Para(); @@ -378,12 +388,9 @@ public class Kyu08PriMain { /** OPEN INPUT R01INNFIL / OUTPUT W01OUTFIL W02OUTFIL. */ private void openFiles() { try { - r01InnFil = new BufferedReader( - new InputStreamReader(new FileInputStream(R01INN_FILE), StandardCharsets.UTF_8)); - w01OutFil = new PrintWriter( - new OutputStreamWriter(new FileOutputStream(W01OUT_FILE), StandardCharsets.UTF_8)); - w02OutFil = new PrintWriter( - new OutputStreamWriter(new FileOutputStream(W02OUT_FILE), StandardCharsets.UTF_8)); + r01InnFil = FileIo.openReader(R01INN_FILE); + w01OutFil = FileIo.openWriter(W01OUT_FILE); + w02OutFil = FileIo.openWriter(W02OUT_FILE); } catch (IOException e) { throw new UncheckedIOException(e); // OPEN失敗 ≈ ABEND } @@ -403,8 +410,8 @@ public class Kyu08PriMain { try { if (handle instanceof BufferedReader) { ((BufferedReader) handle).close(); - } else if (handle instanceof PrintWriter) { - ((PrintWriter) handle).close(); + } else if (handle instanceof BufferedWriter) { + ((BufferedWriter) handle).close(); } } catch (IOException e) { // CLOSE異常は無視(原程序もFILE STATUS未管理) diff --git a/JavaSrc/src/Kyu09MrgMain.java b/JavaSrc/src/Kyu09MrgMain.java index 44061b7..1adf8b6 100644 --- a/JavaSrc/src/Kyu09MrgMain.java +++ b/JavaSrc/src/Kyu09MrgMain.java @@ -1,12 +1,7 @@ import java.io.BufferedReader; -import java.io.FileInputStream; -import java.io.FileOutputStream; +import java.io.BufferedWriter; import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.io.PrintWriter; import java.io.UncheckedIOException; -import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; @@ -74,7 +69,7 @@ public class Kyu09MrgMain { private static final String CST_PAY_TYPE_TOTAL = "T"; /** 88 WRK-MERGE-EOF-Y の HIGH-VALUES(PIC X(008) の最大値)相当。 */ - private static final String HIGH_VALUES_EMP_ID = "\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF"; + private static final String HIGH_VALUES_EMP_ID = "\uFFFF\uFFFF\uFFFF\uFFFF\uFFFF\uFFFF\uFFFF\uFFFF"; // ==================== ファイル定義(SELECT ASSIGN 相当) ==================== @@ -138,8 +133,8 @@ public class Kyu09MrgMain { // ==================== ファイルハンドル(OPEN/CLOSE 相当) ==================== - private PrintWriter w01OutFil; - private PrintWriter w02OutFil; + private BufferedWriter w01OutFil; + private BufferedWriter w02OutFil; // ==================== PROCEDURE DIVISION ==================== @@ -211,8 +206,7 @@ public class Kyu09MrgMain { /** 入力ファイル読込(OPEN INPUT / READ AT END 相当)。 */ private List readFile(final String path) { final List list = new ArrayList<>(); - try (BufferedReader br = new BufferedReader( - new InputStreamReader(new FileInputStream(path), StandardCharsets.UTF_8))) { + try (BufferedReader br = FileIo.openReader(path)) { String line; while ((line = br.readLine()) != null) { if (line.isEmpty()) { @@ -349,7 +343,12 @@ public class Kyu09MrgMain { // MOVE WRK-ACCOUNT-NO TO W01ACCOUNT-NO. w01.setAccountNo(wrkAccountNo); // WRITE W01OUTREC. / ADD 1 TO CUN-W01OUT. - w01OutFil.println(w01.toRecordLine()); + try { + w01OutFil.write(w01.toRecordLine()); + w01OutFil.newLine(); + } catch (IOException e) { + throw new UncheckedIOException(e); + } cunW01Out++; } @@ -412,7 +411,12 @@ public class Kyu09MrgMain { w02.reset(); w02.setErrDetail("DIRECT ENTRY"); // WRITE W02OUTREC. / ADD 1 TO CUN-W02OUT. - w02OutFil.println(w02.toRecordLine()); + try { + w02OutFil.write(w02.toRecordLine()); + w02OutFil.newLine(); + } catch (IOException e) { + throw new UncheckedIOException(e); + } cunW02Out++; } @@ -421,10 +425,8 @@ public class Kyu09MrgMain { /** OPEN OUTPUT W01OUTFIL W02OUTFIL. */ private void openFiles() { try { - w01OutFil = new PrintWriter( - new OutputStreamWriter(new FileOutputStream(W01OUT_FILE), StandardCharsets.UTF_8)); - w02OutFil = new PrintWriter( - new OutputStreamWriter(new FileOutputStream(W02OUT_FILE), StandardCharsets.UTF_8)); + w01OutFil = FileIo.openWriter(W01OUT_FILE); + w02OutFil = FileIo.openWriter(W02OUT_FILE); } catch (IOException e) { throw new UncheckedIOException(e); // OPEN 失敗 ≈ ABEND } @@ -440,8 +442,8 @@ public class Kyu09MrgMain { private static void closeQuiet(final Object handle) { try { - if (handle instanceof PrintWriter) { - ((PrintWriter) handle).close(); + if (handle instanceof BufferedWriter) { + ((BufferedWriter) handle).close(); } } catch (Exception e) { // CLOSE 異常は無視(原程序も FILE STATUS 未管理) diff --git a/JavaSrc/src/Zan01ChkMain.java b/JavaSrc/src/Zan01ChkMain.java index 4b3ced8..1ee32d7 100644 --- a/JavaSrc/src/Zan01ChkMain.java +++ b/JavaSrc/src/Zan01ChkMain.java @@ -175,7 +175,7 @@ public class Zan01ChkMain { // 绀惧摗鐣彿銉併偋銉冦偗 c01.reset(); c01.setC01ChkTyp("EMPID"); - c01.setC01ChkDat(pad8(csvEmpId)); + c01.setC01ChkDat(ConvUtil.padRight(csvEmpId, 8)); Sub04ChkSub.execute(c01); if (c01.getC01ChkRrc() != 0) { writeW03("01", "EMP-ID ERROR:" + csvEmpId); @@ -184,7 +184,7 @@ public class Zan01ChkMain { // 鏃ヤ粯銉併偋銉冦偗 c01.reset(); c01.setC01ChkTyp("DATE"); - c01.setC01ChkDat(pad8(csvApplDate)); + c01.setC01ChkDat(ConvUtil.padRight(csvApplDate, 8)); Sub04ChkSub.execute(c01); if (c01.getC01ChkRrc() != 0) { writeW03("01", "DATE ERROR:" + csvEmpId); @@ -341,9 +341,4 @@ public class Zan01ChkMain { e01.setE01AbdCod(CNS_ABD999); Sub03EndSub.execute(e01); } - - /** EMPID/鏃ヤ粯绛夈伄銉併偋銉冦偗鐢ㄣ伀8妗佸彸瑭般倎(宸﹀煁銈佹枃瀛楀垪闀峰悎銈忋仜). */ - private String pad8(final String s) { - return ConvUtil.padRight(s, 8); - } } diff --git a/JavaSrc/src/Zan02ChkMain.java b/JavaSrc/src/Zan02ChkMain.java index 5b317a9..0fb1b2e 100644 --- a/JavaSrc/src/Zan02ChkMain.java +++ b/JavaSrc/src/Zan02ChkMain.java @@ -14,10 +14,13 @@ import java.nio.charset.StandardCharsets; /** * ============================================================ - * 銆怌OBOL鈫扟ava銆慞ROGRAM-ID. ZAN02CHK 鈫?绫?Zan02ChkMain + * 【COBOL→Java】PROGRAM-ID. ZAN02CHK → クラス Zan02ChkMain * ============================================================ - * 鏅傞枔甯噸瑜囥儊銈с儍銈? OVT-VSORT(R01) 銇悓涓€绀惧摗銉诲悓涓€鏃ヤ粯鍐呫仹 - * 鍓嶃儸銈炽兗銉夌祩浜嗘檪鍒?> 鐝鹃枊濮嬫檪鍒?銇倝 ERROR-LOG(W02) 銇嚭鍔涖€? * 銇濄倢浠ュ銇?OVT-NODUP(W01) 銇稿嚭鍔涖€? * 鈥昏ō瑷堟浉婧栨嫚銆侰OBOL 銇ㄦ暣鍚堛€? */ + * 時間帯重複チェック: OVT-VSORT(R01) の同一社員かつ同一日付内で + * 前レコード終了時刻 > 現レコード開始時刻 の場合 ERROR-LOG(W02) に出力。 + * それ以外は OVT-NODUP(W01) に出力。 + * ※設計書準拠。COBOL と整合。 + */ public class Zan02ChkMain { private static final String PRGIDX = "ZAN02CHK"; @@ -87,7 +90,7 @@ public class Zan02ChkMain { throw new RuntimeException("FILE OPEN ERROR", e); } readR01(); - // 1浠剁洰: W01鍑哄姏 + 鍓嶃儸銈炽兗銉夊垵鏈熷寲 + // 1件目: W01出力 + 前レコード初期化 if (!"1".equals(wrkR01Eof)) { r01Rec.fromRecordLine(r01Line); prevRec.fromRecordLine(r01Line); diff --git a/JavaSrc/src/Zan03ChkMain.java b/JavaSrc/src/Zan03ChkMain.java index 7770edc..fc77c2e 100644 --- a/JavaSrc/src/Zan03ChkMain.java +++ b/JavaSrc/src/Zan03ChkMain.java @@ -1,6 +1,7 @@ import dto.Zan01Rec; import dto.Zan05Rec; import dto.ZanmsgacPar; +import util.ConvUtil; import java.io.BufferedReader; import java.io.BufferedWriter; @@ -13,9 +14,14 @@ import java.util.List; /** * ============================================================ - * 銆怌OBOL鈫扟ava銆慞ROGRAM-ID. ZAN03CHK 鈫?绫?Zan03ChkMain + * 【COBOL→Java】PROGRAM-ID. ZAN03CHK → クラス Zan03ChkMain * ============================================================ - * 鎵撳埢鏅傞枔鐓у悎: OVT-NODUP(R01) 銇?PUNCH(R02) 銈掋偔銉?绀惧摗+鐢宠珛鏃?銇х獊鍚堛€? * 涓€鑷淬仐鏅傞枔甯亴鍑哄嫟銆滈€€鍕ょ瘎鍥插唴 鈫?OVT-TYPE浠樺姞銇椼仸 OVT-CHECKED(W01)銆? * 绡勫洸澶栥伨銇熴伅涓嶄竴鑷?鈫?ERROR-LOG(W02) 銈儐銈淬儶03銆? * 浼戞棩鍒ゅ畾銇?R03(浼戞棩銉曘偂銈ゃ儷) 銇ц銇嗐€? * 鈥籞AN03 銇?SUB01DAT 鏈娇鐢?FUNCTION CURRENT-DATE)銆傝ō瑷堟浉婧栨嫚銆? */ + * 打刻時間照合: OVT-NODUP(R01) と PUNCH(R02) を社員番号+申請日で突合。 + * 一致し申請時間帯が出勤〜退勤の範囲内 → OVT-TYPE付加で OVT-CHECKED(W01)。 + * 範囲外、または不一致 → ERROR-LOG(W02) に出力。 + * 休日判定は R03(休日テーブル) で行う。 + * ※ZAN03 は SUB01DAT 未使用(FUNCTION CURRENT-DATE)。設計書準拠。 + */ public class Zan03ChkMain { private static final String PRGIDX = "ZAN03CHK"; @@ -28,7 +34,7 @@ public class Zan03ChkMain { private static final int CNS_ERR_CAT03 = 3; private static final String OVT_W = "W"; private static final String OVT_H = "H"; - private static final String HIGH = "zzzzzzzzzzzzzzzz"; // 16脳'z' = HIGH-VALUE + private static final String HIGH = "\uFFFF\uFFFF\uFFFF\uFFFF\uFFFF\uFFFF\uFFFF\uFFFF\uFFFF\uFFFF\uFFFF\uFFFF\uFFFF\uFFFF\uFFFF\uFFFF"; // 16×'\uFFFF' = HIGH-VALUE private static final String R01_PATH = "data/ZAN03R01.txt"; private static final String R02_PATH = "data/ZAN03R02.txt"; @@ -56,13 +62,13 @@ public class Zan03ChkMain { private Zan01Rec r01Rec = new Zan01Rec(); - // R02 銈ゃ兂銉┿偆銉抽爡鐩? // R02 インライン項目 + // R02 インライン項目 private String r02EmpId = ""; private String r02Date = ""; private String r02TimeIn = ""; private String r02TimeOut = ""; - // 浼戞棩銉嗐兗銉栥儷 + // 休日テーブル private final List holidayTable = new ArrayList<>(); private BufferedReader r01In; @@ -107,7 +113,7 @@ public class Zan03ChkMain { } catch (IOException e) { throw new RuntimeException("FILE OPEN ERROR", e); } - // 浼戞棩銉曘偂銈ゃ儷瑾炯 + // 休日ファイル読込 holidayLoad(); readR01(); readR02(); @@ -118,8 +124,8 @@ public class Zan03ChkMain { String line; while ((line = r03In.readLine()) != null) { cunR03Inn++; - String date = line.length() >= 8 ? line.substring(0, 8).trim() : ""; - String flg = line.length() >= 9 ? line.substring(8, 9) : " "; + String date = ConvUtil.safeSub(line, 0, 8).trim(); + String flg = ConvUtil.safeSub(line, 8, 9); holidayTable.add(new String[]{date, flg}); } wrkR03Eof = "1"; @@ -136,7 +142,7 @@ public class Zan03ChkMain { } else { r01Line = line; r01Rec.fromRecordLine(line); - wrkR01Key = pad8(r01Rec.getEmpId()) + pad8(r01Rec.getApplDate()); + wrkR01Key = ConvUtil.padRight(r01Rec.getEmpId(), 8) + ConvUtil.padRight(r01Rec.getApplDate(), 8); cunR01Inn++; } } catch (IOException e) { @@ -152,11 +158,11 @@ public class Zan03ChkMain { wrkR02Key = HIGH; } else { r02Line = line; - r02EmpId = line.length() >= 8 ? line.substring(0, 8).trim() : ""; - r02Date = line.length() >= 16 ? line.substring(8, 16).trim() : ""; - r02TimeIn = line.length() >= 20 ? line.substring(16, 20).trim() : ""; - r02TimeOut = line.length() >= 24 ? line.substring(20, 24).trim() : ""; - wrkR02Key = pad8(r02EmpId) + pad8(r02Date); + r02EmpId = ConvUtil.safeSub(line, 0, 8).trim(); + r02Date = ConvUtil.safeSub(line, 8, 16).trim(); + r02TimeIn = ConvUtil.safeSub(line, 16, 20).trim(); + r02TimeOut = ConvUtil.safeSub(line, 20, 24).trim(); + wrkR02Key = ConvUtil.padRight(r02EmpId, 8) + ConvUtil.padRight(r02Date, 8); cunR02Inn++; } } catch (IOException e) { @@ -191,10 +197,10 @@ public class Zan03ChkMain { } private void matchProc() { - int r01Start = parseInt(r01Rec.getStartTime(), 0); - int r01End = parseInt(r01Rec.getEndTime(), 0); - int punchIn = parseInt(r02TimeIn, 0); - int punchOut = parseInt(r02TimeOut, 0); + int r01Start = ConvUtil.parseIntSafe(r01Rec.getStartTime(), 0); + int r01End = ConvUtil.parseIntSafe(r01Rec.getEndTime(), 0); + int punchIn = ConvUtil.parseIntSafe(r02TimeIn, 0); + int punchOut = ConvUtil.parseIntSafe(r02TimeOut, 0); if (r01Start >= punchIn && r01End <= punchOut) { setOvtProc(); try { @@ -305,33 +311,4 @@ public class Zan03ChkMain { m00.setM00Umkdats2205(PRGIDX); Sub02MsgSub.execute(m00); } - - private String pad8(final String s) { - if (s == null) { - return " "; - } - if (s.length() >= 8) { - return s.substring(0, 8); - } - StringBuilder sb = new StringBuilder(s); - while (sb.length() < 8) { - sb.append(' '); - } - return sb.toString(); - } - - private int parseInt(final String s, final int def) { - if (s == null) { - return def; - } - String t = s.trim(); - if (t.isEmpty()) { - return def; - } - try { - return Integer.parseInt(t); - } catch (NumberFormatException e) { - return def; - } - } } diff --git a/JavaSrc/src/Zan04MatMain.java b/JavaSrc/src/Zan04MatMain.java index f5a562a..250f38a 100644 --- a/JavaSrc/src/Zan04MatMain.java +++ b/JavaSrc/src/Zan04MatMain.java @@ -5,6 +5,7 @@ import dto.Zan05Rec; import dto.ZandatacPar; import dto.ZanendacPar; import dto.ZanmsgacPar; +import util.ConvUtil; import java.io.BufferedReader; import java.io.BufferedWriter; @@ -15,9 +16,15 @@ import java.nio.charset.StandardCharsets; /** * ============================================================ - * 銆怌OBOL鈫扟ava銆慞ROGRAM-ID. ZAN04MAT 鈫?绫?Zan04MatMain + * 【COBOL→Java】PROGRAM-ID. ZAN04MAT → クラス Zan04MatMain * ============================================================ - * 鍙栨秷銉炪儍銉併兂銈? OVT-SORTED(R01) 銇?OVT-CSORT(R02) 銈掔敵璜嬬暘鍙?APPL-ID)銇? * 1:1 銉炪儍銉併兂銈般仐銆佺祼鏋溿倰鎸倞鍒嗐亼銈嬨€? * 涓€鑷? 鈫?鍙栨秷娓堛伩鐢宠珛銈?ERROR-LOG(W03) 銇嚭鍔涳紙鐩f熁瑷艰贰锛? * R01銇伩 鈫?鏈夊姽鐢宠珛銈?OVT-MATCHED(W01) 銇嚭鍔? * R02銇伩 鈫?鍙栨秷鐢宠珛銈?OVT-DBCLEAN(W02) 銇嚭鍔? * 鈥昏ō瑷堟浉婧栨嫚銆侰OBOL 銇ㄦ暣鍚堛€傘偔銉笺伅 APPL-ID (8B)銆? */ + * 取消マッチング: OVT-SORTED(R01) と OVT-CSORT(R02) を申請番号(APPL-ID)で + * 1:1 マッチングし、結果を振り分ける。 + * 一致(取消済) → 取消済み申請を監査証跡として ERROR-LOG(W03) に出力。 + * R01のみ → 有効申請 OVT-MATCHED(W01) に出力。 + * R02のみ → 取消申請 OVT-DBCLEAN(W02) に出力(DB削除用)。 + * ※設計書準拠。COBOL と整合。キーは APPL-ID (8B)。 + */ public class Zan04MatMain { private static final String PRGIDX = "ZAN04MAT"; @@ -31,7 +38,7 @@ public class Zan04MatMain { private static final int CNS_ABD999 = 999; private static final int CNS_ERR_CAT04 = 4; private static final int CNS_PROC_SEQ01 = 1; - private static final String HIGH = "zzzzzzzz"; // 8脳'z' = HIGH-VALUE + private static final String HIGH = "\uFFFF\uFFFF\uFFFF\uFFFF\uFFFF\uFFFF\uFFFF\uFFFF"; // 8×'\uFFFF' = HIGH-VALUE private static final String R01_PATH = "data/ZAN04R01.txt"; private static final String R02_PATH = "data/ZAN04R02.txt"; @@ -114,7 +121,7 @@ public class Zan04MatMain { r01Key = HIGH; } else { r01Rec.fromRecordLine(line); - r01Key = pad8(r01Rec.getApplId()); + r01Key = ConvUtil.padRight(r01Rec.getApplId(), 8); cunR01Inn++; } } catch (IOException e) { @@ -129,7 +136,7 @@ public class Zan04MatMain { r02Key = HIGH; } else { r02Rec.fromRecordLine(line); - r02Key = pad8(r02Rec.getApplId()); + r02Key = ConvUtil.padRight(r02Rec.getApplId(), 8); cunR02Inn++; } } catch (IOException e) { @@ -260,18 +267,4 @@ public class Zan04MatMain { e01.setE01AbdCod(CNS_ABD999); Sub03EndSub.execute(e01); } - - private String pad8(final String s) { - if (s == null) { - return " "; - } - if (s.length() >= 8) { - return s.substring(0, 8); - } - StringBuilder sb = new StringBuilder(s); - while (sb.length() < 8) { - sb.append(' '); - } - return sb.toString(); - } } diff --git a/JavaSrc/src/Zan05CalMain.java b/JavaSrc/src/Zan05CalMain.java index b6baf9b..40a3cc5 100644 --- a/JavaSrc/src/Zan05CalMain.java +++ b/JavaSrc/src/Zan05CalMain.java @@ -4,6 +4,7 @@ import dto.ZandatacPar; import dto.ZanendacPar; import dto.ZanmsgacPar; import dto.ZantimacPar; +import util.ConvUtil; import java.io.BufferedReader; import java.io.BufferedWriter; @@ -14,9 +15,13 @@ import java.nio.charset.StandardCharsets; /** * ============================================================ - * 銆怌OBOL鈫扟ava銆慞ROGRAM-ID. ZAN05CAL 鈫?绫?Zan05CalMain + * 【COBOL→Java】PROGRAM-ID. ZAN05CAL → クラス Zan05CalMain * ============================================================ - * 娈嬫キ鏅傞枔闆嗚▓: OVT-SORTED2(R01, APPL-ID+PROC-SEQ 鏄囬爢) 銈掋偔銉笺儢銉偆銈泦瑷堛仐銆? * 鍚屼竴 APPL-ID 鍐呫伄鍏ㄦ槑绱般伄鍔犵彮鏅傞枔銈掔绠椼仐銇?OVT-SUMMARY(W01) 銇?1 銉偝銉笺儔鍑哄姏銆? * 绌嶇畻鍒嗏啋鏅傚埢涓搞倎銇?SUB05TIM(mode=2: 0.1h 鍗樹綅鍒囨崹) 銈掍娇鐢ㄣ€? * 鈥昏ō瑷堟浉婧栨嫚銆侰OBOL 銇ㄦ暣鍚堛€? */ + * 残業時間集約: OVT-SORTED2(R01, APPL-ID+PROC-SEQ 昇順) をキーブレイク集約し、 + * 同一 APPL-ID 内の全明細の残業時間を積算し、OVT-SUMMARY(W01) へ 1 レコード出力。 + * 積算分類時刻計算は SUB05TIM(mode=2: 0.1h 単位切捨) を使用。 + * ※設計書準拠。COBOL と整合。 + */ public class Zan05CalMain { private static final String PRGIDX = "ZAN05CAL"; @@ -29,7 +34,7 @@ public class Zan05CalMain { private static final int CNS_KN0002 = 2; private static final int CNS_TIMMODE02 = 2; private static final int CNS_ABD999 = 999; - private static final String HIGH = "zzzzzzzz"; // 8脳'z' = HIGH-VALUE + private static final String HIGH = "\uFFFF\uFFFF\uFFFF\uFFFF\uFFFF\uFFFF\uFFFF\uFFFF"; // 8×'\uFFFF' = HIGH-VALUE private static final String R01_PATH = "data/ZAN05R01.txt"; private static final String W01_PATH = "data/ZAN05W01.txt"; @@ -133,7 +138,7 @@ public class Zan05CalMain { r01Key = HIGH; } else { r01Rec.fromRecordLine(line); - r01Key = pad8(r01Rec.getApplId()); + r01Key = ConvUtil.padRight(r01Rec.getApplId(), 8); cunR01Inn++; } } catch (IOException e) { @@ -142,8 +147,8 @@ public class Zan05CalMain { } private void accumProc() { - int start = parseInt(r01Rec.getStartTime(), 0); - int end = parseInt(r01Rec.getEndTime(), 0); + int start = ConvUtil.parseIntSafe(r01Rec.getStartTime(), 0); + int end = ConvUtil.parseIntSafe(r01Rec.getEndTime(), 0); int sh = start / 100; int sm = start % 100; int eh = end / 100; @@ -243,33 +248,4 @@ public class Zan05CalMain { e01.setE01AbdCod(CNS_ABD999); Sub03EndSub.execute(e01); } - - private String pad8(final String s) { - if (s == null) { - return " "; - } - if (s.length() >= 8) { - return s.substring(0, 8); - } - StringBuilder sb = new StringBuilder(s); - while (sb.length() < 8) { - sb.append(' '); - } - return sb.toString(); - } - - private int parseInt(final String s, final int def) { - if (s == null) { - return def; - } - String t = s.trim(); - if (t.isEmpty()) { - return def; - } - try { - return Integer.parseInt(t); - } catch (NumberFormatException e) { - return def; - } - } } diff --git a/JavaSrc/src/Zan06UpdMain.java b/JavaSrc/src/Zan06UpdMain.java index d4f213d..888d8b3 100644 --- a/JavaSrc/src/Zan06UpdMain.java +++ b/JavaSrc/src/Zan06UpdMain.java @@ -22,10 +22,14 @@ import java.sql.SQLException; /** * ============================================================ - * 銆怌OBOL鈫扟ava銆慞ROGRAM-ID. ZAN06UPD 鈫?绫?Zan06UpdMain + * 【COBOL→Java】PROGRAM-ID. ZAN06UPD → クラス Zan06UpdMain * ============================================================ - * 娈嬫キ绲辫▓DB鏇存柊: OVT-SUMMARY(R01) 銈?OVT_APPLICATIONS 銇?INSERT(閲嶈鏅?UPDATE) - * 銇椼€丱VT-MONTHLY 銇湀娆¢泦瑷堛倰鍙嶆槧銆侽VT-DBCLEAN(R02) 銇┎褰撶敵璜嬨倰鍙栨秷鐘舵厠銇? * 鏇存柊銇椼€丱VT-MONTHLY 銇嬨倝鍔犵彮鏅傞枔銈掓笡绠椼仚銈嬨€? * 鎺ョ稓鍏? data/OVERTIME.DB (SQLite)銆傘儐銉笺儢銉笉鍦ㄦ檪銇?CREATE TABLE IF NOT EXISTS 銇ц嚜鍕曟绡夈€? * 鈥昏ō瑷堟浉婧栨嫚銆侰OBOL 銇ㄦ暣鍚堛€? */ + * 残業統計DB更新: OVT-SUMMARY(R01) を OVT_APPLICATIONS へ INSERT(重複時 UPDATE) + * し、OVT-MONTHLY に月次集計を反映。OVT-DBCLEAN(R02) は該当申請を取消状態へ + * 更新し、OVT-MONTHLY から残業時間を減算する。 + * 接続先: data/OVERTIME.DB (SQLite)。テーブル不在時は CREATE TABLE IF NOT EXISTS で自動作成。 + * ※設計書準拠。COBOL と整合。 + */ public class Zan06UpdMain { private static final String PRGIDX = "ZAN06UPD"; diff --git a/JavaSrc/src/dto/Kin01Rec.java b/JavaSrc/src/dto/Kin01Rec.java index bae4c7a..a90eff8 100644 --- a/JavaSrc/src/dto/Kin01Rec.java +++ b/JavaSrc/src/dto/Kin01Rec.java @@ -161,17 +161,14 @@ public class Kin01Rec { public void fromRecordLine(final String line) { reset(); String s = (line == null) ? "" : line; - while (s.length() < 80) { - s = s + " "; - } - applId = Integer.parseInt(s.substring(0, 9).trim()); - empId = s.substring(9, 17); - leaveType = s.substring(17, 19); - startDate = Integer.parseInt(s.substring(19, 27).trim()); - startTime = Integer.parseInt(s.substring(27, 31).trim()); - endDate = Integer.parseInt(s.substring(31, 39).trim()); - endTime = Integer.parseInt(s.substring(39, 43).trim()); - status = s.substring(43, 44); - filler = s.substring(44, 80); + applId = Integer.parseInt(ConvUtil.safeSub(s, 0, 9).trim()); + empId = ConvUtil.safeSub(s, 9, 17); + leaveType = ConvUtil.safeSub(s, 17, 19); + startDate = Integer.parseInt(ConvUtil.safeSub(s, 19, 27).trim()); + startTime = Integer.parseInt(ConvUtil.safeSub(s, 27, 31).trim()); + endDate = Integer.parseInt(ConvUtil.safeSub(s, 31, 39).trim()); + endTime = Integer.parseInt(ConvUtil.safeSub(s, 39, 43).trim()); + status = ConvUtil.safeSub(s, 43, 44); + filler = ConvUtil.safeSub(s, 44, 80); } } diff --git a/JavaSrc/src/dto/Kin02Rec.java b/JavaSrc/src/dto/Kin02Rec.java index 4a2c492..b30f8b7 100644 --- a/JavaSrc/src/dto/Kin02Rec.java +++ b/JavaSrc/src/dto/Kin02Rec.java @@ -67,16 +67,13 @@ public class Kin02Rec { */ public void fromRecordLine(final String line) { String s = (line == null) ? "" : line; - if (s.length() < 80) { - s = ConvUtil.padRight(s, 80); - } - empId = s.substring(0, 8); // EMP-ID X(008) [1..8] - date = Integer.parseInt(s.substring(8, 16)); // DATE 9(008) [9..16] - leaveType = s.substring(16, 18); // LEAVE-TYPE X(002) [17..18] - startTime = Integer.parseInt(s.substring(18, 22)); // START-TIME 9(004) [19..22] - endTime = Integer.parseInt(s.substring(22, 26)); // END-TIME 9(004) [23..26] - applId = Integer.parseInt(s.substring(26, 35)); // APPL-ID 9(009) [27..35] - filler = s.substring(35, 80); // FILLER X(045) [36..80] + empId = ConvUtil.safeSub(s, 0, 8); // EMP-ID X(008) [1..8] + date = Integer.parseInt(ConvUtil.safeSub(s, 8, 16)); // DATE 9(008) [9..16] + leaveType = ConvUtil.safeSub(s, 16, 18); // LEAVE-TYPE X(002) [17..18] + startTime = Integer.parseInt(ConvUtil.safeSub(s, 18, 22)); // START-TIME 9(004) [19..22] + endTime = Integer.parseInt(ConvUtil.safeSub(s, 22, 26)); // END-TIME 9(004) [23..26] + applId = Integer.parseInt(ConvUtil.safeSub(s, 26, 35)); // APPL-ID 9(009) [27..35] + filler = ConvUtil.safeSub(s, 35, 80); // FILLER X(045) [36..80] } public String getEmpId() { diff --git a/JavaSrc/src/dto/Kin04Rec.java b/JavaSrc/src/dto/Kin04Rec.java index 15bae37..22374c4 100644 --- a/JavaSrc/src/dto/Kin04Rec.java +++ b/JavaSrc/src/dto/Kin04Rec.java @@ -68,15 +68,12 @@ public class Kin04Rec { */ public void fromRecordLine(final String line) { String s = (line == null) ? "" : line; - if (s.length() < 80) { - s = ConvUtil.padRight(s, 80); - } - empId = s.substring(0, 8); // EMP-ID X(008) [1..8] - workDate = s.substring(8, 16); // WORK-DATE 9(008) [9..16] - strTime = s.substring(16, 20); // STR-TIME 9(004) [17..20] - endTime = s.substring(20, 24); // END-TIME 9(004) [21..24] - deptId = s.substring(24, 28); // DEPT-ID X(004) [25..28] - terminal = s.substring(28, 34); // TERMINAL X(006) [29..34] + empId = ConvUtil.safeSub(s, 0, 8); // EMP-ID X(008) [1..8] + workDate = ConvUtil.safeSub(s, 8, 16); // WORK-DATE 9(008) [9..16] + strTime = ConvUtil.safeSub(s, 16, 20); // STR-TIME 9(004) [17..20] + endTime = ConvUtil.safeSub(s, 20, 24); // END-TIME 9(004) [21..24] + deptId = ConvUtil.safeSub(s, 24, 28); // DEPT-ID X(004) [25..28] + terminal = ConvUtil.safeSub(s, 28, 34); // TERMINAL X(006) [29..34] } public String getEmpId() { diff --git a/JavaSrc/src/dto/Kyu04Rec.java b/JavaSrc/src/dto/Kyu04Rec.java index 77e9d6d..222cdfb 100644 --- a/JavaSrc/src/dto/Kyu04Rec.java +++ b/JavaSrc/src/dto/Kyu04Rec.java @@ -119,29 +119,21 @@ public class Kyu04Rec { public long getR01PayAmount() { return payAmount; } // ---------- 固定長レコード解析 ---------- - private static String sub(final String s, final int a, final int b) { - String x = (s == null) ? "" : s; - if (x.length() < b) { - x = ConvUtil.padRight(x, b); - } - return x.substring(a, b); - } - /** 200B 固定長 SALARY-NET レコードを解析(COPY KYU04REC 05層順)。 */ public void fromRecordLine(final String line) { - empId = sub(line, 0, 8); - recType = sub(line, 8, 9); - empName = sub(line, 9, 49); - deptCode = sub(line, 49, 51); - regionCode = sub(line, 51, 53); - categoryCode = sub(line, 53, 56); - grossPayment = ConvUtil.parseIntSafe(sub(line, 56, 65), 0); - incomeTax = ConvUtil.parseIntSafe(sub(line, 65, 74), 0); - insurance = ConvUtil.parseIntSafe(sub(line, 74, 83), 0); - residentTax = ConvUtil.parseIntSafe(sub(line, 83, 92), 0); - netPayment = ConvUtil.parseIntSafe(sub(line, 92, 101), 0); - taxableIncome = ConvUtil.parseIntSafe(sub(line, 101, 110), 0); - payAmount = ConvUtil.parseIntSafe(sub(line, 110, 119), 0); + empId = ConvUtil.safeSub(line, 0, 8); + recType = ConvUtil.safeSub(line, 8, 9); + empName = ConvUtil.safeSub(line, 9, 49); + deptCode = ConvUtil.safeSub(line, 49, 51); + regionCode = ConvUtil.safeSub(line, 51, 53); + categoryCode = ConvUtil.safeSub(line, 53, 56); + grossPayment = ConvUtil.parseIntSafe(ConvUtil.safeSub(line, 56, 65), 0); + incomeTax = ConvUtil.parseIntSafe(ConvUtil.safeSub(line, 65, 74), 0); + insurance = ConvUtil.parseIntSafe(ConvUtil.safeSub(line, 74, 83), 0); + residentTax = ConvUtil.parseIntSafe(ConvUtil.safeSub(line, 83, 92), 0); + netPayment = ConvUtil.parseIntSafe(ConvUtil.safeSub(line, 92, 101), 0); + taxableIncome = ConvUtil.parseIntSafe(ConvUtil.safeSub(line, 101, 110), 0); + payAmount = ConvUtil.parseIntSafe(ConvUtil.safeSub(line, 110, 119), 0); } /** parseRecord は fromRecordLine と等価(PGM間の命名差を吸収)。 */ diff --git a/JavaSrc/src/util/ConvUtil.java b/JavaSrc/src/util/ConvUtil.java index dfb05db..e50407c 100644 --- a/JavaSrc/src/util/ConvUtil.java +++ b/JavaSrc/src/util/ConvUtil.java @@ -2,6 +2,7 @@ package util; import java.math.BigDecimal; import java.math.RoundingMode; +import java.nio.charset.StandardCharsets; /** * ============================================================ @@ -28,14 +29,30 @@ public final class ConvUtil { */ public static String padRight(final String val, final int len) { String s = (val == null) ? "" : val; - if (s.length() >= len) { - return s.substring(0, len); + byte[] b = s.getBytes(StandardCharsets.UTF_8); + if (b.length > len) { + // 干净 UTF-8 截断:落到 len 字节,若末字节是多字节字符的续字节则回退到 + // 完整字符边界,余下空间以空格字节补足 → 重编码后总字节数恒 = len。 + int cut = len; + while (cut > 0 && (b[cut] & 0xC0) == 0x80) { + cut--; + } + byte[] out = new byte[len]; + System.arraycopy(b, 0, out, 0, cut); + for (int i = cut; i < len; i++) { + out[i] = ' '; + } + return new String(out, StandardCharsets.UTF_8); } - StringBuilder sb = new StringBuilder(s); - while (sb.length() < len) { - sb.append(' '); + if (b.length == len) { + return s; } - return sb.toString(); + byte[] out = new byte[len]; + System.arraycopy(b, 0, out, 0, b.length); + for (int i = b.length; i < len; i++) { + out[i] = ' '; + } + return new String(out, StandardCharsets.UTF_8); } /** @@ -118,12 +135,13 @@ public final class ConvUtil { if (line == null) { return ""; } + byte[] b = line.getBytes(StandardCharsets.UTF_8); int s = Math.max(0, start); - int e = Math.min(line.length(), end); + int e = Math.min(b.length, end); if (s >= e) { return ""; } - return line.substring(s, e); + return new String(b, s, e - s, StandardCharsets.UTF_8); } /**