Skip to content

Commit bc47bc0

Browse files
feat: implement COB_FILE_SEQ_BUFFER_SIZE
1 parent 0812eac commit bc47bc0

5 files changed

Lines changed: 268 additions & 114 deletions

File tree

doc/environment_variables.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,13 +446,22 @@ $ OC_EXTEND_CREATES=yes java ocextcreates
446446
FILE STATUS: 00
447447
```
448448

449-
#### COB_FILE_SEQ_WRITE_BUFFER_SIZE
449+
#### COB_FILE_SEQ_BUFFER_SIZE
450450

451-
Specifies the write buffer size for sequential files.
451+
Specifies the buffer size for sequential file I/O (both read and write).
452+
453+
- **Value**: Integer >= 0 (default: 10). The value represents a multiplier for the record size.
454+
- **Example**: `COB_FILE_SEQ_BUFFER_SIZE=100`
455+
- **Purpose**: Adjusts read and write performance for SEQUENTIAL and LINE SEQUENTIAL files. The actual buffer size is calculated as `COB_FILE_SEQ_BUFFER_SIZE * record_max` bytes. Setting to 0 disables buffering.
456+
457+
#### COB_FILE_SEQ_WRITE_BUFFER_SIZE (Deprecated)
458+
459+
Deprecated. Use `COB_FILE_SEQ_BUFFER_SIZE` instead.
460+
461+
This environment variable is retained for backward compatibility. When `COB_FILE_SEQ_BUFFER_SIZE` is not set, this variable is used as a fallback with the same effect.
452462

453463
- **Value**: Integer >= 0 (default: 10)
454464
- **Example**: `COB_FILE_SEQ_WRITE_BUFFER_SIZE=100`
455-
- **Purpose**: Adjusts write performance.
456465

457466
#### COB_IO_ASSUME_REWRITE
458467

doc/environment_variables_JP.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,13 +446,22 @@ $ OC_EXTEND_CREATES=yes java ocextcreates
446446
FILE STATUS: 00
447447
```
448448

449-
#### COB_FILE_SEQ_WRITE_BUFFER_SIZE
449+
#### COB_FILE_SEQ_BUFFER_SIZE
450450

451-
順編成ファイルの書き込みバッファサイズを指定します。
451+
順編成ファイルの読み書きバッファサイズを指定します。
452+
453+
- ****: 0以上の整数(デフォルト: 10)。レコードサイズに対する倍率を指定します。
454+
- ****: `COB_FILE_SEQ_BUFFER_SIZE=100`
455+
- **用途**: SEQUENTIALおよびLINE SEQUENTIALファイルの読み書きパフォーマンスを調整できます。実際のバッファサイズは `COB_FILE_SEQ_BUFFER_SIZE * record_max` バイトとなります。0を指定するとバッファリングが無効になります。
456+
457+
#### COB_FILE_SEQ_WRITE_BUFFER_SIZE(非推奨)
458+
459+
非推奨です。代わりに `COB_FILE_SEQ_BUFFER_SIZE` を使用してください。
460+
461+
後方互換性のために残されています。`COB_FILE_SEQ_BUFFER_SIZE` が設定されていない場合にフォールバックとして同じ効果で使用されます。
452462

453463
- ****: 0以上の整数(デフォルト: 10)
454464
- ****: `COB_FILE_SEQ_WRITE_BUFFER_SIZE=100`
455-
- **用途**: 書き込みパフォーマンスを調整できます。
456465

457466
#### COB_IO_ASSUME_REWRITE
458467

libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/common/CobolUtil.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ public class CobolUtil {
6969
/** TDOD: 準備中 */
7070
public static Calendar cal;
7171

72-
/** TDOD: 準備中 */
73-
public static int fileSeqWriteBufferSize = 10;
72+
/** 順編成ファイルの読み書きバッファサイズ(レコード数単位) */
73+
public static int fileSeqBufferSize = 10;
7474

7575
/** DISPLAY/ACCEPT文によるデータ出力時のエンコーディング */
7676
public static CobolEncoding terminalEncoding = CobolEncoding.SHIFT_JIS;
@@ -345,11 +345,18 @@ public static void cob_init(String[] argv, boolean cobInitialized) {
345345
CobolUtil.nibbleCForUnsigned = true;
346346
}
347347

348-
s = System.getenv("COB_FILE_SEQ_WRITE_BUFFER_SIZE");
348+
s = CobolUtil.getEnv("COB_FILE_SEQ_BUFFER_SIZE");
349+
if (s == null) {
350+
s = CobolUtil.getEnv("COB_FILE_SEQ_WRITE_BUFFER_SIZE");
351+
}
349352
if (s != null) {
350-
int size = Integer.parseInt(s);
351-
if (size >= 0) {
352-
CobolUtil.fileSeqWriteBufferSize = size;
353+
try {
354+
int size = Integer.parseInt(s);
355+
if (size >= 0) {
356+
CobolUtil.fileSeqBufferSize = size;
357+
}
358+
} catch (NumberFormatException e) {
359+
// ignore invalid value
353360
}
354361
}
355362

libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/CobolFile.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,9 +1243,8 @@ public int open_(String filename, int mode, int sharing) throws IOException {
12431243
}
12441244
if ((this.organization == COB_ORG_SEQUENTIAL
12451245
|| this.organization == COB_ORG_LINE_SEQUENTIAL)
1246-
&& (mode == COB_OPEN_OUTPUT || mode == COB_OPEN_EXTEND)
1247-
&& CobolUtil.fileSeqWriteBufferSize > 0) {
1248-
this.file.prepareWriteBuffer(CobolUtil.fileSeqWriteBufferSize * this.record_max);
1246+
&& CobolUtil.fileSeqBufferSize > 0) {
1247+
this.file.prepareBuffer(CobolUtil.fileSeqBufferSize * this.record_max);
12491248
}
12501249
return 0;
12511250
}

0 commit comments

Comments
 (0)