001/*
002 * #%L
003 * Netarchivesuite - common
004 * %%
005 * Copyright (C) 2005 - 2018 The Royal Danish Library, 
006 *             the National Library of France and the Austrian National Library.
007 * %%
008 * This program is free software: you can redistribute it and/or modify
009 * it under the terms of the GNU Lesser General Public License as
010 * published by the Free Software Foundation, either version 2.1 of the
011 * License, or (at your option) any later version.
012 * 
013 * This program is distributed in the hope that it will be useful,
014 * but WITHOUT ANY WARRANTY; without even the implied warranty of
015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016 * GNU General Lesser Public License for more details.
017 * 
018 * You should have received a copy of the GNU General Lesser Public
019 * License along with this program.  If not, see
020 * <http://www.gnu.org/licenses/lgpl-2.1.html>.
021 * #L%
022 */
023package dk.netarkivet.common.distribute;
024
025import java.io.File;
026import java.io.InputStream;
027import java.io.OutputStream;
028import java.io.Serializable;
029
030import dk.netarkivet.common.exceptions.ArgumentNotValid;
031import dk.netarkivet.common.exceptions.IOFailure;
032
033/**
034 * RemoteFile: Interface for encapsulating remote files. Enables us to transmit large files between system components
035 * situated on different machines. Our current JMS broker(s) does not allow large message (i.e. messages > 70 MB).
036 */
037public interface RemoteFile extends Serializable {
038
039    /**
040     * Copy remotefile to local disk storage. Used by the data recipient
041     *
042     * @param destFile local File
043     * @throws IOFailure on communication trouble.
044     * @throws ArgumentNotValid on null parameter or non-writable file
045     */
046    void copyTo(File destFile);
047
048    /**
049     * Write the contents of this remote file to an output stream.
050     *
051     * @param out OutputStream that the data will be written to. This stream will not be closed by this operation.
052     * @throws IOFailure If append operation fails
053     * @throws ArgumentNotValid on null parameter
054     */
055    void appendTo(OutputStream out);
056
057    /**
058     * Get an inputstream that contains the data transferred in this RemoteFile.
059     *
060     * @return A stream object with the data in the object. Note that the close() method of this may throw exceptions if
061     * e.g. a transmission error is detected.
062     * @throws IOFailure on communication trouble.
063     */
064    InputStream getInputStream();
065
066    /**
067     * Return the file name.
068     *
069     * @return the file name
070     */
071    String getName();
072
073    /**
074     * Returns a MD5 Checksum on the file. May return null, if checksums not supported for this operation.
075     *
076     * @return MD5 checksum
077     */
078    String getChecksum();
079
080    /**
081     * Cleanup this remote file. The file is invalid after this.
082     */
083    void cleanup();
084
085    /**
086     * Returns the total size of the remote file.
087     *
088     * @return Size of the remote file.
089     */
090    long getSize();
091
092}