Class NioExamples

java.lang.Object
net.jrodolfo.java_evolution.java04.NioExamples

public class NioExamples extends Object
Demonstrates Java 4 NIO buffers and channels.
  • Constructor Details

    • NioExamples

      public NioExamples()
  • Method Details

    • writeText

      public void writeText(WritableByteChannel channel, String text) throws IOException
      Writes text through a channel backed by a byte buffer.
      Parameters:
      channel - destination channel
      text - text to write
      Throws:
      IOException - when writing fails
    • readText

      public String readText(ReadableByteChannel channel) throws IOException
      Reads text from a channel using explicit buffer flip and clear phases.
      Parameters:
      channel - source channel
      Returns:
      decoded text
      Throws:
      IOException - when reading fails

      Note: 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.