Java Utililty Methods CharBuffer

List of utility methods to do CharBuffer

Description

The list of methods to do CharBuffer are organized into topic(s).

Method

voidprintCharBuffer(CharBuffer msg)
print Char Buffer
System.out.println("---------------------------------------------------------------------------- \n" + msg
        + "\n----------------------------------------------------------------------------");
CharBufferput(char c, CharBuffer buffer)
Add the character to the buffer, extending the buffer if needed
CharBuffer localBuf = buffer;
if (capacityRemaining(buffer) < 1) {
    localBuf = extendBuffer(buffer, BLOCK_SIZE);
localBuf.put(c);
return localBuf;
intsearchNewline(CharBuffer buffer, int from)
Scan for a newline sequence in the given CharBuffer, starting at position from until buffer.position().
int to = buffer.position();
if (from >= to) {
    return -1;
char[] chars = buffer.array();
for (int i = from; i < to; i++) {
    if (chars[i] == '\n' || (chars[i] == '\r' && i < to - 1)) {
        return i;
...
BooleanstartsWith(final CharBuffer charBuffer, final String token)
starts With
charBuffer.mark();
try {
    for (int i = 0; i < token.length(); i++) {
        if (!charBuffer.hasRemaining()) {
            return false;
        final char cb = charBuffer.get();
        final char ct = token.charAt(i);
...
char[]toCharArray(CharBuffer charBuffer)
to Char Array
char[] chars = new char[charBuffer.remaining()];
charBuffer.get(chars);
return chars;
CharBuffertoCharBuffer(int[] codePoints)
to Char Buffer
final char[] chars = new char[codePoints.length * 2];
int i = 0;
for (int cp : codePoints) {
    i += Character.toChars(cp, chars, i);
return CharBuffer.wrap(chars, 0, i);
voidzeroCharBuffer(CharBuffer buf)
zero Char Buffer
Arrays.fill(buf.array(), buf.arrayOffset(), buf.arrayOffset() + buf.limit(), (char) 0);