Java CharBuffer consume(CharBuffer buf, boolean trim)

Here you can find the source of consume(CharBuffer buf, boolean trim)

Description

consume

License

Open Source License

Declaration

public static String consume(CharBuffer buf, boolean trim) 

Method Source Code

//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;
    }
}

Related

  1. asChars(CharBuffer buffer)
  2. capacityRemaining(CharBuffer buffer)
  3. charBufferToChars(CharBuffer buffer)
  4. convertCharBufferToArray(java.nio.CharBuffer buf)
  5. eraseCharBuffer(CharBuffer buffer)
  6. extendBuffer(CharBuffer buffer, int size)
  7. getCharsFromBufferAndReset(CharBuffer buffer)