Package com.streamconverter.command
Class AbstractStreamCommand
java.lang.Object
com.streamconverter.command.AbstractStreamCommand
- All Implemented Interfaces:
IStreamCommand
- Direct Known Subclasses:
CharacterConvertCommand,ConsumerCommand,ConvertCommand,CsvFilterCommand,CsvNavigateCommand,JsonFilterCommand,JsonNavigateCommand,LineEndingNormalizeCommand,PmdXmlToCsvCommand,PmdXmlToJsonCommand,PmdXmlToMarkdownCommand,SampleStreamCommand,SendHttpCommand,XmlFilterCommand,XmlNavigateCommand
Abstract class for stream commands.
This class provides a template for executing commands on input streams and writing the results to output streams.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final org.slf4j.LoggerLogger instance for this command. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal voidexecute(InputStream inputStream, OutputStream outputStream) Executes the command on the provided input stream and writes the result to the output stream.final voidexecute(InputStream inputStream, OutputStream outputStream, ExecutionContext context) Executes the command with ExecutionContext support.protected abstract voidexecuteInternal(InputStream inputStream, OutputStream outputStream) Abstract method to be implemented by subclasses for executing the command.protected Stringコマンドの詳細情報を取得します。
-
Field Details
-
log
Logger instance for this command. Uses the actual subclass name for better traceability.
-
-
Constructor Details
-
AbstractStreamCommand
public AbstractStreamCommand()Default constructor.Initializes the command with default settings and creates a logger using the actual command class name.
-
-
Method Details
-
execute
public final void execute(InputStream inputStream, OutputStream outputStream, ExecutionContext context) throws IOException Executes the command with ExecutionContext support.This override ensures that MDC is synchronized with the latest shared context values before logging, enabling cross-thread MDC propagation in parallel execution environments.
- Specified by:
executein interfaceIStreamCommand- Parameters:
inputStream- The input stream to read data from.outputStream- The output stream to write data to.context- The execution context for traceability and logging enhancement.- Throws:
IOException- If an I/O error occurs during the execution of the command.
-
execute
Executes the command on the provided input stream and writes the result to the output stream.This method automatically logs execution details including: - Command name and execution time - Input/output data sizes - Exception details if execution fails - Performance metrics
- Specified by:
executein interfaceIStreamCommand- 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.
-
executeInternal
protected abstract void executeInternal(InputStream inputStream, OutputStream outputStream) throws IOException Abstract method to be implemented by subclasses for executing the command.- 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.
-
getCommandDetails
コマンドの詳細情報を取得します。サブクラスでオーバーライドして、コマンド固有の設定や状態を返すことができます。 この情報はデバッグログに出力され、問題の診断に役立ちます。
- Returns:
- コマンドの詳細情報
-