# Business Logic — JBSbatKKCourseChgFileBnkt.readFile() [34 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `eo.business.service.JBSbatKKCourseChgFileBnkt` |
| Layer | Service (Batch-side file I/O utility) |
| Module | `service` (Package: `eo.business.service`) |

## 1. Role

### JBSbatKKCourseChgFileBnkt.readFile()

The `readFile` method is a **batch-side file ingestion utility** responsible for reading a text file from a given directory path and loading its contents into a `List<String>` — one line per element. This method acts as the **primary data intake mechanism** for the course change batch job (`JBSbatKKCourseChg`), which processes student/course enrollment change requests in an academic administration system. The batch operates under the KK (K-opt / K-Operation) batch processing framework, handling course schedule modifications such as student transfers between sections, class additions, and curriculum adjustments.

The method implements the **try-finally resource management pattern** (pre-Java 7 try-with-resources style), ensuring the underlying file reader is always closed regardless of whether the read completes normally or terminates due to an `IOException`. It uses **line-by-line streaming** rather than loading the entire file into memory at once, which supports processing large course change input files without excessive memory pressure. The file is encoded in **Shift-JIS** (a Japanese character encoding standard), and uses **LF** (`
`) line separators, consistent with the file conventions of the source system feeding course change data into the batch pipeline.

As a **private static** method, `readFile` is an internal helper — not a public API — called exclusively by `execute()`, the batch entry point. It delegates to `JBSbatInputFileUtil`, a reusable batch I/O utility class, and wraps I/O exceptions into `JBSbatBusinessException` with error code `EKKB0020CE` for centralized batch error handling and logging.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["readFile String strFileDir"])
    InitList["Create ArrayList<String> resultList"]
    CreateUtil["Create JBSbatInputFileUtil strFileDir"]
    SetEncode["Set encoding to SJIS"]
    SetLine["Set line separator to LF"]
    CreateReader["Create file reader"]
    TryStart["Start try block"]
    LoopStart{"While true"}
    ReadLine["Read line: line = inFile.readLine"]
    CheckNull{"line == null"}
    CloseBreak["inFile.close and break"]
    AddLine["resultList.add line"]
    ReturnList["Return resultList"]
    CatchIO["Catch IOException: throw JBSbatBusinessException EKKB0020CE"]
    FinallyClose["inFile.close in finally block"]
    END_NODE(["End"])

    START --> InitList
    InitList --> CreateUtil
    CreateUtil --> SetEncode
    SetEncode --> SetLine
    SetLine --> CreateReader
    CreateReader --> TryStart
    TryStart --> LoopStart
    LoopStart --> ReadLine
    ReadLine --> CheckNull
    CheckNull --> true
    CheckNull --> false
    true --> CloseBreak
    false --> AddLine
    CloseBreak --> END_NODE
    AddLine --> LoopStart
    LoopStart --> ReturnList
    ReturnList --> END_NODE
    TryStart --> CatchIO
    CatchIO --> FinallyClose
    FinallyClose --> END_NODE
```

**Constant Resolution:**

| Constant | Resolved Value | Business Meaning |
|----------|---------------|------------------|
| `JKKBatConst.SJIS` | `"Shift-JIS"` | Japanese character encoding standard used for batch input files |
| `JCNStrConst.S_LINE_SEPARAOR_LF` | `"
"` | Line Feed — Unix-style line separator used in source course change files |

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `strFileDir` | `String` | Full directory path to the input file containing course change data. This path points to the batch staging area where course change request files are deposited by upstream systems (e.g., student information system exports). The file name is implicitly determined by the batch configuration; only the directory path is passed here. |
| — | `resultList` | `ArrayList<String>` | Instance-level: The return value — a list where each element is one raw line from the input file. Each line corresponds to a record in the course change file, to be parsed further by the caller (`execute()`). |
| — | `inFile` | `JBSbatInputFileUtil` | Local: File input wrapper that manages the file stream, encoding, and line separator configuration. Provides `readLine()` for line-by-line access and `close()` for resource cleanup. |

## 4. CRUD Operations / Called Services

