# Print output for @column tags ?>
Developers

- Design
- Develop
- Distribute

Developer Console

## Most visited

## Recently visited

## Results for

Summary: Methods | Inherited Methods

# Channels

`public final class Channels`
`extends Object` ``

java.lang.Object
↳ | java.nio.channels.Channels

Utility methods for channels and streams.

This class defines static methods that support the interoperation of the stream classes of the ``java.io`` package with the channel classes of this package.

## Summary

### Public methods
`static ReadableByteChannel` | `newChannel(InputStream in)` Constructs a channel that reads bytes from the given stream.
`static WritableByteChannel` | `newChannel(OutputStream out)` Constructs a channel that writes bytes to the given stream.
`static InputStream` | `newInputStream(ReadableByteChannel ch)` Constructs a stream that reads bytes from the given channel.
`static InputStream` | `newInputStream(AsynchronousByteChannel ch)` Constructs a stream that reads bytes from the given channel.
`static OutputStream` | `newOutputStream(AsynchronousByteChannel ch)` Constructs a stream that writes bytes to the given channel.
`static OutputStream` | `newOutputStream(WritableByteChannel ch)` Constructs a stream that writes bytes to the given channel.
`static Reader` | `newReader(ReadableByteChannel ch, CharsetDecoder dec, int minBufferCap)` Constructs a reader that decodes bytes from the given channel using the given decoder.
`static Reader` | `newReader(ReadableByteChannel ch, String csName)` Constructs a reader that decodes bytes from the given channel according to the named charset.
`static Writer` | `newWriter(WritableByteChannel ch, CharsetEncoder enc, int minBufferCap)` Constructs a writer that encodes characters using the given encoder and writes the resulting bytes to the given channel.
`static Writer` | `newWriter(WritableByteChannel ch, String csName)` Constructs a writer that encodes characters according to the named charset and writes the resulting bytes to the given channel.

### Inherited methods
From class `java.lang.Object`
`Object` | `clone()` Creates and returns a copy of this object.
`boolean` | `equals(Object obj)` Indicates whether some other object is "equal to" this one.
`void` | `finalize()` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
`final Class<?>` | `getClass()` Returns the runtime class of this `Object`.
`int` | `hashCode()` Returns a hash code value for the object.
`final void` | `notify()` Wakes up a single thread that is waiting on this object's monitor.
`final void` | `notifyAll()` Wakes up all threads that are waiting on this object's monitor.
`String` | `toString()` Returns a string representation of the object.
`final void` | `wait(long timeout, int nanos)` Causes the current thread to wait until another thread invokes the `notify()` method or the `notifyAll()` method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed.
`final void` | `wait(long timeout)` Causes the current thread to wait until either another thread invokes the `notify()` method or the `notifyAll()` method for this object, or a specified amount of time has elapsed.
`final void` | `wait()` Causes the current thread to wait until another thread invokes the `notify()` method or the `notifyAll()` method for this object.

## Public methods

### newChannel

    public static ReadableByteChannel newChannel (InputStream in)

Constructs a channel that reads bytes from the given stream.

The resulting channel will not be buffered; it will simply redirect its I/O operations to the given stream. Closing the channel will in turn cause the stream to be closed.

Parameters
`in` | `InputStream`: The stream from which bytes are to be read

Returns
`ReadableByteChannel` | A new readable byte channel

### newChannel

    public static WritableByteChannel newChannel (OutputStream out)

Constructs a channel that writes bytes to the given stream.

The resulting channel will not be buffered; it will simply redirect its I/O operations to the given stream. Closing the channel will in turn cause the stream to be closed.

Parameters
`out` | `OutputStream`: The stream to which bytes are to be written

Returns
`WritableByteChannel` | A new writable byte channel

### newInputStream

    public static InputStream newInputStream (ReadableByteChannel ch)

Constructs a stream that reads bytes from the given channel.

The `read` methods of the resulting stream will throw an `IllegalBlockingModeException` if invoked while the underlying channel is in non-blocking mode. The stream will not be buffered, and it will not support the `mark` or `reset` methods. The stream will be safe for access by multiple concurrent threads. Closing the stream will in turn cause the channel to be closed.

Parameters
`ch` | `ReadableByteChannel`: The channel from which bytes will be read

Returns
`InputStream` | A new input stream

### newInputStream

    public static InputStream newInputStream (AsynchronousByteChannel ch)

Constructs a stream that reads bytes from the given channel.

