for (char c : s.toCharArray()) {
buf.putChar(c);
System.err.print(c);
}
System.err.println("\nlimit: " + buf.limit());
buf.rewind();
char[] charArray = new char[s.length()];
for (int i = 0; i < s.length(); i++) {
charArray[i] = buf.getChar();
System.err.print(charArray[i]);
}