Path: blob/master/src/java.base/share/classes/java/nio/channels/Channel.java
41159 views
/*1* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package java.nio.channels;2627import java.io.IOException;28import java.io.Closeable;293031/**32* A nexus for I/O operations.33*34* <p> A channel represents an open connection to an entity such as a hardware35* device, a file, a network socket, or a program component that is capable of36* performing one or more distinct I/O operations, for example reading or37* writing.38*39* <p> A channel is either open or closed. A channel is open upon creation,40* and once closed it remains closed. Once a channel is closed, any attempt to41* invoke an I/O operation upon it will cause a {@link ClosedChannelException}42* to be thrown. Whether or not a channel is open may be tested by invoking43* its {@link #isOpen isOpen} method.44*45* <p> Channels are, in general, intended to be safe for multithreaded access46* as described in the specifications of the interfaces and classes that extend47* and implement this interface.48*49*50* @author Mark Reinhold51* @author JSR-51 Expert Group52* @since 1.453*/5455public interface Channel extends Closeable {5657/**58* Tells whether or not this channel is open.59*60* @return {@code true} if, and only if, this channel is open61*/62public boolean isOpen();6364/**65* Closes this channel.66*67* <p> After a channel is closed, any further attempt to invoke I/O68* operations upon it will cause a {@link ClosedChannelException} to be69* thrown.70*71* <p> If this channel is already closed then invoking this method has no72* effect.73*74* <p> This method may be invoked at any time. If some other thread has75* already invoked it, however, then another invocation will block until76* the first invocation is complete, after which it will return without77* effect. </p>78*79* @throws IOException If an I/O error occurs80*/81public void close() throws IOException;8283}848586