Interface IStreamCommand
- All Known Implementing Classes:
AbstractStreamCommand,CharacterConvertCommand,ConsumerCommand,CsvFilterCommand,CsvNavigateCommand,CsvValidateCommand,FileBufferCommand,JacocoXmlToModuleSlocCommand,JsonFilterCommand,JsonNavigateCommand,LineEndingNormalizeCommand,ModuleXmlConcatCommand,PmdXmlToViolationsCommand,SendHttpCommand,SlocAggregateCommand,SlocReportFormatCommand,ValidateCommand,XmlFilterCommand,XmlNavigateCommand
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
This interface defines methods for executing commands on input streams and writing results to output streams.
This is a functional interface and can be implemented using lambda expressions or method references for simple stream processing operations.
Usage examples:
// Simple copy operation (IOException is propagated from execute method signature)
IStreamCommand copyCommand = (in, out) -> in.transferTo(out);
// Buffered stream processing with custom logic
IStreamCommand bufferCommand = (in, out) -> {
byte[] buffer = new byte[8192];
int len;
while ((len = in.read(buffer)) != -1) {
out.write(buffer, 0, len);
}
};
// Using in StreamConverter pipeline
StreamConverter converter = StreamConverter.create(copyCommand);
converter.run(inputStream, outputStream);
MDC への値の伝搬について: execute() 内で MDC.put() を直接呼び出しても、
他コマンドのスレッドには伝搬されません。ストリームから抽出した値を全コマンドのログに反映させるには MdcPropagatingRule を使用してください。子スレッドへの MDC 自動継承が必要な場合は MDCInitializer を参照してください。
-
Method Summary
Modifier and TypeMethodDescriptiondefault StringReturns a best-effort human-readable name for this command.voidexecute(InputStream inputStream, OutputStream outputStream) Executes the command on the provided input stream and writes the result to the output stream.default IStreamCommandwithLogging(org.slf4j.Logger logger) Wraps this command with logging.default IStreamCommandwithLogging(org.slf4j.Logger logger, String commandName) Wraps this command with logging using an explicit command name.
-
Method Details
-
execute
Executes the command on the provided input stream and writes the result to the output stream.- Parameters:
inputStream- The input stream to read data from.outputStream- The output stream to write data to.- Throws:
IOException- If an I/O error occurs during the execution of the command.
-
commandName
Returns a best-effort human-readable name for this command.Synthetic and anonymous implementations fall back to
IStreamCommandso diagnostics remain stable even when the concrete class name is not meaningful.- Returns:
- command label suitable for logging and error messages
-
withLogging
Wraps this command with logging. The returned command logs start, completion, and failure using the provided logger.The command name is derived by
commandName(). When a caller wants a different label in logs, preferwithLogging(Logger, String).- Parameters:
logger- the logger to write messages to- Returns:
- a new
IStreamCommandthat delegates to this command and emits log records
-
withLogging
Wraps this command with logging using an explicit command name.This overload is recommended when the command is implemented as a lambda expression or method reference, where the underlying class name might be synthetic and not meaningful in logs.
- Parameters:
logger- the logger to write messages tocommandName- the human-readable name of this command to appear in log messages- Returns:
- a new
IStreamCommandthat delegates to this command and emits log records
-