/*
 * @(#)FtpDownloadEvent.java
 *
 * Copyright (c) 2001-2002 JScape
 * 1147 S. 53rd Pl., Mesa, Arizona, 85206, U.S.A.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * JScape. ("Confidential Information").  You shall not disclose such
 * Confidential Information and shall use it only in accordance with
 * the terms of the license agreement you entered into with JScape.
 */
package com.jscape.inet.ftp;

/**
 * Fired when file is downloaded from FTP server.
 */
public class FtpDownloadEvent
        extends FtpEvent {

    private final String filename;
    private final String path;
    private final String localPath;
    private final long size;
    private final long time;

    /**
     * Creates FtpDownloadEvent.
     *
     * @param source    the source of the event
     * @param filename  the file downloaded
     * @param path      the remote directory path that file was downloaded from
     * @param localPath the the local file path
     * @param size      the size of the file downloaded
     * @param time      the amount of time to download file measured in milliseconds
     */
    public FtpDownloadEvent(Object source,
                            String filename,
                            String path,
                            String localPath,
                            long size,
                            long time) {
        super(source);

        this.filename = filename;
        this.path = path;
        this.localPath = localPath;
        this.size = size;
        this.time = time;
    }

    /**
     * Gets name of file downloaded.
     *
     * @return filename
     */
    public String getFilename() {
        return this.filename;
    }

    /**
     * Gets remote directory path that the file was downloaded from.
     *
     * @return the remote directory path
     */
    public String getPath() {
        return this.path;
    }

    /**
     * Returns local file path.
     *
     * @return local file path
     */
    public String getLocalPath() {
        return this.localPath;
    }

    /**
     * Gets total bytes transmitted
     *
     * @return bytes transmitted
     */
    public long getSize() {
        return this.size;
    }

    /**
     * Gets total time to transfer file measured in milliseconds
     *
     * @return total time
     */
    public long getTime() {
        return this.time;
    }

    public void accept(FtpListener listener) {
        if (listener != null) {
            listener.download(this);
        }
    }

    /**
     * Gets String equivalent of this event.
     *
     * @return the String equivalent for this event
     */
    public String toString() {
        return "Downloaded file " + filename + " ," + size + " bytes in "
                + time
                + " ms. from remote directory path " + path;
    }

}
