org.at4j.comp.bzip2.prog
Class BZip2

java.lang.Object
  extended by org.at4j.support.prog.AbstractProgram
      extended by org.at4j.comp.prog.AbstractStreamCompressionProgram<T>
          extended by org.at4j.comp.bzip2.prog.BZip2

public final class BZip2
extends AbstractStreamCompressionProgram<T>

This runnable class emulates the bzip2 command. It understands a subset of bzip2's command line arguments.

The program compresses one or several files. A file is compressed to a new file with ".bz2" added to the name of the original file. The original file is deleted after it has been successfully compressed.

 Usage:
   java -cp [classpath] org.at4j.comp.bzip2.prog.BZip2 [options] file[s]
 Where:
   classpath - Should include the at4j, bzip2 and entityfs-core Jars.
   options   - Command options. See below.
   file[s]   - The files to compress.
 Options:
   -1 (or --fast) to -9 (or --best)
             - Set the block size to 100 kb, 200 kb ... 900 kb when
               compressing. Default is --best.
   --apache  - Use Apache Commons Compress' bzip2 implementation instead of
               At4J's
   -c        - Write the compressed data to standard output and do not delete
               the original files.
   --decompress
   --uncompress
   -d        - Decompress files (instead of compressing them).
   --encoderThreads no - Set the number of encoder threads to use for each
               file. The default number of encoder threads is zero, which
               means that each file is encoded by the thread that writes it.
   --keep
   -k        - Don't delete the original files.
   --suffix suf
   -S suf    - Use the suffix "suf" instead of ".bz2" for the compressed files.
   --threads no - Set the maximum number of threads to use for compressing.
               Different files may be compressed in different threads. The
               default number of threads is one.
   --timing  - After building the archive, print out how long it took.
 

Since:
1.0
Author:
Karl Gustafsson
See Also:
BUnzip2

Constructor Summary
BZip2()
           
 
Method Summary
protected  InputStream createInputStream(int sourceNo, T settings)
          Create an input stream on the source entity for the given command line arguments.
protected  OutputStream createOutputStream(int targetNo, T settings)
          Create an output stream on the target entity for the given command line arguments.
static void main(String[] args)
           
protected  org.at4j.comp.bzip2.prog.BZip2CommandLineArguments 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.
 
Methods inherited from class org.at4j.comp.prog.AbstractStreamCompressionProgram
run
 
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

BZip2

public BZip2()
Method Detail

parseCommandLine

protected org.at4j.comp.bzip2.prog.BZip2CommandLineArguments parseCommandLine(String[] args)
                                                                       throws CommandErrorException
Description copied from class: AbstractStreamCompressionProgram
Subclasses implement this to parse their command line.

Specified by:
parseCommandLine in class AbstractStreamCompressionProgram<org.at4j.comp.bzip2.prog.BZip2CommandLineArguments>
Parameters:
args - The command line arguments, unparsed.
Returns:
The command line arguments, parsed.
Throws:
CommandErrorException - If the commands were invalid.

main

public static void main(String[] args)

createInputStream

protected InputStream createInputStream(int sourceNo,
                                        T settings)
                                 throws IOException
Description copied from class: AbstractStreamCompressionProgram
Create an input stream on the source entity for the given command line arguments.

Specified by:
createInputStream in class AbstractStreamCompressionProgram<T extends org.at4j.comp.bzip2.prog.AbstractBZip2ProgramArguments>
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.

createOutputStream

protected OutputStream createOutputStream(int targetNo,
                                          T settings)
                                   throws IOException,
                                          IgnoreFileException
Description copied from class: AbstractStreamCompressionProgram
Create an output stream on the target entity for the given command line arguments.

Specified by:
createOutputStream in class AbstractStreamCompressionProgram<T extends org.at4j.comp.bzip2.prog.AbstractBZip2ProgramArguments>
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
Description copied from class: AbstractStreamCompressionProgram
Subclasses may override this for postprocessing the source and/or target entity. This implementation does not do anything.

Overrides:
postProcess in class AbstractStreamCompressionProgram<T extends org.at4j.comp.bzip2.prog.AbstractBZip2ProgramArguments>
Parameters:
sourceNo - The index number for the source and target entities.
settings - The command line arguments.
Throws:
IOException - On I/O errors.