001package com.streamconverter.command.impl; 002 003import com.streamconverter.command.AbstractStreamCommand; 004import java.io.IOException; 005import java.io.InputStream; 006import java.io.OutputStream; 007import java.util.Objects; 008 009/** 010 * SampleStreamCommand is a concrete implementation of AbstractStreamCommand. 011 * 012 * <p>This command reads data from an input stream and writes it to an output stream. 013 */ 014public class SampleStreamCommand extends AbstractStreamCommand { 015 016 private String id; 017 018 /** Default constructor that initializes the command with a default ID. */ 019 public SampleStreamCommand() { 020 this.id = "default"; 021 } 022 023 /** 024 * Constructor that initializes the command with a specific ID. 025 * 026 * @param arg The ID to be assigned to this command. 027 * @throws NullPointerException if arg is null 028 */ 029 public SampleStreamCommand(String arg) { 030 this.id = Objects.requireNonNull(arg, "ID cannot be null"); 031 } 032 033 /** 034 * Executes the command on the provided input stream and writes the result to the output stream. 035 * 036 * @param inputStream The input stream to read data from. 037 * @param outputStream The output stream to write data to. 038 * @throws IOException If an I/O error occurs during the execution of the command. 039 */ 040 @Override 041 public void executeInternal(InputStream inputStream, OutputStream outputStream) 042 throws IOException { 043 Objects.requireNonNull(inputStream); 044 Objects.requireNonNull(outputStream); 045 inputStream.transferTo(outputStream); 046 } 047 048 @Override 049 public String toString() { 050 return "SampleStreamCommand [id=" + id + "]"; 051 } 052}