Example usage for java.nio CharBuffer reset

List of usage examples for java.nio CharBuffer reset

Introduction

In this page you can find the example usage for java.nio CharBuffer reset.

Prototype

public final Buffer reset() 

Source Link

Document

Resets the position of this buffer to the mark.

Usage

From source file:MainClass.java

public static void main(String[] argv) throws Exception {
    CharBuffer buffer = CharBuffer.wrap("01234567");

    buffer.position(3).limit(6).mark().position(5);

    CharBuffer dupeBuffer = buffer.duplicate();

    buffer.clear();/*from w  w  w .  j  ava  2s.  c  om*/

    println(buffer);
    println(dupeBuffer);

    dupeBuffer.reset();
    println(dupeBuffer);

    dupeBuffer.clear();
    println(dupeBuffer);
}

From source file:MainClass.java

private static void symmetricScramble(CharBuffer buffer) {
    while (buffer.hasRemaining()) {
        buffer.mark();/*from w w w.  j a va 2 s .c o  m*/
        char c1 = buffer.get();
        char c2 = buffer.get();
        buffer.reset();
        buffer.put(c2).put(c1);
    }
}