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 whether this channel is open or not. 37 * 38 * @return true if the channel is open, otherwise returns false. 39 */ 40 public boolean isOpen(); 41 42 /** 43 * Closes an open channel. If the channel is already closed then this method 44 * has no effect. If there is a problem with closing the channel then the 45 * method throws an IOException and the exception contains reasons for the 46 * failure. 47 * <p> 48 * If an attempt is made to perform an operation on a closed channel then a 49 * {@link ClosedChannelException} will be thrown on that attempt. 50 * <p> 51 * If multiple threads attempt to simultaneously close a channel, then only 52 * one thread will run the closure code, and others will be blocked until 53 * the first returns. 54 * 55 * @throws IOException 56 * if a problem occurs closing the channel. 57 */ 58 public void close() throws IOException; 59} 60