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

public abstract class AbstractStreamCommand extends Object implements IStreamCommand
Abstract class for stream commands.

This class provides a template for executing commands on input streams and writing the results to output streams.

  • Field Details

    • log

      protected final org.slf4j.Logger log
      Logger instance for this command. Uses the actual subclass name for better traceability.
  • Constructor Details

    • 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:
      execute in interface IStreamCommand
      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

      public final void execute(InputStream inputStream, OutputStream outputStream) throws IOException
      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:
      execute in interface IStreamCommand
      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:
      コマンドの詳細情報