The stream will not be buffered, and it will not support the `mark` or `reset` methods. The stream will be safe for access by multiple concurrent threads. Closing the stream will in turn cause the channel to be closed.

Parameters
`ch` | `AsynchronousByteChannel`: The channel from which bytes will be read

Returns
`InputStream` | A new input stream

### newOutputStream

    public static OutputStream newOutputStream (AsynchronousByteChannel ch)

Constructs a stream that writes bytes to the given channel.

The stream will not be buffered. The stream will be safe for access by multiple concurrent threads. Closing the stream will in turn cause the channel to be closed.

Parameters
`ch` | `AsynchronousByteChannel`: The channel to which bytes will be written

Returns
`OutputStream` | A new output stream

### newOutputStream

    public static OutputStream newOutputStream (WritableByteChannel ch)

Constructs a stream that writes bytes to the given channel.

The `write` methods of the resulting stream will throw an `IllegalBlockingModeException` if invoked while the underlying channel is in non-blocking mode. The stream will not be buffered. The stream will be safe for access by multiple concurrent threads. Closing the stream will in turn cause the channel to be closed.

Parameters
`ch` | `WritableByteChannel`: The channel to which bytes will be written

Returns
`OutputStream` | A new output stream

### newReader

    public static Reader newReader (ReadableByteChannel ch,
                    CharsetDecoder dec,
                    int minBufferCap)

Constructs a reader that decodes bytes from the given channel using the given decoder.

The resulting stream will contain an internal input buffer of at least `minBufferCap` bytes. The stream's `read` methods will, as needed, fill the buffer by reading bytes from the underlying channel; if the channel is in non-blocking mode when bytes are to be read then an `IllegalBlockingModeException` will be thrown. The resulting stream will not otherwise be buffered, and it will not support the `mark` or `reset` methods. Closing the stream will in turn cause the channel to be closed.

Parameters
`ch` | `ReadableByteChannel`: The channel from which bytes will be read
`dec` | `CharsetDecoder`: The charset decoder to be used
`minBufferCap` | `int`: The minimum capacity of the internal byte buffer, or `-1` if an implementation-dependent default capacity is to be used

Returns
`Reader` | A new reader

### newReader

    public static Reader newReader (ReadableByteChannel ch,
                    String csName)

Constructs a reader that decodes bytes from the given channel according to the named charset.

An invocation of this method of the form

>      Channels.newReader(ch, csname)

behaves in exactly the same way as the expression

>      Channels.newReader(ch,
>                         Charset.forName(csName)
>                             .newDecoder(),
>                         -1);

Parameters
`ch` | `ReadableByteChannel`: The channel from which bytes will be read
`csName` | `String`: The name of the charset to be used

Returns
`Reader` | A new reader

Throws
`UnsupportedCharsetException` | If no support for the named charset is available in this instance of the Java virtual machine

### newWriter

    public static Writer newWriter (WritableByteChannel ch,
                    CharsetEncoder enc,
                    int minBufferCap)

Constructs a writer that encodes characters using the given encoder and writes the resulting bytes to the given channel.

The resulting stream will contain an internal output buffer of at least `minBufferCap` bytes. The stream's `write` methods will, as needed, flush the buffer by writing bytes to the underlying channel; if the channel is in non-blocking mode when bytes are to be written then an `IllegalBlockingModeException` will be thrown. The resulting stream will not otherwise be buffered. Closing the stream will in turn cause the channel to be closed.

Parameters
`ch` | `WritableByteChannel`: The channel to which bytes will be written
`enc` | `CharsetEncoder`: The charset encoder to be used
`minBufferCap` | `int`: The minimum capacity of the internal byte buffer, or `-1` if an implementation-dependent default capacity is to be used

Returns
`Writer` | A new writer

### newWriter

    public static Writer newWriter (WritableByteChannel ch,
                    String csName)

Constructs a writer that encodes characters according to the named charset and writes the resulting bytes to the given channel.

An invocation of this method of the form

>      Channels.newWriter(ch, csname)

behaves in exactly the same way as the expression

>      Channels.newWriter(ch,
>                         Charset.forName(csName)
>                             .newEncoder(),
>                         -1);

Parameters
`ch` | `WritableByteChannel`: The channel to which bytes will be written
`csName` | `String`: The name of the charset to be used

Returns
`Writer` | A new writer

Throws
`UnsupportedCharsetException` | If no support for the named charset is available in this instance of the Java virtual machine

Full name *
Email address *
Company / developer name
One of your Play Store app URLs *
Which best describes your business:*
Apps
Games
Apps & Games
*
*