import java.nio.CharBuffer;
/**
* Test buffer duplication.
*/
public class MainClass {
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();
println(buffer);
println(dupeBuffer);
dupeBuffer.reset();
println(dupeBuffer);
dupeBuffer.clear();
println(dupeBuffer);
}
private static void println(CharBuffer cb) {
System.out.println("pos=" + cb.position() + ", limit=" + cb.limit() + ", capacity="
+ cb.capacity() + ": '" + cb + "'");
}
}
/**/
pos=0, limit=8, capacity=8: '01234567'
pos=5, limit=6, capacity=8: '5'
pos=3, limit=6, capacity=8: '345'
pos=0, limit=8, capacity=8: '01234567'