1/**
2 * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 *     http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * Unless required by applicable law or agreed to in writing, software
9 * distributed under the License is distributed on an "AS IS" BASIS,
10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 * See the License for the specific language governing permissions and
12 * limitations under the License.
13 */
14package org.jivesoftware.smackx.bytestreams;
15
16import java.io.IOException;
17import java.io.InputStream;
18import java.io.OutputStream;
19
20import org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamSession;
21import org.jivesoftware.smackx.bytestreams.socks5.Socks5BytestreamSession;
22
23/**
24 * BytestreamSession provides an interface for established bytestream sessions.
25 * <p>
26 * There are two implementations of the interface. See {@link Socks5BytestreamSession} and
27 * {@link InBandBytestreamSession}.
28 *
29 * @author Henning Staib
30 */
31public interface BytestreamSession {
32
33    /**
34     * Returns the InputStream associated with this session to send data.
35     *
36     * @return the InputStream associated with this session to send data
37     * @throws IOException if an error occurs while retrieving the input stream
38     */
39    public InputStream getInputStream() throws IOException;
40
41    /**
42     * Returns the OutputStream associated with this session to receive data.
43     *
44     * @return the OutputStream associated with this session to receive data
45     * @throws IOException if an error occurs while retrieving the output stream
46     */
47    public OutputStream getOutputStream() throws IOException;
48
49    /**
50     * Closes the bytestream session.
51     * <p>
52     * Closing the session will also close the input stream and the output stream associated to this
53     * session.
54     *
55     * @throws IOException if an error occurs while closing the session
56     */
57    public void close() throws IOException;
58
59    /**
60     * Returns the timeout for read operations of the input stream associated with this session. 0
61     * returns implies that the option is disabled (i.e., timeout of infinity). Default is 0.
62     *
63     * @return the timeout for read operations
64     * @throws IOException if there is an error in the underlying protocol
65     */
66    public int getReadTimeout() throws IOException;
67
68    /**
69     * Sets the specified timeout, in milliseconds. With this option set to a non-zero timeout, a
70     * read() call on the input stream associated with this session will block for only this amount
71     * of time. If the timeout expires, a java.net.SocketTimeoutException is raised, though the
72     * session is still valid. The option must be enabled prior to entering the blocking operation
73     * to have effect. The timeout must be > 0. A timeout of zero is interpreted as an infinite
74     * timeout. Default is 0.
75     *
76     * @param timeout the specified timeout, in milliseconds
77     * @throws IOException if there is an error in the underlying protocol
78     */
79    public void setReadTimeout(int timeout) throws IOException;
80
81}
82