Legacy Claims Portal Home Patterns Handbuch
Java-Quellcode · HTML-first

FileShareDocumentStorageAdapter.java

Browserlesbare Ansicht der unveränderten Java-Quelldatei. Die Originaldatei bleibt im Maven-Projekt erhalten.

Zuordnung

Adapter
Originalpfad03_after_refactoring_modular/claim-infrastructure/src/main/java/com/seb4u/demo/claims/infrastructure/document/FileShareDocumentStorageAdapter.java

Quellcode

package com.seb4u.demo.claims.infrastructure.document;

import com.seb4u.demo.claims.application.port.DocumentStoragePort;
import java.nio.file.*;

public class FileShareDocumentStorageAdapter implements DocumentStoragePort {
    private final Path root;
    public FileShareDocumentStorageAdapter(Path root) { this.root = root; }
    public String store(String claimId, String name, String contentType, byte[] payload) {
        try {
            Path dir = root.resolve(claimId);
            Files.createDirectories(dir);
            Path target = dir.resolve(name);
            Files.write(target, payload);
            return target.toString();
        } catch (Exception e) { throw new IllegalStateException("Could not store document", e); }
    }
    public byte[] load(String storageReference) {
        try { return Files.readAllBytes(Path.of(storageReference)); }
        catch (Exception e) { throw new IllegalStateException("Could not load document", e); }
    }
}
⌂ Cockpit