Here you can find the source of consume(CharBuffer buf, boolean trim)
public static String consume(CharBuffer buf, boolean trim)
//package com.java2s; //License from project: Open Source License import java.nio.CharBuffer; public class Main { public static String consume(CharBuffer buf, boolean trim) { buf.flip();/*from w ww .j a va 2 s . c o m*/ 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[] result = new char[end - offset]; buf.position(offset); buf.get(result).clear(); return new String(result); } public static <T> T get(T[] items, int index) { if (items == null || index < 0) return null; return (items.length > index) ? items[index] : null; } }