Channel
Stay organized with collections
Save and categorize content based on your preferences.
Known Indirect Subclasses
AbstractInterruptibleChannel,
AbstractSelectableChannel,
AsynchronousByteChannel,
AsynchronousChannel,
AsynchronousFileChannel,
AsynchronousServerSocketChannel,
AsynchronousSocketChannel,
ByteChannel,
DatagramChannel,
FileChannel,
GatheringByteChannel,
InterruptibleChannel,
MulticastChannel,
NetworkChannel,
Pipe.SinkChannel,
and
8 others.
|
A nexus for I/O operations.
A channel represents an open connection to an entity such as a hardware
device, a file, a network socket, or a program component that is capable of
performing one or more distinct I/O operations, for example reading or
writing.
A channel is either open or closed. A channel is open upon creation,
and once closed it remains closed. Once a channel is closed, any attempt to
invoke an I/O operation upon it will cause a ClosedChannelException
to be thrown. Whether or not a channel is open may be tested by invoking
its isOpen
method.
Channels are, in general, intended to be safe for multithreaded access
as described in the specifications of the interfaces and classes that extend
and implement this interface.
Public Method Summary
abstract
void
|
close()
Closes this channel.
|
abstract
boolean
|
isOpen()
Tells whether or not this channel is open.
|
Inherited Method Summary
From interface
java.io.Closeable
abstract
void
|
close()
Closes this stream and releases any system resources associated
with it.
|
Public Methods
public
abstract
void
close
()
Closes this channel.
After a channel is closed, any further attempt to invoke I/O
operations upon it will cause a ClosedChannelException
to be
thrown.
If this channel is already closed then invoking this method has no
effect.
This method may be invoked at any time. If some other thread has
already invoked it, however, then another invocation will block until
the first invocation is complete, after which it will return without
effect.
public
abstract
boolean
isOpen
()
Tells whether or not this channel is open.
Returns
- true if, and only if, this channel is open
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-07-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-07-10 UTC."],[[["\u003cp\u003eThe \u003ccode\u003eChannel\u003c/code\u003e interface represents an open connection to an entity like a file, network socket, or hardware device, enabling I/O operations.\u003c/p\u003e\n"],["\u003cp\u003eA \u003ccode\u003eChannel\u003c/code\u003e can be either open or closed, with attempts to perform I/O on a closed channel resulting in a \u003ccode\u003eClosedChannelException\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eChannel\u003c/code\u003e interface provides methods to close the channel (\u003ccode\u003eclose()\u003c/code\u003e) and to check if it's open (\u003ccode\u003eisOpen()\u003c/code\u003e).\u003c/p\u003e\n"],["\u003cp\u003eChannels are generally designed to be thread-safe for multithreaded access.\u003c/p\u003e\n"],["\u003cp\u003eMany types of channels exist, including \u003ccode\u003eFileChannel\u003c/code\u003e, \u003ccode\u003eSocketChannel\u003c/code\u003e, \u003ccode\u003eDatagramChannel\u003c/code\u003e, and asynchronous variations, each catering to specific I/O needs.\u003c/p\u003e\n"]]],[],null,["public interface **Channel** implements [Closeable](../../../../reference/java/io/Closeable.html) \n\n|---|---|---|\n| Known Indirect Subclasses [AbstractInterruptibleChannel](../../../../reference/java/nio/channels/spi/AbstractInterruptibleChannel.html), [AbstractSelectableChannel](../../../../reference/java/nio/channels/spi/AbstractSelectableChannel.html), [AsynchronousByteChannel](../../../../reference/java/nio/channels/AsynchronousByteChannel.html), [AsynchronousChannel](../../../../reference/java/nio/channels/AsynchronousChannel.html), [AsynchronousFileChannel](../../../../reference/java/nio/channels/AsynchronousFileChannel.html), [AsynchronousServerSocketChannel](../../../../reference/java/nio/channels/AsynchronousServerSocketChannel.html), [AsynchronousSocketChannel](../../../../reference/java/nio/channels/AsynchronousSocketChannel.html), [ByteChannel](../../../../reference/java/nio/channels/ByteChannel.html), [DatagramChannel](../../../../reference/java/nio/channels/DatagramChannel.html), [FileChannel](../../../../reference/java/nio/channels/FileChannel.html), [GatheringByteChannel](../../../../reference/java/nio/channels/GatheringByteChannel.html), [InterruptibleChannel](../../../../reference/java/nio/channels/InterruptibleChannel.html), [MulticastChannel](../../../../reference/java/nio/channels/MulticastChannel.html), [NetworkChannel](../../../../reference/java/nio/channels/NetworkChannel.html), [Pipe.SinkChannel](../../../../reference/java/nio/channels/Pipe.SinkChannel.html), and [8 others.](#) |-----------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------| | [AbstractInterruptibleChannel](../../../../reference/java/nio/channels/spi/AbstractInterruptibleChannel.html) | Base implementation class for interruptible channels. | | [AbstractSelectableChannel](../../../../reference/java/nio/channels/spi/AbstractSelectableChannel.html) | Base implementation class for selectable channels. | | [AsynchronousByteChannel](../../../../reference/java/nio/channels/AsynchronousByteChannel.html) | An asynchronous channel that can read and write bytes. | | [AsynchronousChannel](../../../../reference/java/nio/channels/AsynchronousChannel.html) | A channel that supports asynchronous I/O operations. | | [AsynchronousFileChannel](../../../../reference/java/nio/channels/AsynchronousFileChannel.html) | An asynchronous channel for reading, writing, and manipulating a file. | | [AsynchronousServerSocketChannel](../../../../reference/java/nio/channels/AsynchronousServerSocketChannel.html) | An asynchronous channel for stream-oriented listening sockets. | | [AsynchronousSocketChannel](../../../../reference/java/nio/channels/AsynchronousSocketChannel.html) | An asynchronous channel for stream-oriented connecting sockets. | | [ByteChannel](../../../../reference/java/nio/channels/ByteChannel.html) | A channel that can read and write bytes. | | [DatagramChannel](../../../../reference/java/nio/channels/DatagramChannel.html) | A selectable channel for datagram-oriented sockets. | | [FileChannel](../../../../reference/java/nio/channels/FileChannel.html) | A channel for reading, writing, mapping, and manipulating a file. | | [GatheringByteChannel](../../../../reference/java/nio/channels/GatheringByteChannel.html) | A channel that can write bytes from a sequence of buffers. | | [InterruptibleChannel](../../../../reference/java/nio/channels/InterruptibleChannel.html) | A channel that can be asynchronously closed and interrupted. | | [MulticastChannel](../../../../reference/java/nio/channels/MulticastChannel.html) | A network channel that supports Internet Protocol (IP) multicasting. | | [NetworkChannel](../../../../reference/java/nio/channels/NetworkChannel.html) | A channel to a network socket. | | [Pipe.SinkChannel](../../../../reference/java/nio/channels/Pipe.SinkChannel.html) | A channel representing the writable end of a [Pipe](../../../../reference/java/nio/channels/Pipe.html). | | [Pipe.SourceChannel](../../../../reference/java/nio/channels/Pipe.SourceChannel.html) | A channel representing the readable end of a [Pipe](../../../../reference/java/nio/channels/Pipe.html). | | [ReadableByteChannel](../../../../reference/java/nio/channels/ReadableByteChannel.html) | A channel that can read bytes. | | [ScatteringByteChannel](../../../../reference/java/nio/channels/ScatteringByteChannel.html) | A channel that can read bytes into a sequence of buffers. | | [SeekableByteChannel](../../../../reference/java/nio/channels/SeekableByteChannel.html) | A byte channel that maintains a current *position* and allows the position to be changed. | | [SelectableChannel](../../../../reference/java/nio/channels/SelectableChannel.html) | A channel that can be multiplexed via a [Selector](../../../../reference/java/nio/channels/Selector.html). | | [ServerSocketChannel](../../../../reference/java/nio/channels/ServerSocketChannel.html) | A selectable channel for stream-oriented listening sockets. | | [SocketChannel](../../../../reference/java/nio/channels/SocketChannel.html) | A selectable channel for stream-oriented connecting sockets. | | [WritableByteChannel](../../../../reference/java/nio/channels/WritableByteChannel.html) | A channel that can write bytes. | |||\n\nA nexus for I/O operations.\n\nA channel represents an open connection to an entity such as a hardware\ndevice, a file, a network socket, or a program component that is capable of\nperforming one or more distinct I/O operations, for example reading or\nwriting.\n\nA channel is either open or closed. A channel is open upon creation,\nand once closed it remains closed. Once a channel is closed, any attempt to\ninvoke an I/O operation upon it will cause a [ClosedChannelException](../../../../reference/java/nio/channels/ClosedChannelException.html)\nto be thrown. Whether or not a channel is open may be tested by invoking\nits [isOpen](../../../../reference/java/nio/channels/Channel.html#isOpen()) method.\n\nChannels are, in general, intended to be safe for multithreaded access\nas described in the specifications of the interfaces and classes that extend\nand implement this interface. \n\nPublic Method Summary\n\n|------------------|----------------------------------------------------------------------------------------------------------------------|\n| abstract void | [close](../../../../reference/java/nio/channels/Channel.html#close())() Closes this channel. |\n| abstract boolean | [isOpen](../../../../reference/java/nio/channels/Channel.html#isOpen())() Tells whether or not this channel is open. |\n\nInherited Method Summary \nFrom interface [java.io.Closeable](../../../../reference/java/io/Closeable.html) \n\n|---------------|------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract void | [close](../../../../reference/java/io/Closeable.html#close())() Closes this stream and releases any system resources associated with it. |\n\nFrom interface [java.lang.AutoCloseable](../../../../reference/java/lang/AutoCloseable.html) \n\n|---------------|-------------------------------------------------------------------------------------------------------------------------------------|\n| abstract void | [close](../../../../reference/java/lang/AutoCloseable.html#close())() Closes this resource, relinquishing any underlying resources. |\n\nPublic Methods \n\npublic abstract void\n**close**\n() \nCloses this channel.\n\nAfter a channel is closed, any further attempt to invoke I/O\noperations upon it will cause a [ClosedChannelException](../../../../reference/java/nio/channels/ClosedChannelException.html) to be\nthrown.\n\nIf this channel is already closed then invoking this method has no\neffect.\n\nThis method may be invoked at any time. If some other thread has\nalready invoked it, however, then another invocation will block until\nthe first invocation is complete, after which it will return without\neffect.\n\n\u003cbr /\u003e\n\nThrows\n\n| [IOException](../../../../reference/java/io/IOException.html) | If an I/O error occurs |\n|---------------------------------------------------------------|------------------------|\n\npublic abstract boolean\n**isOpen**\n() \nTells whether or not this channel is open. \n\nReturns\n\n- true if, and only if, this channel is open"]]