# Business Logic — Example.downloadFile() [13 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `io.github.biezhi.java11.http.Example` |
| Layer | Utility (Sample/Example class demonstrating Java 11 HTTP Client API) |
| Module | `http` (Package: `io.github.biezhi.java11.http`) |

## 1. Role

### Example.downloadFile()

This method demonstrates the **Java 11 HTTP Client** API (introduced in `java.net.http`) by performing a **file download** from a remote HTTP endpoint. Specifically, it issues an HTTP GET request to `https://labs.consol.de/`, creates a temporary local file, and streams the response body directly into that file. The method follows a **linear delegation pattern** — it creates an `HttpClient`, constructs an `HttpRequest`, and delegates the network transfer to `HttpClient.send()` with a body handler that writes to disk. It serves as a **code sample / demonstration** within the `Example` class, which is a collection of Java 11 feature showcase snippets. The method has no conditional branches, no database operations, and no dependency on business logic layers.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["downloadFile()"])
    START --> STEP1["Create HttpClient via newHttpClient()"]
    STEP1 --> STEP2["Build HttpRequest for https://labs.consol.de/ using newBuilder().GET().build()"]
    STEP2 --> STEP3["Create temp file via Files.createTempFile with prefix consol-labs-home and suffix .html"]
    STEP3 --> STEP4["Send request via client.send(request, BodyHandlers.ofFile(tempFile))"]
    STEP4 --> STEP5["Print response statusCode to stdout"]
    STEP5 --> STEP6["Print response body (tempFilePath) to stdout"]
    STEP6 --> END_NODE(["Return void / Next"])
```

**CRITICAL — Constant Resolution:**
No constants are used in this method.

**Requirements:**
- Every step is represented as a rectangular processing node (no conditions or loops exist).
- The flow is strictly linear: create HTTP client → build request → create temp file → send request → print results → return.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| - | (none) | - | This method takes no parameters. All configuration is hardcoded. |

**Instance fields / external state read:** None. This method operates entirely with local variables and static JDK classes.

## 4. CRUD Operations / Called Services

This method does not perform any CRUD operations. It makes no database calls, no service component (SC) invocations, and does not interact with any entity or table. It only uses Java standard library APIs (`java.net.http.HttpClient`, `java.net.http.HttpRequest`, `java.net.http.HttpResponse`, `java.nio.file.Files`).

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| — | — | — | — | No database or service interactions |

## 5. Dependency Trace

No callers found. This method is a standalone example snippet and is not invoked by any other code in the project.

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | — (no callers) | — | — |

## 6. Per-Branch Detail Blocks

This method has no control flow branches (no if/else, switch, loops, or try-catch). The execution is a single straight-line sequence.

**Block 1** — LINEAR EXECUTION (no condition) (L89)

> Create HTTP client, build request, create temp file, send request, and print results.

| # | Type | Code |
|---|------|------|
| 1 | SET | `HttpClient client = HttpClient.newHttpClient();` // Create a new HTTP client instance (L89) |
| 2 | SET | `HttpRequest request = HttpRequest.newBuilder().uri(new URI("https://labs.consol.de/")).GET().build();` // Build a GET request targeting https://labs.consol.de/ (L91-L94) |
| 3 | SET | `Path tempFile = Files.createTempFile("consol-labs-home", ".html");` // Create a temporary file with prefix "consol-labs-home" and extension ".html" (L96) |
| 4 | SET | `HttpResponse<Path> response = client.send(request, HttpResponse.BodyHandlers.ofFile(tempFile));` // Send the HTTP request; body handler streams response bytes to tempFile (L97) |
| 5 | EXEC | `System.out.println(response.statusCode());` // Print HTTP status code (e.g., 200) to stdout (L98) |
| 6 | EXEC | `System.out.println(response.body());` // Print the path to the downloaded temp file to stdout (L99) |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `HttpClient` | Class | Java 11 HTTP Client — a modern, blocking HTTP client for sending requests and receiving responses |
| `HttpRequest` | Class | HTTP request builder object — holds URI, method, headers, and body for an outbound HTTP request |
| `HttpResponse<Path>` | Class | HTTP response with body handler that delivers content as a `Path` (file path on disk) |
| `BodyHandlers.ofFile(Path)` | API | Response body handler that writes the HTTP response body bytes to a specified file on disk |
| `Files.createTempFile(prefix, suffix)` | API | JDK file utility that creates an empty temporary file with a unique name, given a prefix and suffix |
| `HttpClient.newHttpClient()` | API | Factory method that creates a new default-configured `HttpClient` instance |
| `https://labs.consol.de/` | URL | The HTTP endpoint targeted by this example — the CONSOL Labs blog, used as a sample download target |
| `throws Exception` | Signature | Method declares it may throw checked exceptions (e.g., `IOException` from network/file I/O, `URISyntaxException` from URI parsing) |
| L88 (Chinese) | Comment | 下载文件 — "Download File" — Chinese comment describing this method's purpose |
