FileShareDocumentStorageAdapter.java
Browserlesbare Ansicht der unveränderten Java-Quelldatei. Die Originaldatei bleibt im Maven-Projekt erhalten.
Zuordnung
Adapter
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); }
}
}