org.schmant.task.stub
Class AbstractProcessOneFileTask<T extends AbstractProcessOneFileTask<T>>

java.lang.Object
  extended by org.schmant.support.AbstractArgumentChecker
      extended by org.schmant.task.stub.AbstractTask<T>
          extended by org.schmant.task.stub.AbstractActionTask<T>
              extended by org.schmant.task.stub.AbstractProcessTask<T>
                  extended by org.schmant.task.stub.AbstractProcessOneFileTask<T>
All Implemented Interfaces:
Producer<WritableFile>, TaskDependency, ActionTaskConfigurable<T>, ActionTaskSpec<T>, LoggingConfigurable<T>, OverwriteConfigurable<T>, SourceConfigurable<T>, SourceConfigured, TargetConfigurable<T>, TargetConfigured, GeneratorTaskConfigurable<T>, GeneratorTaskSpec<T>, ProcessTaskConfigurable<T>, ProcessTaskSpec<T>, Task, TaskRunnable, TaskSpecification<T>
Direct Known Subclasses:
BZip2Task, GZipTask, LzmaTask

public abstract class AbstractProcessOneFileTask<T extends AbstractProcessOneFileTask<T>>
extends AbstractProcessTask<T>
implements Producer<WritableFile>

This is an abstract implementation of a task that reads the contents of one file, processes it in some way and then writes it to a target file.

The contents are processed by proxying the output stream used to write to the target file.

This object implements the Producer interface. The generated object is the interpreted target object, so its type depends on the type of target that is used.

Since:
0.8
Author:
Karl Gustafsson

Field Summary
 
Fields inherited from interface org.schmant.task.confable.OverwriteConfigurable
DEFAULT_OVERWRITE_STRATEGY
 
Constructor Summary
AbstractProcessOneFileTask()
           
 
Method Summary
 void copyProperties(T spec)
          Override the implementation from AbstractTask to copy the source properties.
 WritableFile get()
          Returns the produced object, or null if nothing is produced yet.
protected abstract  String getDefaultTargetFileExtension()
          Subclasses implement this to return the default file extension for target files (such as ".gz").
protected  boolean isTargetMandatory()
          If the target is not set it can be inferred from the source entity.
protected abstract  OutputStream proxyOutputStream(OutputStream os)
           
protected  void runInternal(Report r)
          Subclasses implement this.
 void setDeleteSourceFile(boolean b)
          Set to true to delete the source file after processing it.
 
Methods inherited from class org.schmant.task.stub.AbstractProcessTask
getOverwriteStrategy, getTarget, setOverwrite, setOverwriteStrategy, setTarget, toString, validate
 
Methods inherited from class org.schmant.task.stub.AbstractActionTask
addSource, addSources, clearSources, getRelativeToBase, getSource, getSources, isMoreThanOneSourceAllowed, isSourcesMandatory, setRelativeToBase, setSource, setSources
 
Methods inherited from class org.schmant.task.stub.AbstractTask
cancel, createTask, getDefaultLogFooter, getDefaultLogHeader, getDependencyForTasksScheduledByThisTask, getDependencyObservable, getFailureCause, getLogFooter, getLogHeader, getSatisfiedStateLock, getThis, isCancelled, isDone, isInterrupted, isRunning, isSatisfied, isSuccessful, run, setLogFooter, setLogHeader, setReportLevel, setTraceLogging
 
Methods inherited from class org.schmant.support.AbstractArgumentChecker
check, check, check, check
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.schmant.task.confable.SourceConfigurable
addSource, addSources, clearSources, setRelativeToBase, setSource, setSources
 
Methods inherited from interface org.schmant.task.confable.SourceConfigured
getSource, getSources
 
Methods inherited from interface org.schmant.task.TaskSpecification
createTask
 
Methods inherited from interface org.schmant.task.confable.LoggingConfigurable
setLogFooter, setLogHeader, setReportLevel, setTraceLogging
 

Constructor Detail

AbstractProcessOneFileTask

public AbstractProcessOneFileTask()
Method Detail

proxyOutputStream

protected abstract OutputStream proxyOutputStream(OutputStream os)
                                           throws IOException
Throws:
IOException

isTargetMandatory

protected boolean isTargetMandatory()
If the target is not set it can be inferred from the source entity.

Overrides:
isTargetMandatory in class AbstractProcessTask<T extends AbstractProcessOneFileTask<T>>
Returns:
true, always

setDeleteSourceFile

public void setDeleteSourceFile(boolean b)
Set to true to delete the source file after processing it. This requires that the source file is a file entity. Otherwise an warning will be logged.

The default behavior is to not delete the source file.

Parameters:
b - Should the source file be deleted?

get

public final WritableFile get()
Description copied from interface: Producer
Returns the produced object, or null if nothing is produced yet.

This method should be implemented thread-safe.

Specified by:
get in interface Producer<WritableFile>
Returns:
The produced object.

getDefaultTargetFileExtension

protected abstract String getDefaultTargetFileExtension()
Subclasses implement this to return the default file extension for target files (such as ".gz"). This is used when inferring the target entity.

Returns:
The default target file name extension.
Since:
1.0.1

runInternal

protected final void runInternal(Report r)
                          throws TaskFailedException
Description copied from class: AbstractTask
Subclasses implement this. The task is AbstractTask.validate(Report):d before this method is called, see AbstractTask.run().

Specified by:
runInternal in class AbstractTask<T extends AbstractProcessOneFileTask<T>>
Parameters:
r - The current thread's Report.
Throws:
TaskFailedException

copyProperties

public void copyProperties(T spec)
Description copied from class: AbstractActionTask
Override the implementation from AbstractTask to copy the source properties. Subclasses must override this to copy their own properties.

Specified by:
copyProperties in interface TaskSpecification<T extends AbstractProcessOneFileTask<T>>
Overrides:
copyProperties in class AbstractProcessTask<T extends AbstractProcessOneFileTask<T>>
Parameters:
spec - The specification to copy properties to.