| |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public final class Channels extends Object
Utility methods for channels and streams.
This class defines static methods that support the interoperation of the stream classes of the {@link java.io} package with the channel classes of this package.
Method Summary | |
---|---|
static ReadableByteChannel |
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 |
Constructs a stream that reads bytes from the given channel. |
static OutputStream |
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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static ReadableByteChannel newChannel(InputStream in)
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.
in
- The stream from which bytes are to be readpublic static WritableByteChannel newChannel(OutputStream out)
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.
out
- The stream to which bytes are to be writtenpublic static InputStream newInputStream(ReadableByteChannel ch)
The read methods of the resulting stream will throw an {@link IllegalBlockingModeException} if invoked while the underlying channel is in non-blocking mode. The stream will not be buffered, and it will not support the {@link InputStream#mark mark} or {@link InputStream#reset 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.
ch
- The channel from which bytes will be readpublic static OutputStream newOutputStream(WritableByteChannel ch)
The write methods of the resulting stream will throw an {@link 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.
ch
- The channel to which bytes will be writtenpublic static Reader newReader(ReadableByteChannel ch, CharsetDecoder dec, int minBufferCap)
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 {@link IllegalBlockingModeException} will be thrown. The resulting stream will not otherwise be buffered, and it will not support the {@link Reader#mark mark} or {@link Reader#reset reset} methods. Closing the stream will in turn cause the channel to be closed.
ch
- The channel from which bytes will be readdec
- The charset decoder to be usedminBufferCap
- The minimum capacity of the internal byte buffer,
or -1 if an implementation-dependent
default capacity is to be usedpublic static Reader newReader(ReadableByteChannel ch, String csName)
An invocation of this method of the form
behaves in exactly the same way as the expressionChannels.newReader(ch, csname)
Channels.newReader(ch, Charset.forName(csName) .newDecoder(), -1);
ch
- The channel from which bytes will be readcsName
- The name of the charset to be usedpublic static Writer newWriter(WritableByteChannel ch, CharsetEncoder enc, int minBufferCap)
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 {@link IllegalBlockingModeException} will be thrown. The resulting stream will not otherwise be buffered. Closing the stream will in turn cause the channel to be closed.
ch
- The channel to which bytes will be writtenenc
- The charset encoder to be usedminBufferCap
- The minimum capacity of the internal byte buffer,
or -1 if an implementation-dependent
default capacity is to be usedpublic static Writer newWriter(WritableByteChannel ch, String csName)
An invocation of this method of the form
behaves in exactly the same way as the expressionChannels.newWriter(ch, csname)
Channels.newWriter(ch, Charset.forName(csName) .newEncoder(), -1);
ch
- The channel to which bytes will be writtencsName
- The name of the charset to be used
| |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |