/*
 * @(#)FtpConnection.java
 *
 * Copyright (c) 2004 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;

import com.jscape.inet.util.ServerSocketUtil;

import java.io.InputStream;
import java.io.OutputStream;

/**
 * Base interface for FTP connections.
 */
public interface FtpConnection {

    //--------------------------------------------------------------------------

    /**
     * Prepares incoming connection.
     *
     * @param range data port range
     * @param timeout       connection timeout.
     *
     * @throws FtpException if an I/O error occurs.
     */
    void prepareIncoming(ServerSocketUtil.PortRange range, int timeout)
            throws FtpException;

    //--------------------------------------------------------------------------

    /**
     * Opens incoming connection.
     *
     * @param timeout connection timeout.
     *
     * @throws FtpException if an I/O error occurs.
     */
    void openIncoming(int timeout, int linger)
            throws FtpException;

    //--------------------------------------------------------------------------

    /**
     * Opens outgoing connection.
     *
     * @param host    host to connect
     * @param port    port to connect
     * @param timeout connection timeout
     *
     * @throws FtpException an I/O error occurs.
     */
    void openOutgoing(String host, int port, int timeout, int linger, boolean keepAlive, boolean tcpNoDelay)
            throws FtpException;

    /**
     * Opens outgoing connection.
     *
     * @param host          host to connect
     * @param port          port to connect
     * @param timeout       connection timeout
     * @param keepAlive     keep alive
     * @param linger        how long to linger for
     * @param proxyHost     Proxy host server
     * @param proxyPort     Proxy port
     * @param proxyUserId   Proxy user name
     * @param proxyPassword Proxy user password
     * @param proxyType     Valid proxy type: HTTP, SOCKS5
     *
     * @throws FtpException if an I/O error occurs.
     */
    void openOutgoing(String host,
                      int port,
                      int timeout,
                      boolean keepAlive,
                      boolean tcpNoDelay,
                      int linger,
                      String proxyHost,
                      int proxyPort,
                      String proxyUserId,
                      String proxyPassword,
                      String proxyType)
            throws FtpException;

    //--------------------------------------------------------------------------

    /**
     * Closes open connection.
     */
    void close();

    //--------------------------------------------------------------------------

    /**
     * Checks if connection is open.
     *
     * @return <code>true</code> if connection is open.
     */
    boolean isOpen();

    //--------------------------------------------------------------------------

    /**
     * Returns connection input stream.
     *
     * @return connection input stream.
     *
     * @throws FtpException an I/O error occurs.
     */
    InputStream getInputStream()
            throws FtpException;

    //--------------------------------------------------------------------------

    /**
     * Returns connection output stream.
     *
     * @return connection output stream.
     *
     * @throws FtpException an I/O error occurs.
     */
    OutputStream getOutputStream()
            throws FtpException;

    //--------------------------------------------------------------------------

    /**
     * Returns current host name.
     *
     * @return current host name.
     */
    String getHost();

    /**
     * Sets whether the sockets streams will be wrapped into Deflatered
     * and Inflatered streams.
     */
    void setCompression(boolean compression);

    /**
     * Sets the send buffer size option of the ftp connection.
     *
     * @param sendBufferSize Send buffer size.
     */
    void setSendBufferSize(int sendBufferSize);

    /**
     * Sets the receive buffer size option of the ftp connection.
     *
     * @param receiveBufferSize Receive buffer size.
     */
    void setReceiveBufferSize(int receiveBufferSize);

}