### Pre-computed evidence from code analysis graph:

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JBSbatInputFileUtil.createReader` | JBSbatInputFileUtil | - | Opens the input file for reading; establishes the file stream |
| R | `JBSbatInputFileUtil.readLine` | JBSbatInputFileUtil | - | Reads one line from the input file; returns `null` on EOF |
| - | `JBSbatInputFileUtil.close` | JBSbatInputFileUtil | - | Closes the file stream and releases the file handle |
| - | `JBSbatInputFileUtil.setEncode` | JBSbatInputFileUtil | - | Sets the character encoding for the file reader (Shift-JIS) |
| - | `JBSbatInputFileUtil.setLine` | JBSbatInputFileUtil | - | Sets the line separator for the file reader (LF) |
| C | `JBSbatBusinessException` | - | - | Throws a batch business exception with error code EKKB0020CE when file I/O fails |

**Note:** No SC (Service Component) codes, DB tables, or entity classes are directly involved in this method. It is a pure file I/O wrapper — the only data interaction is reading text lines from a file. The actual business processing (parsing, validation, DB persistence) occurs in the caller (`execute()`), which processes the `resultList` returned by this method.

## 5. Dependency Trace

### Pre-computed evidence from code analysis graph:

No screen/batch entry points found within 8 hops. Direct callers found: 1 methods.
Terminal operations from this method: `close` [-], `readLine` [R]

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: `JBSbatKKCourseChgFileBnkt` | `JBSbatKKCourseChgFileBnkt.execute` -> `JBSbatKKCourseChgFileBnkt.readFile` | `readLine [R] file` / `close [-] file` |

**Analysis:** `readFile` is a **private static helper** called only by `execute()` — the batch entry point of the same class (`JBSbatKKCourseChgFileBnkt`). It is not reachable from any screen (`KKSV*`) or external CBS. Its dependency footprint is minimal: it reads from a file and closes the stream. No database, no SC calls, no entity operations.

## 6. Per-Branch Detail Blocks

**Block 1** — [SET] `(Initialization)` (L295)

> Initializes the in-memory result container before opening the file.

| # | Type | Code |
|---|------|------|
| 1 | SET | `resultList = new ArrayList<String>()` // Empty list to accumulate file lines |

**Block 2** — [SET / EXEC] `(File I/O Setup)` (L298-302)

> Configures the batch file input utility with encoding, line separator, and opens the file stream.

| # | Type | Code |
|---|------|------|
| 1 | SET | `inFile = new JBSbatInputFileUtil(strFileDir)` // [External file path] // Opens a reference to the input file at the given directory |
| 2 | EXEC | `inFile.setEncode(JKKBatConst.SJIS)` // [-> JKKBatConst.SJIS = "Shift-JIS"] // Sets file character encoding to Shift-JIS (Japanese standard) |
| 3 | EXEC | `inFile.setLine(JCNStrConst.S_LINE_SEPARAOR_LF)` // [-> JCNStrConst.S_LINE_SEPARAOR_LF = "
"] // Sets line separator to LF |
| 4 | EXEC | `inFile.createReader()` // Opens the actual file stream for reading |

**Block 3** — [TRY] `(File Reading Loop)` (L304-320)

> The core processing block: reads the file line-by-line until EOF, accumulating lines into the result list.

**Block 3.1** — [WHILE] `(Infinite Loop with Break)` (L305)

> Uses `while(true)` with a `break` on EOF — a common pattern for streaming reads in legacy Java batch code.

**Block 3.2** — [SET] `(Read Line)` (L306)

| # | Type | Code |
|---|------|------|
| 1 | SET | `line = inFile.readLine()` // Reads one line from the file; returns null when EOF is reached |

**Block 3.3** — [IF] `(line == null)` (L307)

> EOF detected: close the file and exit the loop.

**Block 3.3.1** — [EXEC] `(Close and Break)` (L309)

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `inFile.close()` // Closes the file stream |
| 2 | SET | `break` // Exits the while loop |

**Block 3.4** — [ELSE] `(line != null)` (L307 implicit)

> A line was read successfully — append it to the result list.

**Block 3.4.1** — [SET] `(Add Line to Result)` (L311)

| # | Type | Code |
|---|------|------|
| 1 | SET | `resultList.add(line)` // Appends the non-null line to the result list |

**Block 3.5** — [RETURN] `(Return Result)` (L314)

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return resultList` // Returns all accumulated lines to the caller |

**Block 4** — [CATCH] `(IOException)` (L316)

> Wraps any file I/O failure into a batch business exception with error code `EKKB0020CE`, providing the file directory path as context for error reporting.

| # | Type | Code |
|---|------|------|
| 1 | C | `throw new JBSbatBusinessException("EKKB0020CE", new String[]{strFileDir})` // Wraps IOException into batch exception |

**Block 5** — [FINALLY] `(Resource Cleanup)` (L319)

> Guarantees the file stream is always closed, even if an exception occurred or the method returned early. This is a **defensive close** — the `inFile.close()` in Block 3.3.1 handles the normal path, but the finally block ensures cleanup on any abnormal exit.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `inFile.close()` // Ensures file stream is released regardless of execution path |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `strFileDir` | Parameter | File directory path — the full path to the batch input staging directory where course change data files are placed |
| `JBSbatKKCourseChgFileBnkt` | Class | KK Course Change File Bank — batch service class that handles file-level operations (read, parse, validate) for course change input data |
| `KK` | Acronym | K-Operation — Fujitsu's batch processing framework naming convention; indicates this is an operation/batch component |
| `CourseChg` | Domain term | Course Change — refers to student/course enrollment modifications (additions, deletions, transfers between course sections) in an academic administration system |
| `SJIS` | Encoding | Shift-JIS — Japanese industrial standard character encoding (ISO-2022-JP successor), used for Japanese text files in enterprise batch processing |
| `LF` | Encoding | Line Feed (`
`) — Unix-style line separator character |
| `JBSbatInputFileUtil` | Component | Batch Student Input File Utility — shared batch I/O utility for reading input files with configurable encoding and line separators |
| `JBSbatBusinessException` | Exception | Batch Student Business Exception — the standard exception type for batch-side business logic errors; wraps error codes and context for centralized error handling |
| `EKKB0020CE` | Error Code | KK Batch Business Error Code — error code assigned when a batch input file cannot be read (I/O failure). "CE" suffix typically denotes a "Critical Error" in the batch error code taxonomy |
| `resultList` | Field | Result List — the in-memory collection of all file lines, passed to the caller for further parsing and business processing |
| `L` | Notation | Line — abbreviation for "line" (as in a line of text or a line number in source code) |
| `L{number}` | Notation | Source line reference — indicates the specific source line number where a code block begins |
| `L` (in mermaid) | Notation | Line — abbreviation for "line" (as in a line of text or a line number in source code) |
| `L{number}` | Notation | Source line reference — indicates the specific source line number where a code block begins |
