---
title: "Business Logic — JBSbatKKCourseChgFixTgCst.executeOutputFile()"
created: "2026-07-28"
updated: "2026-07-28"
source:
  file: "source/koptBatch/src/eo/business/service/JBSbatKKCourseChgFixTgCst.java"
  range: "891-915"
---

# Business Logic — JBSbatKKCourseChgFixTgCst.executeOutputFile() [25 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `eo.business.service.JBSbatKKCourseChgFixTgCst` |
| Layer | Service (Batch CC/Common Component) |
| Module | `service` (Package: `eo.business.service`) |

## 1. Role

### JBSbatKKCourseChgFixTgCst.executeOutputFile()

This method is responsible for writing a prepared intermediate data string to a file on disk as part of a course change batch processing pipeline. It is a private utility method used internally by the batch job to materialize formatted course change fix data into an intermediate file (`KKIFM156001`) at a configurable directory path. The method uses Shift-JIS encoding, which is the standard encoding for Japanese enterprise batch output files, ensuring compatibility with downstream systems that consume the intermediate file. It delegates to the standard Java `BufferedWriter`/`FileOutputStream` chain — no database or external SC/CBS calls are made. The method implements a defensive try-catch-finally pattern: on file I/O failure, it raises a `JBSbatBusinessException` with error code `EKKB0250CE` to signal a file output error (ファイル出力) to the caller's exception handler, while guaranteeing the `BufferedWriter` is always closed in the `finally` block. Its role in the larger system is as a dedicated file-output utility within the course change fix batch, encapsulating a single responsibility — persisting a pre-built string buffer to disk — so that the main `execute()` method remains focused on orchestration logic.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["executeOutputFile(file_data, file_path, file_name)"])
    INIT["Initialize: BufferedWriter wr = null"]
    TRY_BEGIN["Try Block Start"]
    CREATE_WR["Create BufferedWriter wrapping FileOutputStream(file_path) with ENCODE='Shift-JIS'"]
    WRITE["Write file_data string to file_path"]
    FLUSH["Flush BufferedWriter"]
    TRY_OK["Try Block completes successfully"]
    FINALLY["Finally Block: Check if wr != null"]
    CLOSE_WR["Close BufferedWriter"]
    END_OK(["Return / Next"])
    CATCH_BEGIN["Catch IOException e"]
    RAISE_ERR["Throw JBSbatBusinessException('EKKB0250CE', [file_name, MASSEAGE='ファイル出力'])"]
    FINALLY_AFTER_EXC["Finally Block: Check if wr != null"]
    CLOSE_WR_EXC["Close BufferedWriter (may throw)"]
    END_FAIL(["Exception propagated / Exit"])

    START --> INIT
    INIT --> TRY_BEGIN
    TRY_BEGIN --> CREATE_WR
    CREATE_WR --> WRITE
    WRITE --> FLUSH
    FLUSH --> TRY_OK
    TRY_OK --> FINALLY
    FINALLY --> CLOSE_WR
    CLOSE_WR --> END_OK
    FLUSH -. IOException .-> CATCH_BEGIN
    CATCH_BEGIN --> RAISE_ERR
    RAISE_ERR --> FINALLY_AFTER_EXC
    FINALLY_AFTER_EXC --> CLOSE_WR_EXC
    CLOSE_WR_EXC --> END_FAIL
