List of utility methods to do CharBuffer
char[] | asChars(CharBuffer buffer) as Chars final char[] data = new char[buffer.limit()]; System.arraycopy(buffer.array(), 0, data, 0, buffer.limit()); return data; |
int | capacityRemaining(CharBuffer buffer) capacity Remaining return buffer.limit() - buffer.position();
|
char[] | charBufferToChars(CharBuffer buffer) char Buffer To Chars final char[] array = buffer.array(); final int arrayOffset = buffer.arrayOffset(); return Arrays.copyOfRange(array, arrayOffset + buffer.position(), arrayOffset + buffer.limit()); |
String | consume(CharBuffer buf, boolean trim) consume buf.flip(); int offset = 0; int end = buf.limit(); if (trim) { while (offset < end && buf.get(offset) == ' ') offset++; while (end > offset && buf.get(end - 1) == ' ') end--; ... |
char[] | convertCharBufferToArray(java.nio.CharBuffer buf) convert Char Buffer To Array if (buf.hasArray()) { return buf.array(); } else { buf.rewind(); char[] array = new char[buf.remaining()]; int index = 0; while (buf.hasRemaining()) { array[index++] = buf.get(); ... |
void | eraseCharBuffer(CharBuffer buffer) erase Char Buffer char[] data = buffer.array(); long limit = buffer.arrayOffset() + buffer.limit(); for (int i = buffer.arrayOffset(); i < limit; i++) data[i] = 0xAA; for (int i = buffer.arrayOffset(); i < limit; i++) data[i] = 0x55; for (int i = buffer.arrayOffset(); i < limit; i++) data[i] = 0x00; ... |
CharBuffer | extendBuffer(CharBuffer buffer, int size) extend Buffer final CharBuffer localBuffer = CharBuffer.allocate(buffer.capacity() + size); System.arraycopy(buffer.array(), 0, localBuffer.array(), 0, buffer.position()); localBuffer.position(buffer.position()); return localBuffer; |
char[] | getCharsFromBufferAndReset(CharBuffer buffer) Copy the chars out of a buffer from 0 to the current position, resets the position to 0 final int len = buffer.position(); final char[] chars = new char[len]; System.arraycopy(buffer.array(), 0, chars, 0, len); buffer.position(0); return chars; |
boolean | nextEquals(final CharBuffer buffer, final char next) next Equals if (!buffer.hasRemaining()) { return false; return buffer.get(buffer.position()) == next; |
void | printBuffer(CharBuffer charBuffer) print Buffer charBuffer.mark(); int remain = charBuffer.remaining(); char[] ch = new char[remain]; charBuffer.get(ch, 0, remain); System.out.print(new String(ch)); charBuffer.reset(); |