TrueZIP Samples 7.1

de.schlichtherle.truezip.sample.file.app
Class Application

java.lang.Object
  extended by de.schlichtherle.truezip.file.TApplication<RuntimeException>
      extended by de.schlichtherle.truezip.sample.file.app.Application
Direct Known Subclasses:
Decrypt, Encrypt, Nzip, PathCat, UriCat

@DefaultAnnotation(value=edu.umd.cs.findbugs.annotations.NonNull.class)
abstract class Application
extends TApplication<RuntimeException>

Abstract base class for command line utilities.

Author:
Christian Schlichtherle

Nested Class Summary
protected static class Application.IllegalUsageException
          Indicates illegal application parameters.
protected static class Application.ProgressMonitor
          Monitors progress when committing unsynchronized changes to the contents of archive files.
 
Field Summary
protected  PrintStream err
          The print stream for error output.
protected  Application.ProgressMonitor monitor
          A progress monitor for TFile.umount().
protected  PrintStream out
          The print stream for standard output.
 
Constructor Summary
protected Application()
          Equivalent to Application(System.out, System.err, true).
protected Application(OutputStream out, OutputStream err, boolean autoFlush)
          Constructs a new command line utility instance.
 
Method Summary
protected abstract  int runChecked(String[] args)
          Runs this command line utility.
protected  void setup()
          Runs the setup phase.
protected  void sync()
           
protected  int work(String[] args)
          Runs the work phase by calling runChecked(java.lang.String[]).
 
Methods inherited from class de.schlichtherle.truezip.file.TApplication
run
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

out

protected final PrintStream out
The print stream for standard output.


err

protected final PrintStream err
The print stream for error output.


monitor

protected final Application.ProgressMonitor monitor
A progress monitor for TFile.umount().

Constructor Detail

Application

protected Application()
Equivalent to Application(System.out, System.err, true).


Application

protected Application(OutputStream out,
                      OutputStream err,
                      boolean autoFlush)
Constructs a new command line utility instance.

Note that this constructor has side effects:

Parameters:
out - the standard output stream.
err - the error output stream.
autoFlush - if the output streams are not PrintStreams, then they are wrapped in a new PrintStream with this as the additional constructor parameter.
Method Detail

setup

protected void setup()
Runs the setup phase.

This method is run only once at the start of the life cycle. Its task is to configure the default behavior of the TrueZIP File* API in order to answer the following questions:

The implementation in the class Application configures the type of the feedback when prompting the user for keys for RAES encrypted ZIP alias ZIP.RAES alias TZP files by the Swing based prompting key manager. If this JVM is running in headless mode, then this configuration is ignored and the user is prompted by the console I/O based prompting key manager.

Overrides:
setup in class TApplication<RuntimeException>

work

protected final int work(String[] args)
Runs the work phase by calling runChecked(java.lang.String[]). Prints a user readable error message to the error output stream which was provided to the constructor if an occurs.

This method is run at least once and repeatedly called until runChecked(java.lang.String[]) returns a non-negative integer for use as the exist status of the VM. After this method, the sync() method is called in a finally-block.

Specified by:
work in class TApplication<RuntimeException>
Parameters:
args - an array of arguments for this command line utility.
Returns:
A negative integer in order to continue calling this method in a loop. Otherwise, the return value is used as the exit status of the VM.
Throws:
RuntimeException - at the discretion of runChecked(java.lang.String[]).

runChecked

protected abstract int runChecked(String[] args)
                           throws Exception
Runs this command line utility. Throws an exception if an error occurs.

Avoid repeating this method and updating the same archive file upon each call! This would degrade the overall performance from O(n) to O(m*n), where m is the number of new or modified entries and n is the number of all entries in the archive file!

Parameters:
args - an array of arguments for this command line utility.
Returns:
A negative integer in order to continue calling this method in a loop. Otherwise, the return value is used as the exit status of the VM.
Throws:
Application.IllegalUsageException - on any exception.
Exception

sync

protected void sync()
             throws FsSyncException
Overrides:
sync in class TApplication<RuntimeException>
Throws:
FsSyncException

TrueZIP Samples 7.1

Copyright © 2005-2011 Schlichtherle IT Services. All Rights Reserved.