1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements.  See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License.  You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package java.nio.channels;
18
19import java.io.Closeable;
20import java.io.IOException;
21
22/**
23 * A channel is a conduit to I/O services covering such items as files, sockets,
24 * hardware devices, I/O ports or some software component.
25 * <p>
26 * Channels are open upon creation, and can be closed explicitly. Once a channel
27 * is closed it cannot be re-opened, and any attempts to perform I/O operations
28 * on the closed channel result in a <code>ClosedChannelException</code>.
29 * <p>
30 * Particular implementations or sub-interfaces of {@code Channel} dictate
31 * whether they are thread-safe or not.
32 */
33public interface Channel extends Closeable {
34
35    /**
36     * Returns true if this channel is open.
37     */
38    public boolean isOpen();
39
40    /**
41     * Closes an open channel. If the channel is already closed then this method
42     * has no effect. If there is a problem with closing the channel then the
43     * method throws an IOException and the exception contains reasons for the
44     * failure.
45     * <p>
46     * If an attempt is made to perform an operation on a closed channel then a
47     * {@link ClosedChannelException} will be thrown on that attempt.
48     * <p>
49     * If multiple threads attempt to simultaneously close a channel, then only
50     * one thread will run the closure code, and others will be blocked until
51     * the first returns.
52     *
53     * @throws IOException
54     *             if a problem occurs closing the channel.
55     */
56    public void close() throws IOException;
57}
58