Class Channels
-
Method Summary
Modifier and TypeMethodDescriptionstatic ReadableByteChannelConstructs a channel that reads bytes from the given stream.static WritableByteChannelnewChannel(OutputStream out) Constructs a channel that writes bytes to the given stream.static InputStreamConstructs a stream that reads bytes from the given channel.static InputStreamConstructs a stream that reads bytes from the given channel.static OutputStreamConstructs a stream that writes bytes to the given channel.static OutputStreamConstructs a stream that writes bytes to the given channel.static ReadernewReader(ReadableByteChannel ch, String csName) Constructs a reader that decodes bytes from the given channel according to the named charset.static ReadernewReader(ReadableByteChannel ch, Charset charset) Constructs a reader that decodes bytes from the given channel according to the given charset.static ReadernewReader(ReadableByteChannel ch, CharsetDecoder dec, int minBufferCap) Constructs a reader that decodes bytes from the given channel using the given decoder.static WriternewWriter(WritableByteChannel ch, String csName) Constructs a writer that encodes characters according to the named charset and writes the resulting bytes to the given channel.static WriternewWriter(WritableByteChannel ch, Charset charset) Constructs a writer that encodes characters according to the given charset and writes the resulting bytes to the given channel.static WriternewWriter(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.Methods declared in class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitModifier and TypeMethodDescriptionprotected Objectclone()Answers a new instance of the same class as the receiver, whose slots have been filled in with the values in the slots of the receiver.booleanCompares the argument to the receiver, and answers true if they represent the same object using a class specific comparison.protected voidfinalize()Deprecated, for removal: This API element is subject to removal in a future version.May cause performance issues, deadlocks and hangs.getClass()Answers the unique instance of java.lang.Class which represents the class of the receiver.inthashCode()Answers an integer hash code for the receiver.final voidnotify()Causes one thread which iswaiting on the receiver to be made ready to run.final voidCauses all threads which arewaiting on the receiver to be made ready to run.toString()Answers a string containing a concise, human-readable description of the receiver.final voidwait()Causes the thread which sent this message to be made not ready to run pending some change in the receiver (as indicated bynotifyornotifyAll).final voidwait(long time) Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated bynotifyornotifyAll) or the expiration of the timeout.final voidwait(long time, int frac) Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated bynotifyornotifyAll) or the expiration of the timeout.
-
Method Details
-
newInputStream
Constructs a stream that reads bytes from the given channel.The
readandtransferTomethods of the resulting stream will throw anIllegalBlockingModeExceptionif invoked while the underlying channel is in non-blocking mode. ThetransferTomethod will also throw anIllegalBlockingModeExceptionif invoked to transfer bytes to an output stream that writes to an underlying channel in non-blocking mode. The stream will not be buffered, and it will not support themarkorresetmethods. 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- The channel from which bytes will be read- Returns:
- A new input stream
-
newOutputStream
Constructs a stream that writes bytes to the given channel.The
writemethods of the resulting stream will throw anIllegalBlockingModeExceptionif 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- The channel to which bytes will be written- Returns:
- A new output stream
-
newInputStream
Constructs a stream that reads bytes from the given channel.The stream will not be buffered, and it will not support the
markorresetmethods. 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- The channel from which bytes will be read- Returns:
- A new input stream
- Since:
- 1.7
-
newOutputStream
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- The channel to which bytes will be written- Returns:
- A new output stream
- Since:
- 1.7
-
newChannel
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. Reading from the resulting channel will read from the input stream and thus block until input is available or end of file is reached. Closing the channel will in turn cause the stream to be closed.
- Parameters:
in- The stream from which bytes are to be read- Returns:
- A new readable byte channel
-
newChannel
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- The stream to which bytes are to be written- Returns:
- A new writable byte channel
-
newReader
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
minBufferCapbytes. The stream'sreadmethods 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 anIllegalBlockingModeExceptionwill be thrown. The resulting stream will not otherwise be buffered, and it will not support themarkorresetmethods. Closing the stream will in turn cause the channel to be closed.- Parameters:
ch- The channel from which bytes will be readdec- The charset decoder to be usedminBufferCap- The minimum capacity of the internal byte buffer, or-1if an implementation-dependent default capacity is to be used- Returns:
- A new reader
-
newReader
Constructs a reader that decodes bytes from the given channel according to the named charset.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))- Parameters:
ch- The channel from which bytes will be readcsName- The name of the charset to be used- Returns:
- A new reader
- Throws:
UnsupportedCharsetException- If no support for the named charset is available in this instance of the Java virtual machine
-
newReader
Constructs a reader that decodes bytes from the given channel according to the given charset.An invocation of this method of the form
behaves in exactly the same way as the expressionChannels.newReader(ch, charset)Channels.newReader(ch, charset.newDecoder(), -1)The reader's default action for malformed-input and unmappable-character errors is to report them. When more control over the error handling is required, the constructor that takes a CharsetDecoder should be used.
- Parameters:
ch- The channel from which bytes will be readcharset- The charset to be used- Returns:
- A new reader
- Since:
- 10
-
newWriter
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
minBufferCapbytes. The stream'swritemethods 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 anIllegalBlockingModeExceptionwill be thrown. The resulting stream will not otherwise be buffered. Closing the stream will in turn cause the channel to be closed.- Implementation Note:
- The value of
minBufferCapis ignored. - Parameters:
ch- The channel to which bytes will be writtenenc- The charset encoder to be usedminBufferCap- The minimum capacity of the internal byte buffer, or-1if an implementation-dependent default capacity is to be used. The value ofminBufferCapmay be ignored- Returns:
- A new writer
-
newWriter
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
behaves in exactly the same way as the expressionChannels.newWriter(ch, csname)Channels.newWriter(ch, Charset.forName(csName))- Parameters:
ch- The channel to which bytes will be writtencsName- The name of the charset to be used- Returns:
- A new writer
- Throws:
UnsupportedCharsetException- If no support for the named charset is available in this instance of the Java virtual machine
-
newWriter
Constructs a writer that encodes characters according to the given charset and writes the resulting bytes to the given channel.An invocation of this method of the form
behaves in exactly the same way as the expressionChannels.newWriter(ch, charset)Channels.newWriter(ch, charset.newEncoder(), -1)The writer's default action for malformed-input and unmappable-character errors is to report them. When more control over the error handling is required, the constructor that takes a CharsetEncoder should be used.
- Parameters:
ch- The channel to which bytes will be writtencharset- The charset to be used- Returns:
- A new writer
- Since:
- 10
-