Package dk.netarkivet.common.distribute
Class HTTPRemoteFile
- java.lang.Object
-
- dk.netarkivet.common.distribute.AbstractRemoteFile
-
- dk.netarkivet.common.distribute.HTTPRemoteFile
-
- All Implemented Interfaces:
RemoteFile
,Serializable
- Direct Known Subclasses:
HTTPSRemoteFile
,TestRemoteFile
public class HTTPRemoteFile extends AbstractRemoteFile
A remote file implemented with point-to-point HTTP communication. Optimised to communicate locally, if file is on the same host. Optimised to transfer 0 byte files inline.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected String
checksum
If useChecksums is true, contains the file checksum.protected String
hostname
The name of the host this file originated on.static String
HTTPREMOTEFILE_PORT_NUMBER
settings.common.remoteFile.port:
The setting for the HTTP remotefile port number used.protected URL
url
The url that exposes this remote file.-
Fields inherited from class dk.netarkivet.common.distribute.AbstractRemoteFile
file, fileDeletable, filesize, multipleDownloads, useChecksums
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
HTTPRemoteFile(File file, boolean useChecksums, boolean fileDeletable, boolean multipleDownloads)
Initialises a remote file implemented by point-to-point HTTP communication.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
cleanup()
Invalidate all file handles, by asking the remote registry to remove the url for this remote file from the list of shared files.void
copyTo(File destFile)
Copy this remote file to the given file.String
getChecksum()
Get checksum for file, or null if checksums were not requested.InputStream
getInputStream()
Get an input stream representing the remote file.static RemoteFile
getInstance(File f, Boolean useChecksums, Boolean fileDeletable, Boolean multipleDownloads)
Initialises a remote file implemented by point-to-point HTTP communication.int
getNumberOfRetries()
Retrieval of the number of retries for retrieving a file from a HTTP server.protected HTTPRemoteFileRegistry
getRegistry()
Get the webserver registry for this class of files.protected boolean
isLocal()
Helper method to determine if file resides on local machine.-
Methods inherited from class dk.netarkivet.common.distribute.AbstractRemoteFile
appendTo, getName, getSize, toString
-
-
-
-
Field Detail
-
hostname
protected final String hostname
The name of the host this file originated on.
-
url
protected final URL url
The url that exposes this remote file.
-
checksum
protected final String checksum
If useChecksums is true, contains the file checksum.
-
HTTPREMOTEFILE_PORT_NUMBER
public static String HTTPREMOTEFILE_PORT_NUMBER
settings.common.remoteFile.port:
The setting for the HTTP remotefile port number used.
-
-
Constructor Detail
-
HTTPRemoteFile
protected HTTPRemoteFile(File file, boolean useChecksums, boolean fileDeletable, boolean multipleDownloads)
Initialises a remote file implemented by point-to-point HTTP communication.- Parameters:
file
- The file to make a remote file foruseChecksums
- Whether communications are checksummed. If true, getChecksum will also return the checksum.fileDeletable
- if true, the file given to this method is deletable, once it is transferred.multipleDownloads
- if true, the file may be transferred more than once. Otherwise, all file handles are attempted to be made invalid after the first transfer, although no guarantees are made.- Throws:
ArgumentNotValid
- if file is null, or not a readable file.IOFailure
- if checksums are requested, but i/o errors occur while checksumming.
-
-
Method Detail
-
getInstance
public static RemoteFile getInstance(File f, Boolean useChecksums, Boolean fileDeletable, Boolean multipleDownloads)
Initialises a remote file implemented by point-to-point HTTP communication.- Parameters:
f
- The file to make a remote file foruseChecksums
- Whether communications are checksummed. If true, getChecksum will also return the checksum.fileDeletable
- if true, the file given to this method is deletable, once it is transferred.multipleDownloads
- if true, the file may be transferred more than once. Otherwise, all file handles are attempted to be made invalid after the first transfer, although no guarantees are made.- Throws:
ArgumentNotValid
- if file is null, or not a readable file.IOFailure
- if checksums are requested, but i/o errors occur while checksumming.
-
getRegistry
protected HTTPRemoteFileRegistry getRegistry()
Get the webserver registry for this class of files. Meant to be subclassed for specialised versions of this file.- Returns:
- The reigstry.
-
copyTo
public void copyTo(File destFile)
Copy this remote file to the given file. If the file resides on the current machine, remote file transfer is done locally. Otherwise, the remote file is transferred over http. If the file is not set to be able to be transferred multiple times, it is cleaned up after the transfer.- Specified by:
copyTo
in interfaceRemoteFile
- Overrides:
copyTo
in classAbstractRemoteFile
- 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.
-
getInputStream
public InputStream getInputStream()
Get an input stream representing the remote file. If the file resides on the current machine, the input stream is to the local file. Otherwise, the remote file is transferred over http. The close method of the input stream will cleanup this handle, and if checksums are requested, will check the checksums on close. If the file is not set to be able to be transferred multiple times, it is cleaned up after the transfer.- Specified by:
getInputStream
in interfaceRemoteFile
- Specified by:
getInputStream
in classAbstractRemoteFile
- Returns:
- An input stream for the remote file.
- Throws:
IOFailure
- on I/O trouble generating inputstream for remote file. Also, the returned remote file will throw IOFailure on close, if checksums are requested, but do not match.
-
cleanup
public void cleanup()
Invalidate all file handles, by asking the remote registry to remove the url for this remote file from the list of shared files. Invalidating a file handle may delete the original files, if deletable. This method does not throw exceptions, but will warn on errors.- Specified by:
cleanup
in interfaceRemoteFile
- Specified by:
cleanup
in classAbstractRemoteFile
-
getChecksum
public String getChecksum()
Get checksum for file, or null if checksums were not requested.- Specified by:
getChecksum
in interfaceRemoteFile
- Specified by:
getChecksum
in classAbstractRemoteFile
- Returns:
- checksum for file, or null if checksums were not requested.
-
isLocal
protected boolean isLocal()
Helper method to determine if file resides on local machine.- Returns:
- true if the file is on the local machine, false otherwise.
-
getNumberOfRetries
public int getNumberOfRetries()
Retrieval of the number of retries for retrieving a file from a HTTP server. TODO define a setting for HTTP retries, just like for the FTP retries.- Specified by:
getNumberOfRetries
in classAbstractRemoteFile
- Returns:
- The number of retries. Currently a constant: 1.
-
-