dk.netarkivet.common.distribute
Class AbstractRemoteFile

java.lang.Object
  extended by dk.netarkivet.common.distribute.AbstractRemoteFile
All Implemented Interfaces:
RemoteFile, java.io.Serializable
Direct Known Subclasses:
FTPRemoteFile, HTTPRemoteFile

public abstract class AbstractRemoteFile
extends java.lang.Object
implements RemoteFile

Abstract superclass for easy implementation of remote file. Sub classes should override this class, and do the following: - Implement getChecksum. - Implement getInputStream. - Implement cleanup. - Add getInstance(File, Boolean, Boolean, Boolean)-method to make the file work with the factory.

See Also:
Serialized Form

Field Summary
protected  java.io.File file
          The file this is remote file for
protected  boolean fileDeletable
          If true, the file may be deleted after all transfers are done.
protected  long filesize
          The size of the file.
protected  boolean multipleDownloads
          If true, the file may be downloaded multiple times.
protected  boolean useChecksums
          If true, communication is checksummed.
 
Constructor Summary
AbstractRemoteFile(java.io.File file, boolean useChecksums, boolean fileDeletable, boolean multipleDownloads)
          Initialise common fields in remote file.
 
Method Summary
 void appendTo(java.io.OutputStream out)
          Append this remote file to the given output stream.
abstract  void cleanup()
          Invalidate all file handles.
 void copyTo(java.io.File destFile)
          Copy this remote file to the given file.
abstract  java.lang.String getChecksum()
          Get checksum for file, or null if checksums were not requested.
abstract  java.io.InputStream getInputStream()
          Get an input stream representing the remote file.
 java.lang.String getName()
          Get the name of the remote file.
abstract  int getNumberOfRetries()
          Method for retrieving the number of retries for retrieving a file.
 long getSize()
          Get the size of this remote file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

file

protected final java.io.File file
The file this is remote file for


useChecksums

protected final boolean useChecksums
If true, communication is checksummed.


fileDeletable

protected final boolean fileDeletable
If true, the file may be deleted after all transfers are done.


multipleDownloads

protected final boolean multipleDownloads
If true, the file may be downloaded multiple times. Otherwise, the remote file is invalidated after first transfer.


filesize

protected final long filesize
The size of the file.

Constructor Detail

AbstractRemoteFile

public AbstractRemoteFile(java.io.File file,
                          boolean useChecksums,
                          boolean fileDeletable,
                          boolean multipleDownloads)
Initialise common fields in remote file. Overriding classes should also initialise checksum field.

Parameters:
file - The file to make remote file for.
useChecksums - If true, communications should be checksummed.
fileDeletable - If true, the file may be downloaded multiple times. Otherwise, the remote file is invalidated after first transfer.
multipleDownloads - If useChecksums is true, contains the file checksum.
Method Detail

copyTo

public void copyTo(java.io.File destFile)
Copy this remote file to the given file. This method will make a fileoutputstream, and use appendTo to write the remote file to this stream.

Specified by:
copyTo in interface RemoteFile
Parameters:
destFile - The file to write the remote file to.
Throws:
ArgumentNotValid - on null destFile, or parent to destfile is not a writeable directory, or destfile exists and cannot be overwritten.
IOFailure - on I/O trouble writing remote file to destination.

appendTo

public void appendTo(java.io.OutputStream out)
Append this remote file to the given output stream. This method will use getInputStream to get the remote stream, and then copy that stream to the given output stream.

Specified by:
appendTo in interface RemoteFile
Parameters:
out - The stream to write the remote file to.
Throws:
ArgumentNotValid - if outputstream is null.
IOFailure - on I/O trouble writing remote file to stream.

getInputStream

public abstract java.io.InputStream getInputStream()
Get an input stream representing the remote file. The returned input stream should throw IOFailure on close, if checksums are requested, but do not match. The returned inputstream should call cleanup on close, if multipleDownloads is not true.

Specified by:
getInputStream in interface RemoteFile
Returns:
An input stream for the remote file.
Throws:
IOFailure - on I/O trouble generating inputstream for remote file.

getName

public java.lang.String getName()
Get the name of the remote file.

Specified by:
getName in interface RemoteFile
Returns:
The name of the remote file.

getChecksum

public abstract java.lang.String getChecksum()
Get checksum for file, or null if checksums were not requested.

Specified by:
getChecksum in interface RemoteFile
Returns:
checksum for file, or null if checksums were not requested.

cleanup

public abstract void cleanup()
Invalidate all file handles. If file is deletable, it should be deleted after this method is called. This method should never throw exceptions, but only log a warning on trouble. It should be idempotent, meaning it should be safe to call this method twice.

Specified by:
cleanup in interface RemoteFile

getNumberOfRetries

public abstract int getNumberOfRetries()
Method for retrieving the number of retries for retrieving a file.

Returns:
The number of retries for retrieving a file.

getSize

public long getSize()
Get the size of this remote file.

Specified by:
getSize in interface RemoteFile
Returns:
The size of this remote file.