public final class Channels extends Object
| Modifier and Type | Method and Description |
|---|---|
static ReadableByteChannel |
newChannel(InputStream inputStream)
Returns a readable channel on the given input stream.
|
static WritableByteChannel |
newChannel(OutputStream outputStream)
Returns a writable channel on the given output stream.
|
static InputStream |
newInputStream(ReadableByteChannel channel)
Returns an input stream on the given channel.
|
static OutputStream |
newOutputStream(WritableByteChannel channel)
Returns an output stream on the given channel.
|
static Reader |
newReader(ReadableByteChannel channel,
CharsetDecoder decoder,
int minBufferCapacity)
Returns a reader that decodes bytes from a channel.
|
static Reader |
newReader(ReadableByteChannel channel,
String charsetName)
Returns a reader that decodes bytes from a channel.
|
static Writer |
newWriter(WritableByteChannel channel,
CharsetEncoder encoder,
int minBufferCapacity)
Returns a writer that encodes characters with the specified
encoder and sends the bytes to the specified channel. |
static Writer |
newWriter(WritableByteChannel channel,
String charsetName)
Returns a writer that encodes characters with the specified
encoder and sends the bytes to the specified channel. |
public static InputStream newInputStream(ReadableByteChannel channel)
IllegalBlockingModeException if the channel is
in non-blocking mode and read is called.mark nor reset is supported.channel - the channel to be wrapped by an InputStream.public static OutputStream newOutputStream(WritableByteChannel channel)
IllegalBlockingModeException if the channel is
in non-blocking mode and write is called.channel - the channel to be wrapped by an OutputStream.public static ReadableByteChannel newChannel(InputStream inputStream)
inputStream - the stream to be wrapped by a byte channel.public static WritableByteChannel newChannel(OutputStream outputStream)
outputStream - the stream to be wrapped by a byte channel.public static Reader newReader(ReadableByteChannel channel, CharsetDecoder decoder, int minBufferCapacity)
channel - the Channel to be read.decoder - the Charset decoder to be used.minBufferCapacity - The minimum size of the byte buffer, -1 means to use the
default size.public static Reader newReader(ReadableByteChannel channel, String charsetName)
channel - the Channel to be read.charsetName - the name of the charset.UnsupportedCharsetException - if the given charset name is not supported.public static Writer newWriter(WritableByteChannel channel, CharsetEncoder encoder, int minBufferCapacity)
encoder and sends the bytes to the specified channel.channel - the Channel to write to.encoder - the CharsetEncoder to be used.minBufferCapacity - the minimum size of the byte buffer, -1 means to use the
default size.public static Writer newWriter(WritableByteChannel channel, String charsetName)
encoder and sends the bytes to the specified channel. This method
creates a writer with a buffer of default size.channel - the Channel to be written to.charsetName - the name of the charset.UnsupportedCharsetException - if the given charset name is not supported.