Class HTTPRemoteFile

    • 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 for
        useChecksums - 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 for
        useChecksums - 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 interface RemoteFile
        Overrides:
        copyTo in class AbstractRemoteFile
        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 interface RemoteFile
        Specified by:
        getInputStream in class AbstractRemoteFile
        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 interface RemoteFile
        Specified by:
        cleanup in class AbstractRemoteFile
      • getChecksum

        public String getChecksum()
        Get checksum for file, or null if checksums were not requested.
        Specified by:
        getChecksum in interface RemoteFile
        Specified by:
        getChecksum in class AbstractRemoteFile
        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 class AbstractRemoteFile
        Returns:
        The number of retries. Currently a constant: 1.