```

**Branches:**

| Branch | Condition | Constant/Value | Business Meaning |
|--------|-----------|----------------|------------------|
| **Normal flow** | No exception during write/flush | N/A | File data is written successfully using Shift-JIS encoding to the target intermediate file |
| **IOException catch** | `IOException` thrown during write or flush | `ENCODE = "Shift-JIS"`, `MASSEAGE = "ファイル出力"` (file output) | File I/O error — the system could not write the intermediate file; raises business exception `EKKB0250CE` with the file name and error message |
| **Finally (wr == null)** | `wr` is null (allocation failed) | N/A | No close needed — the writer was never successfully created |
| **Finally (wr != null)** | `wr` is not null | N/A | The writer exists and must be closed to release the file handle, whether the try block succeeded or threw an exception |

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `file_data` | `String` | The prepared intermediate file content — a pre-built string containing the formatted course change fix data assembled by the caller (`execute()` method) via a `StringBuilder`. This is the actual data to be persisted to disk. |
| 2 | `file_path` | `String` | The full absolute file path on the server where the intermediate file will be written (e.g., a directory configured for batch intermediate files like `mid_dir_kk_path`). The directory must exist and be writable. |
| 3 | `file_name` | `String` | The intermediate file identifier used in error reporting. The actual file name constant is `CRS_CHG_FIX_IF_ID = "KKIFM156001"`, which represents the course change fix intermediate file ID. Used as context in the `EKKB0250CE` exception message when a write error occurs. |

**External state accessed:**

| Field | Type | Description |
|-------|------|-------------|
| `ENCODE` | `String` (private static final) | Character encoding constant, value `"Shift-JIS"`. Defines the encoding for the output file, required for Japanese text compatibility. |
| `MASSEAGE` | `String` (private static final) | Error message label constant, value `"ファイル出力"` (file output). Passed to the exception error code `EKKB0250CE` to contextualize which operation failed. |
| `JBSbatBusinessException` | — | Custom batch exception class. Thrown with error code `EKKB0250CE` and a string array `[file_name, MASSEAGE]` for localized error message resolution. |
| `IOException` | — | Java standard I/O exception. Caught when the file system cannot write or flush the file. |

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| - | `FileOutputStream` | - | - | Opens a file output stream for writing to the file system |
| - | `BufferedWriter.write` | - | - | Writes the `file_data` string content to the buffered writer |
| - | `BufferedWriter.flush` | - | - | Flushes buffered data to the underlying output stream |
| - | `BufferedWriter.close` | - | - | Closes the buffered writer and releases the file handle |
| - | `JBSbatBusinessException` constructor | - | - | Constructs a business exception with error code `EKKB0250CE` |

**Notes:** This method performs **no database or SC/CBS operations**. It is purely a file-system output utility that writes a string buffer to disk using standard Java I/O. There are no C/R/U/D operations against database tables or external services.

## 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` [-], `close` [-], `close` [-], `close` [-], `close` [-], `write` [-], `write` [-], `write` [-], `write` [-], `write` [-]

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: JBSbatKKCourseChgFixTgCst.execute() | `execute()` → `executeOutputFile(crsChgIf_str.toString(), mid_dir_kk_path, CRS_CHG_FIX_IF_ID)` | `FileOutputStream` (file output), `BufferedWriter.close` (file handle release) |

**Details on caller:** The sole caller is the `execute()` method of the same class (`JBSbatKKCourseChgFixTgCst`) at line 692. It passes three arguments:
- `crsChgIf_str.toString()` — the accumulated course change intermediate data built via `StringBuilder`
- `mid_dir_kk_path` — the configured intermediate file directory path
- `CRS_CHG_FIX_IF_ID` — the constant `"KKIFM156001"` identifying the intermediate file

The method has no terminal database operations. Its only external effect is writing to the local file system and releasing the file handle via `close()`.

## 6. Per-Branch Detail Blocks

**Block 1** — [VARIABLE DECLARATION] `(L895)`

> Initializes the `BufferedWriter` reference to `null` before the try block for safe cleanup in the finally clause.

| # | Type | Code |
|---|------|------|
| 1 | SET | `BufferedWriter wr = null;` // Initialize writer reference for finally-block safety |

---

**Block 2** — [TRY-CATCH-FINALLY] `(L896-914)`

