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

| Field | Value |
|-------|-------|
| Fully Qualified Name | `eo.business.service.JBSbatKKMiStcKikiSvcCncl` |
| Layer | Batch Service |
| Module | `service` (Package: `eo.business.service`) |

## 1. Role

### JBSbatKKMiStcKikiSvcCncl.readFile()

This method performs **batch file input reading** for the uninstalled-machine cancellation service (`JBSbatKKMiStcKikiSvcCncl`). The service class handles cancellation processing for services where no terminal equipment was ever installed (未設定機器サービスキャンセル) — a business scenario where a customer subscribed to a service but the physical device was never delivered or set up. The `readFile()` method acts as a **private utility** that reads an entire input file line-by-line from a specified directory (full path), returning each line as a string element in an `ArrayList`. It uses **SJIS (Shift-JIS)** character encoding and **LF (line feed)** as the line separator, which is the standard Japanese batch file format convention.

This method implements a **read-everything pattern**: it opens a file, reads all lines sequentially into a list, and returns the complete result set. It is not a routing or dispatch method — there are no conditional branches based on data content. Instead, it serves as a **data ingestion step** that provides raw line content to callers (typically other batch processing methods within the same class) that then parse, validate, and route the data according to business rules. The method follows a **try-catch-finally** pattern ensuring resource cleanup via `inFile.close()` in both normal flow and exception paths.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["readFile(String strFileDir)"])
    INIT["Initialize ArrayList result"]
    CREATE_UTIL["Create JBSbatInputFileUtil with strFileDir"]
    SET_ENC["Set encoding to SJIS (Shift-JIS)"]
    SET_LSEP["Set line separator to LF (\
)"]
    CREATE_READER["Create file reader (inFile.createReader)"]
    LOOP_START{"More lines?"}
    READ_LN["Read one line: inFile.readLine()"]
    NULL_CHECK{"line == null?"}
    CLOSE_NORM["Close file: inFile.close()"]
    ADD_ITEM["Add line to resultList"]
    RETURN["Return resultList"]
    CATCH_IO["Catch IOException"]
    THROW_ERR["Throw JBSbatBusinessException (EKKB0020CE)"]
    FINALLY["Finally: inFile.close()"]

    START --> INIT
    INIT --> CREATE_UTIL
    CREATE_UTIL --> SET_ENC
    SET_ENC --> SET_LSEP
    SET_LSEP --> CREATE_READER
    CREATE_READER --> LOOP_START
    LOOP_START -->|false / EOF| CLOSE_NORM
    LOOP_START -->|true| READ_LN
    READ_LN --> NULL_CHECK
    NULL_CHECK -->|true| CLOSE_NORM
    NULL_CHECK -->|false| ADD_ITEM
    ADD_ITEM --> LOOP_START
    CLOSE_NORM --> RETURN
    RETURN --> FINALLY
    CATCH_IO --> THROW_ERR
    THROW_ERR --> FINALLY
```

**Processing Description:**

1. **Initialize**: Create an empty `ArrayList<String>` to accumulate file lines.
2. **File Setup**: Instantiate `JBSbatInputFileUtil` with the input directory path, set encoding to `SJIS` (Shift-JIS, resolved from `JKKBatConst.SJIS = "Shift-JIS"`), set line separator to `LF` (line feed, resolved from `JCNStrConst.S_LINE_SEPARAOR_LF = "
"`), and create the file reader.
3. **Read Loop**: Continuously read lines from the file until `readLine()` returns `null` (end-of-file).
4. **Accumulate**: Each non-null line is added to `resultList`.
5. **Normal Exit**: When EOF is reached, close the input stream, return the accumulated list, and enter the finally block for a second close (safe no-op).
6. **Error Exit**: On `IOException`, throw `JBSbatBusinessException` with error code `EKKB0020CE`, then enter the finally block for cleanup.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `strFileDir` | `String` | Full path to the input file directory. Specifies the filesystem directory where the batch input file resides. This path is used to construct the file reader for line-by-line reading. In the batch context, this is typically an incoming processing directory populated by upstream systems or file transfer operations. |

