org.at4j.comp.prog
Class AbstractStreamCompressionProgram<T extends StreamCompressionProgramArguments>

java.lang.Object
  extended by org.at4j.support.prog.AbstractProgram
      extended by org.at4j.comp.prog.AbstractStreamCompressionProgram<T>
Type Parameters:
T - The class containing the parsed command line arguments for the command.
Direct Known Subclasses:
BUnzip2, BZip2

public abstract class AbstractStreamCompressionProgram<T extends StreamCompressionProgramArguments>
extends AbstractProgram

An abstract base class for compression programs that use streams to compress and decompress data.

Since:
1.0
Author:
Karl Gustafsson

Constructor Summary
AbstractStreamCompressionProgram()
           
 
Method Summary
protected abstract  InputStream createInputStream(int sourceNo, T settings)
          Create an input stream on the source entity for the given command line arguments.
protected abstract  OutputStream createOutputStream(int targetNo, T settings)
          Create an output stream on the target entity for the given command line arguments.
protected abstract  T parseCommandLine(String[] args)
          Subclasses implement this to parse their command line.
protected  void postProcess(int sourceNo, T settings)
          Subclasses may override this for postprocessing the source and/or target entity.
protected  void run(String[] args)
           
 
Methods inherited from class org.at4j.support.prog.AbstractProgram
getArg, getParentLocation, isFlagArgument
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractStreamCompressionProgram

public AbstractStreamCompressionProgram()
Method Detail

parseCommandLine

protected abstract T parseCommandLine(String[] args)
                                                                         throws CommandErrorException
Subclasses implement this to parse their command line.

Parameters:
args - The command line arguments, unparsed.
Returns:
The command line arguments, parsed.
Throws:
CommandErrorException - If the commands were invalid.

createInputStream

protected abstract InputStream createInputStream(int sourceNo,
                                                 T settings)
                                          throws IOException,
                                                 IgnoreFileException
Create an input stream on the source entity for the given command line arguments.

Parameters:
sourceNo - The index number for the source entity. The first source has index == 0.
settings - The command line arguments.
Returns:
An input stream on the source.
Throws:
IOException - On I/O errors.
IgnoreFileException - If the file should be ignored for some reason.

createOutputStream

protected abstract OutputStream createOutputStream(int targetNo,
                                                   T settings)
                                            throws IOException,
                                                   IgnoreFileException
Create an output stream on the target entity for the given command line arguments.

Parameters:
targetNo - The index number for the target entity. The first target has index == 0.
settings - The command line arguments.
Returns:
An output stream on the target.
Throws:
IOException - On I/O errors.
IgnoreFileException - If the file should be ignored for some reason.

postProcess

protected void postProcess(int sourceNo,
                           T settings)
                    throws IOException
Subclasses may override this for postprocessing the source and/or target entity. This implementation does not do anything.

Parameters:
sourceNo - The index number for the source and target entities.
settings - The command line arguments.
Throws:
IOException - On I/O errors.

run

protected void run(String[] args)
            throws CommandErrorException,
                   IOException
Throws:
CommandErrorException
IOException