> Tries to write the intermediate file data to disk using Shift-JIS encoding. On `IOException`, raises a business exception. In the finally block, ensures the writer is closed.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `wr = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file_path), ENCODE));` // Create writer wrapping FileOutputStream with ENCODE="Shift-JIS" [-> ENCODE="Shift-JIS"] |
| 2 | EXEC | `wr.write(file_data);` // Write the prepared file data string to the intermediate file |
| 3 | EXEC | `wr.flush();` // Flush buffered content to disk |
| 4 | CATCH | `catch(IOException e)` → `throw new JBSbatBusinessException("EKKB0250CE", new String[]{file_name, MASSEAGE});` // On file I/O error, throw business exception with error code EKKB0250CE (file output error) [-> MASSEAGE="ファイル出力"] |
| 5 | FINALLY | `if (null != wr) { wr.close(); }` // Safely close the writer if it was successfully allocated |

**Block 2.1** — [NESTED: TRY block — normal execution path] `(L897-900)`

> Opens the file output stream with Shift-JIS encoding, writes the data, and flushes.

| # | Type | Code |
|---|------|------|
| 1 | SET | `wr = new BufferedWriter(...)` // Creates buffered writer with file_path and ENCODE="Shift-JIS" [-> ENCODE="Shift-JIS"] |
| 2 | EXEC | `wr.write(file_data);` // Writes the complete file data to the output stream |
| 3 | EXEC | `wr.flush();` // Flushes all buffered content to ensure it reaches disk |

**Block 2.2** — [NESTED: CATCH block — IOException path] `(L903-907)`

> On any I/O error (e.g., disk full, permission denied, path not found), raises a `JBSbatBusinessException` with error code `EKKB0250CE`.

| # | Type | Code |
|---|------|------|
| 1 | EXCEPTION | `throw new JBSbatBusinessException("EKKB0250CE", new String[]{file_name, MASSEAGE});` // Business exception with error code EKKB0250CE, file_name parameter, and MASSEAGE="ファイル出力" (file output) |

**Block 2.3** — [NESTED: FINALLY block] `(L909-914)`

> Always executes — whether the try block succeeded or threw an exception. Checks if the writer was allocated before closing.

| # | Type | Code |
|---|------|------|
| 1 | CONDITIONAL | `if (null != wr)` // Check if writer was successfully allocated |
| 2.1 | EXEC | `wr.close();` // Close the buffered writer and release file handle |
| 2.2 | ELSE | (no-op — writer is null, nothing to close) |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `file_data` | Parameter | Prepared intermediate file content — the formatted course change fix data to be written to disk |
| `file_path` | Parameter | Full absolute path on the server for the intermediate output file |
| `file_name` | Parameter | File identifier used in error reporting; typically the intermediate file ID constant `CRS_CHG_FIX_IF_ID` |
| `CRS_CHG_FIX_IF_ID` | Constant | Course Change Fix Intermediate File ID — value `"KKIFM156001"`, the identifier for the course change fix intermediate file |
| `ENCODE` | Constant | Character encoding — value `"Shift-JIS"`, the standard encoding for Japanese batch output files |
| `MASSEAGE` | Constant | Error message label — value `"ファイル出力"` (file output), used in error code `EKKB0250CE` to identify the failed operation |
| `EKKB0250CE` | Error Code | Error code for file output failure — a custom business exception code used to signal that writing to the intermediate file failed |
| `JBSbatBusinessException` | Exception Class | Custom batch processing exception class used throughout the batch framework to propagate business-level errors with error codes and parameters |
| Intermediate File (中間ファイル) | Domain Term | A temporary file generated during batch processing that holds formatted data for downstream consumption. In this case, course change fix data is written as an intermediate file before further processing. |
| `mid_dir_kk_path` | Domain Term | The configured intermediate file directory path for KK (likely "kokuchu" or internal) batch files |
| Shift-JIS | Technical Term | A character encoding standard commonly used in Japanese computing systems, supporting JIS X 0208 characters |
| Course Change (コース変更) | Business Term | The business process of modifying service course/plan configurations for customers |