**External State / Instance Fields Read:** None — this is a static method with no dependency on instance state.

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JBSbatInputFileUtil` (constructor) | - | Filesystem | Opens input file stream at the specified directory path |
| - | `JBSbatInputFileUtil.setEncode` | - | - | Sets character encoding to SJIS (Shift-JIS) for file reading |
| - | `JBSbatInputFileUtil.setLine` | - | - | Sets line separator to LF (
) for line-based parsing |
| - | `JBSbatInputFileUtil.createReader` | - | - | Initializes the file reader with configured encoding and separator |
| R | `JBSbatInputFileUtil.readLine` | JBSbatFileRead | Filesystem | Reads one line from the input file; returns null at EOF |
| - | `ArrayList.add` | - | In-memory | Appends a file line to the result list |
| - | `JBSbatInputFileUtil.close` | - | - | Closes the input file stream (called in try and finally blocks) |
| - | `JBSbatBusinessException` | - | - | Throws business exception with error code EKKB0020CE on IO failure |

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch:JBSbatKKMiStcKikiSvcCncl (internal) | Private static method — called within the same class | N/A — utility method with no external callers found |

**Note:** `readFile()` is a `private static` method. The search found no external callers referencing this method from other classes. It is intended for internal use within `JBSbatKKMiStcKikiSvcCncl` only, likely called by other private helper methods or the main `execute()` method for reading input configuration files during the uninstalled-machine cancellation batch processing.

## 6. Per-Branch Detail Blocks

### Block 1 — SETUP (L314)

> Initialize result container and configure file reader for batch input.

| # | Type | Code |
|---|------|------|
| 1 | SET | `ArrayList<String> resultList = new ArrayList<String>();` // Empty list to accumulate file lines |
| 2 | SET | `JBSbatInputFileUtil inFile = new JBSbatInputFileUtil(strFileDir);` // Create file input utility with full path [-> Input file directory path] |
| 3 | SET | `inFile.setEncode(JKKBatConst.SJIS);` // Set encoding to Shift-JIS [-> JKKBatConst.SJIS = "Shift-JIS"] |
| 4 | SET | `inFile.setLine(JCNStrConst.S_LINE_SEPARAOR_LF);` // Set line separator to LF [-> JCNStrConst.S_LINE_SEPARAOR_LF = "
"] |
| 5 | EXEC | `inFile.createReader();` // Open the file reader with configured encoding and separator |

### Block 2 — TRY BLOCK: Read Loop (L319)

> Read all lines from the file until end-of-file, accumulating them in the result list.

| # | Type | Code |
|---|------|------|
| 1 | LOOP | `while (true)` // Continuous read loop |
| 2 | SET | `String line = inFile.readLine();` // Read one line; returns null at EOF |
| 3 | SET | `resultList.add(line);` // Add non-null line to result list |

#### Block 2.1 — EOF CHECK (L321)

> Check if the read line is null (end-of-file reached). If so, close the file and break the loop.

| # | Type | Code |
|---|------|------|
| 1 | SET | `String line = inFile.readLine();` [-> inFile.readLine()] |
| 2 | IF | `if (null == line)` [-> End of file detected] (L321) |
| 3 | EXEC | `inFile.close();` // Close input stream on EOF |
| 4 | SET | `break;` // Exit while loop |

#### Block 2.2 — LINE ACCUMULATION (L325)

> Add the non-null (valid) line to the result list and continue reading.

| # | Type | Code |
|---|------|------|
| 1 | SET | `resultList.add(line);` // Append to result list (L325) |

### Block 3 — RETURN (L328)

> Return the accumulated list of all file lines.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return resultList;` // Return complete file content as list of strings (L328) |

### Block 4 — CATCH (IOException) (L330)

> Handle IO exceptions by throwing a business exception with error code.

| # | Type | Code |
|---|------|------|
| 1 | IF | CATCH [IOException e] (L330) |
| 2 | SET | `throw new JBSbatBusinessException("EKKB0020CE", new String[]{strFileDir});` // Business exception with error code and file path [-> Error Code: EKKB0020CE] |

### Block 5 — FINALLY (L334)

> Ensure file input stream is always closed, even if an exception occurred.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `inFile.close();` // Guaranteed cleanup of file input stream (L336) |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `strFileDir` | Parameter | Input file directory (full path) — the filesystem path pointing to the batch input file to be read line-by-line |
| SJIS | Business term | Shift-JIS — Japanese character encoding standard used for batch file I/O in legacy Japanese enterprise systems |
| LF | Technical term | Line Feed (U+000A) — the line separator character used for line-based file reading in this batch process |
| `EKKB0020CE` | Error Code | Business exception error code — indicates a file I/O failure occurred during batch file reading |
| `JBSbatInputFileUtil` | Utility Class | Batch file input utility — framework component for reading input files with configurable encoding and line separator |
| `JBSbatBusinessException` | Exception Class | Business-layer exception wrapper — wraps error codes and contextual parameters for structured error handling in batch services |
| KKMiStcKikiSvcCncl | Domain term | Uninstalled-Machine Service Cancellation — batch service that processes cancellations for subscriptions where the terminal equipment was never installed or delivered |
| `resultList` | Field | Result accumulator — the ArrayList<String> that collects all file lines for downstream processing |
| `createReader` | Method | File reader initialization — opens the underlying file stream with the configured encoding and separator settings |
| Batch Service | Architecture term | A background processing unit that executes scheduled data processing jobs, typically reading input files, transforming data, and writing results |
