001/**
002 *
003 * Copyright the original author or authors
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.jivesoftware.smackx.bytestreams;
018
019import java.io.IOException;
020import java.io.InputStream;
021import java.io.OutputStream;
022
023import org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamSession;
024import org.jivesoftware.smackx.bytestreams.socks5.Socks5BytestreamSession;
025
026/**
027 * BytestreamSession provides an interface for established bytestream sessions.
028 * <p>
029 * There are two implementations of the interface. See {@link Socks5BytestreamSession} and
030 * {@link InBandBytestreamSession}.
031 *
032 * @author Henning Staib
033 */
034public interface BytestreamSession {
035
036    /**
037     * Returns the InputStream associated with this session to send data.
038     *
039     * @return the InputStream associated with this session to send data
040     * @throws IOException if an error occurs while retrieving the input stream
041     */
042    InputStream getInputStream() throws IOException;
043
044    /**
045     * Returns the OutputStream associated with this session to receive data.
046     *
047     * @return the OutputStream associated with this session to receive data
048     * @throws IOException if an error occurs while retrieving the output stream
049     */
050    OutputStream getOutputStream() throws IOException;
051
052    /**
053     * Closes the bytestream session.
054     * <p>
055     * Closing the session will also close the input stream and the output stream associated to this
056     * session.
057     *
058     * @throws IOException if an error occurs while closing the session
059     */
060    void close() throws IOException;
061
062    /**
063     * Returns the timeout for read operations of the input stream associated with this session. 0
064     * returns implies that the option is disabled (i.e., timeout of infinity). Default is 0.
065     *
066     * @return the timeout for read operations
067     * @throws IOException if there is an error in the underlying protocol
068     */
069    int getReadTimeout() throws IOException;
070
071    /**
072     * Sets the specified timeout, in milliseconds. With this option set to a non-zero timeout, a
073     * read() call on the input stream associated with this session will block for only this amount
074     * of time. If the timeout expires, a java.net.SocketTimeoutException is raised, though the
075     * session is still valid. The option must be enabled prior to entering the blocking operation
076     * to have effect. The timeout must be &gt; 0. A timeout of zero is interpreted as an infinite
077     * timeout. Default is 0.
078     *
079     * @param timeout the specified timeout, in milliseconds
080     * @throws IOException if there is an error in the underlying protocol
081     */
082    void setReadTimeout(int timeout) throws IOException;
083
084}