Class AbstractStreamController

java.lang.Object
com.streamconverter.controller.AbstractStreamController
All Implemented Interfaces:
IStreamController
Direct Known Subclasses:
CsvProcessingController, JsonProcessingController, PmdAnalysisController

public abstract class AbstractStreamController extends Object implements IStreamController
Abstract base class for stream controllers.

This class provides common functionality for controllers including:

  • Command configuration and creation using CommandFactory
  • StreamConverter lifecycle management
  • Error handling and logging
  • Input/output validation

Subclasses need to implement the command configuration logic by overriding configureCommands() method. This allows each controller to define its specific processing pipeline while inheriting common functionality.

Example usage:

 public class CsvToJsonController extends AbstractStreamController {

     @Override
     protected CommandConfig[] configureCommands() {
         return new CommandConfig[] {
             new CommandConfig(CsvNavigateCommand.class, "Extract CSV data"),
             new CommandConfig(JsonFormatCommand.class, "Format as JSON")
         };
     }

     @Override
     public String getInputDataType() { return "CSV"; }

     @Override
     public String getOutputDataType() { return "JSON"; }
 }
 
Since:
1.0
Version:
1.0
Author:
StreamConverter Team
  • Constructor Details

    • AbstractStreamController

      Default constructor that initializes the controller.

      The controller will be configured lazily on first use to allow subclasses to complete their initialization.

  • Method Details

    • process

      public final List<CommandResult> process(InputStream inputStream, OutputStream outputStream) throws IOException
      Processes data from input stream to output stream using the configured command pipeline.

      This method ensures the controller is configured before processing and handles all error scenarios appropriately.

      Specified by:
      process in interface IStreamController
      Parameters:
      inputStream - the input stream to read data from
      outputStream - the output stream to write results to
      Returns:
      list of command execution results
      Throws:
      IOException - if an I/O error occurs during processing
      IllegalArgumentException - if input parameters are null
      IllegalStateException - if the controller cannot be configured
    • isConfigured

      public final boolean isConfigured()
      Checks if the controller is properly configured.
      Specified by:
      isConfigured in interface IStreamController
      Returns:
      true if configured, false otherwise
    • getConfigurationDescription

      Gets a description of the controller's current configuration.
      Specified by:
      getConfigurationDescription in interface IStreamController
      Returns:
      configuration description
    • configureCommands

      protected abstract CommandConfig[] configureCommands()
      Configures the command pipeline for this controller.

      Subclasses must implement this method to define their specific processing pipeline. The returned CommandConfig array will be used to create the actual command objects using EnhancedCommandFactory.

      Example implementation:

       @Override
       protected CommandConfig[] configureCommands() {
           return new CommandConfig[] {
               new CommandConfig(CsvNavigateCommand.class, "data", "Extract data column"),
               new CommandConfig(CsvValidateCommand.class, "Validate output", requiredColumns)
           };
       }
       
      Returns:
      array of command configurations defining the processing pipeline
      Throws:
      IllegalStateException - if the configuration is invalid
    • getCommandConfigs

      protected final CommandConfig[] getCommandConfigs()
      Gets the configured command configurations.

      This method is protected to allow subclasses access to the configuration for advanced scenarios while keeping it internal to the controller hierarchy.

      Returns:
      array of command configurations, or null if not yet configured
    • getStreamConverter

      Gets the configured StreamConverter instance.

      This method is protected to allow subclasses access to the StreamConverter for advanced scenarios while keeping it internal to the controller hierarchy.

      Returns:
      the StreamConverter instance, or null if not yet configured
    • validateConfiguration

      protected void validateConfiguration()
      Allows subclasses to perform additional validation after configuration.

      This method is called after the command pipeline is configured but before the controller is marked as ready. Subclasses can override this to add custom validation logic.

      Throws:
      IllegalStateException - if validation fails