Class NioExamples
java.lang.Object
net.jrodolfo.java_evolution.java04.NioExamples
Demonstrates Java 4 NIO buffers and channels.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionreadText(ReadableByteChannel channel) Reads text from a channel using explicit buffer flip and clear phases.voidwriteText(WritableByteChannel channel, String text) Writes text through a channel backed by a byte buffer.
-
Constructor Details
-
NioExamples
public NioExamples()
-
-
Method Details
-
writeText
Writes text through a channel backed by a byte buffer.- Parameters:
channel- destination channeltext- text to write- Throws:
IOException- when writing fails
-
readText
Reads text from a channel using explicit buffer flip and clear phases.- Parameters:
channel- source channel- Returns:
- decoded text
- Throws:
IOException- when reading failsNote: this compact example decodes each buffer chunk independently and is intended for ASCII-compatible sample text. Streaming non-ASCII text with multibyte characters split across buffers requires a stateful
CharsetDecoder.
-