Skip to content

feat: add shared read/write buffer for sequential files (COB_FILE_SEQ_BUFFER_SIZE)#795

Draft
yutaro-sakamoto wants to merge 6 commits intoopensourcecobol:developfrom
yutaro-sakamoto:file-record-buffer
Draft

feat: add shared read/write buffer for sequential files (COB_FILE_SEQ_BUFFER_SIZE)#795
yutaro-sakamoto wants to merge 6 commits intoopensourcecobol:developfrom
yutaro-sakamoto:file-record-buffer

Conversation

@yutaro-sakamoto
Copy link
Copy Markdown
Contributor

@yutaro-sakamoto yutaro-sakamoto commented Mar 2, 2026

Summary

  • Introduce a new environment variable COB_FILE_SEQ_BUFFER_SIZE that enables buffering for both
    read and write operations on SEQUENTIAL and LINE SEQUENTIAL files
  • The old COB_FILE_SEQ_WRITE_BUFFER_SIZE (write-only) is deprecated and used as a fallback when
    the new variable is not set
  • Significantly improves read performance by eliminating 1-byte-at-a-time FileChannel.read()
    calls

Changes

  • FileIO.java: Replace separate read/write buffers with a unified buffer using a 3-state
    mode machine (BUFFER_MODE_NONE / READ / WRITE). Mode transitions handle flushing
    (WRITE→READ) and FileChannel position adjustment (READ→WRITE). Also fixes getc() to return
    unsigned byte values (& 0xFF).
  • CobolUtil.java: Rename fileSeqWriteBufferSizefileSeqBufferSize. Read
    COB_FILE_SEQ_BUFFER_SIZE first, falling back to COB_FILE_SEQ_WRITE_BUFFER_SIZE. Add
    NumberFormatException handling and use CobolUtil.getEnv() for consistency.
  • CobolFile.java: Expand buffer preparation in open_() from OUTPUT/EXTEND only to all open
    modes (INPUT, OUTPUT, I-O, EXTEND).
  • doc/environment_variables.md / doc/environment_variables_JP.md: Add
    COB_FILE_SEQ_BUFFER_SIZE documentation and mark COB_FILE_SEQ_WRITE_BUFFER_SIZE as deprecated.
  • tests/misc.src/seq-buffer.at: Add 10 integration tests covering sequential read, line
    sequential read, buffer size 1, buffer disabled, I-O rewrite, many records, deprecated fallback,
    mode transitions, and short records.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant