com.mucommander.job
Class TransferFileJob

java.lang.Object
  extended by com.mucommander.job.FileJob
      extended by com.mucommander.job.TransferFileJob
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
AbstractCopyJob, ArchiveJob, CalculateChecksumJob, SendMailJob

public abstract class TransferFileJob
extends FileJob

TransferFileJob is a container for a file task : basically an operation that involves files and bytes.

What makes TransferFileJob different from FileJob (and explains its very inspired name) is that a class implementing TransferFileJob has to be able to give progress information about the file currently being processed.

Author:
Maxence Bernard

Field Summary
 
Fields inherited from class com.mucommander.job.FileJob
APPEND_ACTION, APPEND_TEXT, baseSourceFolder, CANCEL_ACTION, CANCEL_TEXT, currentFile, currentFileIndex, currentFilename, files, FINISHED, INTERRUPTED, mainFrame, nbFiles, NOT_STARTED, PAUSED, progressDialog, RETRY_ACTION, RETRY_TEXT, RUNNING, SKIP_ACTION, SKIP_TEXT
 
Constructor Summary
TransferFileJob(ProgressDialog progressDialog, MainFrame mainFrame, FileSet files)
          Creates a new TransferFileJob.
 
Method Summary
protected  void closeCurrentInputStream()
          Closes the currently registered source InputStream.
protected  void copyFile(AbstractFile sourceFile, AbstractFile destFile, boolean append)
          Copies the given source file to the specified destination file, optionally resuming the operation.
 ByteCounter getCurrentFileByteCounter()
          Returns the number of bytes that have been processed in the current file.
 long getCurrentFileSize()
          Returns the size of the file currently being processed, -1 if this information is not available.
 ByteCounter getCurrentFileSkippedByteCounter()
          Returns the number of bytes that have been skipped in the current file.
 float getFilePercentDone()
          Returns the percentage of the current file that has been processed, 0 if the current file's size is not available (in this case getNbCurrentFileBytesProcessed() returns -1).
 java.lang.String getStatusString()
          This method is overridden to return a custom string "Checking integrity of CURRENT_FILE" when the current file is being checked for integrity.
 long getThroughputLimit()
          Returns the current transfer throughput limit, in bytes per second.
 ByteCounter getTotalByteCounter()
          Returns a ByteCounter that holds the total number of bytes that have been processed by this job so far.
 float getTotalPercentDone()
          Method overridden to return a more accurate percentage of job processed so far by taking into account the current file's percentage of completion.
 ByteCounter getTotalSkippedByteCounter()
          Returns a ByteCounter that holds the total number of bytes that have been skipped by this job so far.
protected  boolean isCheckingIntegrity()
          Returns true if the integrity of the current file is being verified.
 boolean isIntegrityCheckEnabled()
          Returns true if file transfers need to be checked for data integrity.
protected  void jobPaused()
          Overrides FileJob.jobPaused() to pause any file processing by having the source InputStream's read methods lock.
protected  void jobResumed()
          Overrides FileJob.jobResumed() to resume any file processing by releasing the lock on the source InputStream's read methods.
protected  void jobStopped()
          Overrides FileJob.jobStopped() to stop any file processing by closing the source InputStream.
protected  void nextFile(AbstractFile file)
          Advances file index and resets current file's byte counters.
protected  java.io.InputStream setCurrentInputStream(java.io.InputStream in)
          Registers the given InputStream as currently in use, in order to: count the number of bytes that have been read from it (see getCurrentFileByteCounter()) block read methods calls when the job is paused limit the throughput if a limit has been specified (see setThroughputLimit(long)) close the InputStream when the job is stopped
 void setIntegrityCheckEnabled(boolean integrityCheckEnabled)
          Specifies if file transfers need to be checked for data integrity.
 void setThroughputLimit(long bytesPerSecond)
          Sets a transfer throughput limit in bytes per seconds, replacing any previous limit.
 void skipCurrentFile()
          Interrupts the current file transfer and advance to the next one.
protected  boolean tryCopyFile(AbstractFile sourceFile, AbstractFile destFile, boolean append, java.lang.String errorDialogTitle)
          Tries to copy the given source file to the specified destination file (see copyFile(AbstractFile,AbstractFile,boolean) displaying a generic error dialog #showErrorDialog() if something went wrong, and giving the user the choice to skip the file, retry or cancel.
 boolean wasCurrentFileSkipped()
          Return true if the file that is currently being processed has been skipped.
 
Methods inherited from class com.mucommander.job.FileJob
addFileJobListener, getCurrentFileIndex, getCurrentFilename, getEffectiveJobTime, getEndDate, getNbFiles, getPausedTime, getPauseStartDate, getStartDate, getState, hasFolderChanged, interrupt, jobCompleted, jobStarted, processFile, refreshTables, removeFileJobListener, run, selectFileWhenFinished, setAutoUnmark, setPaused, setState, showErrorDialog, showErrorDialog, start, waitForUserResponse
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TransferFileJob

public TransferFileJob(ProgressDialog progressDialog,
                       MainFrame mainFrame,
                       FileSet files)
Creates a new TransferFileJob.

Method Detail

copyFile

protected void copyFile(AbstractFile sourceFile,
                        AbstractFile destFile,
                        boolean append)
                 throws FileTransferException
Copies the given source file to the specified destination file, optionally resuming the operation. As much as the source and destination protocols allow, the source file's date and permissions will be preserved.

Throws:
FileTransferException

tryCopyFile

protected boolean tryCopyFile(AbstractFile sourceFile,
                              AbstractFile destFile,
                              boolean append,
                              java.lang.String errorDialogTitle)
Tries to copy the given source file to the specified destination file (see copyFile(AbstractFile,AbstractFile,boolean) displaying a generic error dialog #showErrorDialog() if something went wrong, and giving the user the choice to skip the file, retry or cancel.

Returns:
true if the file was properly copied, false if the transfer was interrupted / aborted by the user

setCurrentInputStream

protected java.io.InputStream setCurrentInputStream(java.io.InputStream in)
Registers the given InputStream as currently in use, in order to:

This method should be called by subclasses when creating a new InputStream, before the InputStream is used.

Parameters:
in - the InputStream to be used
Returns:
the 'augmented' InputStream using the given stream as the underlying InputStream

closeCurrentInputStream

protected void closeCurrentInputStream()
Closes the currently registered source InputStream.


isIntegrityCheckEnabled

public boolean isIntegrityCheckEnabled()
Returns true if file transfers need to be checked for data integrity. In this case, the checksum of the source and destination files are both calculated and compared to verify they match.

Returns:
true if file transfers need to be checked for data integrity

setIntegrityCheckEnabled

public void setIntegrityCheckEnabled(boolean integrityCheckEnabled)
Specifies if file transfers need to be checked for data integrity. If true is specified, the checksum of the source and destination files will both be calculated and compared to verify they match.

Parameters:
integrityCheckEnabled - true if file transfers need to be checked for data integrity

isCheckingIntegrity

protected boolean isCheckingIntegrity()
Returns true if the integrity of the current file is being verified.

Returns:
true if the integrity of the current file is being verified

skipCurrentFile

public void skipCurrentFile()
Interrupts the current file transfer and advance to the next one.


wasCurrentFileSkipped

public boolean wasCurrentFileSkipped()
Return true if the file that is currently being processed has been skipped.

Returns:
true if the file that is currently being processed has been skipped

getFilePercentDone

public float getFilePercentDone()
Returns the percentage of the current file that has been processed, 0 if the current file's size is not available (in this case getNbCurrentFileBytesProcessed() returns -1).

Returns:
the percentage of the current file that has been processed

getCurrentFileByteCounter

public ByteCounter getCurrentFileByteCounter()
Returns the number of bytes that have been processed in the current file.

Returns:
the number of bytes that have been processed in the current file

getCurrentFileSkippedByteCounter

public ByteCounter getCurrentFileSkippedByteCounter()
Returns the number of bytes that have been skipped in the current file. Bytes are skipped when file transfers are resumed.

Returns:
the number of bytes that have been skipped in the current file

getCurrentFileSize

public long getCurrentFileSize()
Returns the size of the file currently being processed, -1 if this information is not available.

Returns:
the size of the file currently being processed, -1 if this information is not available.

getTotalByteCounter

public ByteCounter getTotalByteCounter()
Returns a ByteCounter that holds the total number of bytes that have been processed by this job so far.

Returns:
a ByteCounter that holds the total number of bytes that have been processed by this job so far

getTotalSkippedByteCounter

public ByteCounter getTotalSkippedByteCounter()
Returns a ByteCounter that holds the total number of bytes that have been skipped by this job so far. Bytes are skipped when file transfers are resumed.

Returns:
a ByteCounter that holds the total number of bytes that have been skipped by this job so far

setThroughputLimit

public void setThroughputLimit(long bytesPerSecond)
Sets a transfer throughput limit in bytes per seconds, replacing any previous limit. This limit corresponds to the number of bytes that can be read from a registered InputStream.

Specifying 0 or -1 disables any throughput limit, the transfer will be carried out at full speed.

If this job is paused, the new limit will be effective after the job has been resumed. If not, it will be effective immediately.

Parameters:
bytesPerSecond - new throughput limit in bytes per second, 0 or -1 to disable the limit

getThroughputLimit

public long getThroughputLimit()
Returns the current transfer throughput limit, in bytes per second. 0 or -1 means that there currently is no limit to the attainable transfer speed (full speed).

Returns:
the current transfer throughput limit, in bytes per second

jobStopped

protected void jobStopped()
Overrides FileJob.jobStopped() to stop any file processing by closing the source InputStream.

Overrides:
jobStopped in class FileJob

jobPaused

protected void jobPaused()
Overrides FileJob.jobPaused() to pause any file processing by having the source InputStream's read methods lock.

Overrides:
jobPaused in class FileJob

jobResumed

protected void jobResumed()
Overrides FileJob.jobResumed() to resume any file processing by releasing the lock on the source InputStream's read methods.

Overrides:
jobResumed in class FileJob

nextFile

protected void nextFile(AbstractFile file)
Advances file index and resets current file's byte counters. This method should be called by subclasses whenever the job starts processing a new file.

Overrides:
nextFile in class FileJob

getTotalPercentDone

public float getTotalPercentDone()
Method overridden to return a more accurate percentage of job processed so far by taking into account the current file's percentage of completion.

Overrides:
getTotalPercentDone in class FileJob
Returns:
this job's percentage of completion, as a float comprised between 0 and 1

getStatusString

public java.lang.String getStatusString()
This method is overridden to return a custom string "Checking integrity of CURRENT_FILE" when the current file is being checked for integrity.

Overrides:
getStatusString in class FileJob
Returns:
a String describing what the job is currently doing


This file is part of muCommander - Copyright (C) 2002-2008 Maxence Bernard