Interface FileHandler
- All Known Implementing Classes:
CsvHandler,ExcelHandler
A FileHandler wraps a generated file payload (an SXSSF workbook, a staged
CSV temp file, etc.) and writes it to a target OutputStream exactly once.
This lets callers treat Excel and CSV outputs polymorphically — for example,
a single Spring controller method can return either by wiring the handler into
a StreamingResponseBody.
One-shot contract
Each implementation must refuse a secondwriteTo(OutputStream) call and
must release any temporary resources (workbooks, staging files) inside the call,
whether it succeeds or throws.
Closed hierarchy
The shipped implementations (ExcelHandler, CsvHandler) are final.
excel-kit ships as an automatic module (no module-info.java), so this
interface is not declared sealed — but the library does not support pluggable
output formats beyond the ones it ships. Third-party implementations are unsupported.- Since:
- 0.11.0
-
Method Summary
Modifier and TypeMethodDescriptionvoidwriteTo(OutputStream out) Writes the generated file content to the given output stream.default voidWrites the generated file content directly to a file path.
-
Method Details
-
writeTo
Writes the generated file content to the given output stream.Can only be called once per handler instance. The handler's backing resources (workbook, staging file) are released before this method returns.
I/O errors are wrapped as unchecked exceptions (e.g.,
ExcelWriteException,CsvWriteException) so callers do not need to handle checked exceptions.- Parameters:
out- the destination stream
-
writeTo
Writes the generated file content directly to a file path.Convenience overload that opens a buffered
OutputStreamto the given path, delegates towriteTo(OutputStream), and closes the stream. The one-shot contract applies — this method can only be called once.ExcelWriter.<User>create() .column("Name", User::getName) .write(stream) .writeTo(Path.of("users.xlsx"));- Parameters:
path- the destination file path- Since:
- 0.14.0
-