Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Protected Ctors](https://developer.android.com/reference/java/nio/channels/spi/AbstractInterruptibleChannel#proctors) \| [Methods](https://developer.android.com/reference/java/nio/channels/spi/AbstractInterruptibleChannel#pubmethods) \| [Protected Methods](https://developer.android.com/reference/java/nio/channels/spi/AbstractInterruptibleChannel#promethods) \| [Inherited Methods](https://developer.android.com/reference/java/nio/channels/spi/AbstractInterruptibleChannel#inhmethods)

# AbstractInterruptibleChannel


`
public


abstract
class
AbstractInterruptibleChannel
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


implements

https://developer.android.com/reference/java/nio/channels/Channel,

https://developer.android.com/reference/java/nio/channels/InterruptibleChannel


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | java.nio.channels.spi.AbstractInterruptibleChannel |

|---|
| Known direct subclasses [FileChannel](https://developer.android.com/reference/java/nio/channels/FileChannel), [SelectableChannel](https://developer.android.com/reference/java/nio/channels/SelectableChannel) |---|---| | [FileChannel](https://developer.android.com/reference/java/nio/channels/FileChannel) | A channel for reading, writing, mapping, and manipulating a file. | | [SelectableChannel](https://developer.android.com/reference/java/nio/channels/SelectableChannel) | A channel that can be multiplexed via a `https://developer.android.com/reference/java/nio/channels/Selector`. | |

|---|
| Known indirect subclasses [AbstractSelectableChannel](https://developer.android.com/reference/java/nio/channels/spi/AbstractSelectableChannel), [DatagramChannel](https://developer.android.com/reference/java/nio/channels/DatagramChannel), [Pipe.SinkChannel](https://developer.android.com/reference/java/nio/channels/Pipe.SinkChannel), [Pipe.SourceChannel](https://developer.android.com/reference/java/nio/channels/Pipe.SourceChannel), [ServerSocketChannel](https://developer.android.com/reference/java/nio/channels/ServerSocketChannel), [SocketChannel](https://developer.android.com/reference/java/nio/channels/SocketChannel) |---|---| | [AbstractSelectableChannel](https://developer.android.com/reference/java/nio/channels/spi/AbstractSelectableChannel) | Base implementation class for selectable channels. | | [DatagramChannel](https://developer.android.com/reference/java/nio/channels/DatagramChannel) | A selectable channel for datagram-oriented sockets. | | [Pipe.SinkChannel](https://developer.android.com/reference/java/nio/channels/Pipe.SinkChannel) | A channel representing the writable end of a `https://developer.android.com/reference/java/nio/channels/Pipe`. | | [Pipe.SourceChannel](https://developer.android.com/reference/java/nio/channels/Pipe.SourceChannel) | A channel representing the readable end of a `https://developer.android.com/reference/java/nio/channels/Pipe`. | | [ServerSocketChannel](https://developer.android.com/reference/java/nio/channels/ServerSocketChannel) | A selectable channel for stream-oriented listening sockets. | | [SocketChannel](https://developer.android.com/reference/java/nio/channels/SocketChannel) | A selectable channel for stream-oriented connecting sockets. | |

<br />

*** ** * ** ***

Base implementation class for interruptible channels.

This class encapsulates the low-level machinery required to implement
the asynchronous closing and interruption of channels. A concrete channel
class must invoke the `https://developer.android.com/reference/java/nio/channels/spi/AbstractInterruptibleChannel#begin()` and `https://developer.android.com/reference/java/nio/channels/spi/AbstractInterruptibleChannel#end(boolean)` methods
before and after, respectively, invoking an I/O operation that might block
indefinitely. In order to ensure that the `https://developer.android.com/reference/java/nio/channels/spi/AbstractInterruptibleChannel#end(boolean)` method is always
invoked, these methods should be used within a
`try` ... `finally` block:

> ```
> boolean completed = false;
> try {
>     begin();
>     completed = ...;    // Perform blocking I/O operation
>     return ...;         // Return result
> } finally {
>     end(completed);
> }
> ```

The `completed` argument to the `https://developer.android.com/reference/java/nio/channels/spi/AbstractInterruptibleChannel#end(boolean)` method tells
whether or not the I/O operation actually completed, that is, whether it had
any effect that would be visible to the invoker. In the case of an
operation that reads bytes, for example, this argument should be
`true` if, and only if, some bytes were actually transferred into the
invoker's target buffer.

A concrete channel class must also implement the `https://developer.android.com/reference/java/nio/channels/spi/AbstractInterruptibleChannel#implCloseChannel()` method in such a way that if it is
invoked while another thread is blocked in a native I/O operation upon the
channel then that operation will immediately return, either by throwing an
exception or by returning normally. If a thread is interrupted or the
channel upon which it is blocked is asynchronously closed then the channel's
`https://developer.android.com/reference/java/nio/channels/spi/AbstractInterruptibleChannel#end(boolean)` method will throw the appropriate exception.

This class performs the synchronization required to implement the `https://developer.android.com/reference/java/nio/channels/Channel` specification. Implementations of the `https://developer.android.com/reference/java/nio/channels/spi/AbstractInterruptibleChannel#implCloseChannel()` method need not synchronize against
other threads that might be attempting to close the channel.

<br />

## Summary

| ### Protected constructors ||
|---|---|
| ` https://developer.android.com/reference/java/nio/channels/spi/AbstractInterruptibleChannel#AbstractInterruptibleChannel()() ` Initializes a new instance of this class. |

| ### Public methods ||
|---|---|
| ` final void` | ` https://developer.android.com/reference/java/nio/channels/spi/AbstractInterruptibleChannel#close()() ` Closes this channel. |
| ` final boolean` | ` https://developer.android.com/reference/java/nio/channels/spi/AbstractInterruptibleChannel#isOpen()() ` Tells whether or not this channel is open. |

| ### Protected methods ||
|---|---|
| ` final void` | ` https://developer.android.com/reference/java/nio/channels/spi/AbstractInterruptibleChannel#begin()() ` Marks the beginning of an I/O operation that might block indefinitely. |
| ` final void` | ` https://developer.android.com/reference/java/nio/channels/spi/AbstractInterruptibleChannel#end(boolean)(boolean completed) ` Marks the end of an I/O operation that might block indefinitely. |
| ` abstract void` | ` https://developer.android.com/reference/java/nio/channels/spi/AbstractInterruptibleChannel#implCloseChannel()() ` Closes this channel. |

| ### Inherited methods |
|---|---|
| From class ` https://developer.android.com/reference/java/lang/Object ` |---|---| | ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/lang/Object#clone()() ` Creates and returns a copy of this object. | | ` boolean` | ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) ` Indicates whether some other object is "equal to" this one. | | ` void` | ` https://developer.android.com/reference/java/lang/Object#finalize()() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. | | ` final https://developer.android.com/reference/java/lang/Class<?>` | ` https://developer.android.com/reference/java/lang/Object#getClass()() ` Returns the runtime class of this `Object`. | | ` int` | ` https://developer.android.com/reference/java/lang/Object#hashCode()() ` Returns a hash code value for the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notify()() ` Wakes up a single thread that is waiting on this object's monitor. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notifyAll()() ` Wakes up all threads that are waiting on this object's monitor. | | ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/lang/Object#toString()() ` Returns a string representation of the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait()() ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*. | ||
| From interface ` https://developer.android.com/reference/java/nio/channels/Channel ` |---|---| | ` abstract void` | ` https://developer.android.com/reference/java/nio/channels/Channel#close()() ` Closes this channel. | | ` abstract boolean` | ` https://developer.android.com/reference/java/nio/channels/Channel#isOpen()() ` Tells whether or not this channel is open. | ||
| From interface ` https://developer.android.com/reference/java/nio/channels/InterruptibleChannel ` |---|---| | ` abstract void` | ` https://developer.android.com/reference/java/nio/channels/InterruptibleChannel#close()() ` Closes this channel. | ||
| From interface ` https://developer.android.com/reference/java/io/Closeable ` |---|---| | ` abstract void` | ` https://developer.android.com/reference/java/io/Closeable#close()() ` Closes this stream and releases any system resources associated with it. | ||
| From interface ` https://developer.android.com/reference/java/lang/AutoCloseable ` |---|---| | ` abstract void` | ` https://developer.android.com/reference/java/lang/AutoCloseable#close()() ` Closes this resource, relinquishing any underlying resources. | ||

## Protected constructors

### AbstractInterruptibleChannel

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected AbstractInterruptibleChannel ()
```

Initializes a new instance of this class.

<br />

## Public methods

### close

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public final void close ()
```

Closes this channel.

If the channel has already been closed then this method returns
immediately. Otherwise it marks the channel as closed and then invokes
the `https://developer.android.com/reference/java/nio/channels/spi/AbstractInterruptibleChannel#implCloseChannel()` method in order to
complete the close operation.

<br />

<br />

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | If an I/O error occurs |

### isOpen

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public final boolean isOpen ()
```

Tells whether or not this channel is open.

<br />

| Returns ||
|---|---|
| `boolean` | `true` if, and only if, this channel is open <br /> |

## Protected methods

### begin

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected final void begin ()
```

Marks the beginning of an I/O operation that might block indefinitely.

This method should be invoked in tandem with the `https://developer.android.com/reference/java/nio/channels/spi/AbstractInterruptibleChannel#end(boolean)`
method, using a `try` ... `finally` block as
shown [above](https://developer.android.com/reference/java/nio/channels/spi/AbstractInterruptibleChannel#be), in order to implement asynchronous
closing and interruption for this channel.

<br />

<br />

### end

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected final void end (boolean completed)
```

Marks the end of an I/O operation that might block indefinitely.

This method should be invoked in tandem with the `https://developer.android.com/reference/java/nio/channels/spi/AbstractInterruptibleChannel#begin()` method, using a `try` ... `finally` block
as shown [above](https://developer.android.com/reference/java/nio/channels/spi/AbstractInterruptibleChannel#be), in order to implement asynchronous
closing and interruption for this channel.

<br />

<br />

| Parameters ||
|---|---|
| `completed` | `boolean`: `true` if, and only if, the I/O operation completed successfully, that is, had some effect that would be visible to the operation's invoker <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/nio/channels/AsynchronousCloseException` | If the channel was asynchronously closed |
| `https://developer.android.com/reference/java/nio/channels/ClosedByInterruptException` | If the thread blocked in the I/O operation was interrupted |

### implCloseChannel

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected abstract void implCloseChannel ()
```

Closes this channel.

This method is invoked by the `https://developer.android.com/reference/java/nio/channels/spi/AbstractInterruptibleChannel#close()` method in order
to perform the actual work of closing the channel. This method is only
invoked if the channel has not yet been closed, and it is never invoked
more than once.

An implementation of this method must arrange for any other thread
that is blocked in an I/O operation upon this channel to return
immediately, either by throwing an exception or by returning normally.

<br />

<br />

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | If an I/O error occurs while closing the channel |