dk.netarkivet.common.distribute
Class ExtendedFTPRemoteFile

java.lang.Object
  extended by dk.netarkivet.common.distribute.ExtendedFTPRemoteFile
All Implemented Interfaces:
RemoteFile, java.io.Serializable

public class ExtendedFTPRemoteFile
extends java.lang.Object
implements RemoteFile

This class extends the functionality of FTPRemoteFile by allowing local input to be taken from an ArchiveRecord. It has factory methods which return an instance of FTPRemoteFile when a File is used as input so that behaviour is effectively delegated to that class when required.

See Also:
Serialized Form

Method Summary
 void appendTo(java.io.OutputStream out)
          Write the contents of this remote file to an output stream.
 void cleanup()
          The cleanup to be effected is deletion of the intermediate file from the ftp server.
 void copyTo(java.io.File destFile)
          Copy remotefile to local disk storage.
 java.lang.String getChecksum()
          Checksums are not available in this implementation.
 java.io.InputStream getInputStream()
          Get an inputstream that contains the data transferred in this RemoteFile.
static RemoteFile getInstance(org.archive.io.ArchiveRecord record)
          Create an instance of this class connected to an ARC or WARC record.
static RemoteFile getInstance(org.archive.io.arc.ARCRecord record)
          Create an instance of this class connected to an ARCRecord.
static RemoteFile getInstance(java.io.File localFile, java.lang.Boolean useChecksums, java.lang.Boolean fileDeletable, java.lang.Boolean multipleDownloads)
          This method returns an instance of FTPRemoteFile using the factory method with the same signature in that class.
static RemoteFile getInstance(java.io.File localFile, java.lang.Boolean useChecksums, java.lang.Boolean fileDeletable, java.lang.Boolean multipleDownloads, RemoteFileSettings connectionParams)
          This method returns an instance of FTPRemoteFile using the factory method with the same signature in that class.
static RemoteFile getInstance(org.archive.io.warc.WARCRecord record)
          Create an instance of this class connected to a WARCRecord.
 java.lang.String getName()
          Return the file name.
 long getSize()
          For an ARCRecord, this is the length of the record as defined in the header.
 java.lang.String toString()
          A human readbale description of the object which should be sufficient to identify and track it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

getInstance

public static RemoteFile getInstance(org.archive.io.ArchiveRecord record)
Create an instance of this class connected to an ARC or WARC record. Unfortunately the reflection we use to find the factory method cannot find this method directly because the runtime-class of the parameter is not ArchiveRecord. Therefore we also define the two specific overloaded factory methods for ARCRecords and WARCRecord.

Parameters:
record - the record
Returns:
the instance

getInstance

public static RemoteFile getInstance(org.archive.io.arc.ARCRecord record)
Create an instance of this class connected to an ARCRecord.

Parameters:
record - the record
Returns:
the instance

getInstance

public static RemoteFile getInstance(org.archive.io.warc.WARCRecord record)
Create an instance of this class connected to a WARCRecord.

Parameters:
record - the record
Returns:
the instance

getInstance

public static RemoteFile getInstance(java.io.File localFile,
                                     java.lang.Boolean useChecksums,
                                     java.lang.Boolean fileDeletable,
                                     java.lang.Boolean multipleDownloads)
                              throws IOFailure
This method returns an instance of FTPRemoteFile using the factory method with the same signature in that class.

Parameters:
localFile - File object for the remote file
useChecksums - If true, checksums will be used to check transfers.
fileDeletable - If true, this file will be deleted after upload to FTP.
multipleDownloads - If true, the file will not be removed from FTP server automatically after first download.
Returns:
FTPRemoteFile object
Throws:
IOFailure - if FTPRemoteFile creation fails

getInstance

public static RemoteFile getInstance(java.io.File localFile,
                                     java.lang.Boolean useChecksums,
                                     java.lang.Boolean fileDeletable,
                                     java.lang.Boolean multipleDownloads,
                                     RemoteFileSettings connectionParams)
                              throws IOFailure
This method returns an instance of FTPRemoteFile using the factory method with the same signature in that class.

Parameters:
localFile - File object for the remote file
useChecksums - If true, checksums will be used to check transfers.
fileDeletable - If true, this file will be deleted after upload to FTP.
multipleDownloads - If true, the file will not be removed from FTP server automatically after first download.
Returns:
FTPRemoteFile object
Throws:
IOFailure - if FTPRemoteFile creation fails

copyTo

public void copyTo(java.io.File destFile)
Description copied from interface: RemoteFile
Copy remotefile to local disk storage. Used by the data recipient

Specified by:
copyTo in interface RemoteFile
Parameters:
destFile - local File

appendTo

public void appendTo(java.io.OutputStream out)
Description copied from interface: RemoteFile
Write the contents of this remote file to an output stream.

Specified by:
appendTo in interface RemoteFile
Parameters:
out - OutputStream that the data will be written to. This stream will not be closed by this operation.

getInputStream

public java.io.InputStream getInputStream()
Description copied from interface: RemoteFile
Get an inputstream that contains the data transferred in this RemoteFile.

Specified by:
getInputStream in interface RemoteFile
Returns:
A stream object with the data in the object. Note that the close() method of this may throw exceptions if e.g. a transmission error is detected.

getName

public java.lang.String getName()
Description copied from interface: RemoteFile
Return the file name.

Specified by:
getName in interface RemoteFile
Returns:
the file name

getChecksum

public java.lang.String getChecksum()
Checksums are not available in this implementation. Returns null.

Specified by:
getChecksum in interface RemoteFile
Returns:
null

cleanup

public void cleanup()
The cleanup to be effected is deletion of the intermediate file from the ftp server.

Specified by:
cleanup in interface RemoteFile

getSize

public long getSize()
For an ARCRecord, this is the length of the record as defined in the header. For a WARCRecods, this is the payload length, defined as the difference between the total record length and the size of the header.

Specified by:
getSize in interface RemoteFile
Returns:
the length of the record content in bytes.

toString

public java.lang.String toString()
A human readbale description of the object which should be sufficient to identify and track it.

Overrides:
toString in class java.lang.Object
Returns:
description of this object.