Example usage for java.nio ByteBuffer limit

List of usage examples for java.nio ByteBuffer limit

Introduction

In this page you can find the example usage for java.nio ByteBuffer limit.

Prototype

public final int limit() 

Source Link

Document

Returns the limit of this buffer.

Usage

From source file:org.apache.hadoop.hbase.PerformanceEvaluationCommons.java

public static void assertKey(final byte[] expected, final ByteBuffer got) {
    byte[] b = new byte[got.limit()];
    got.get(b, 0, got.limit());//from   w  w w  .j av  a2s.c  om
    assertKey(expected, b);
}

From source file:Main.java

/**
 * Stores substring in bb// www  .  j av a2 s  .co  m
 * 
 * @param bb
 * @param startIdx
 * @return new bb limit
 */
public static final int substring(final ByteBuffer bb, final int startIdx) {
    final int limit = bb.limit();
    if (startIdx >= limit) {
        bb.limit(0);
        return 0;
    } else {
        final byte[] array = bb.array();
        int i = 0;
        int j = startIdx;
        while (j < limit) {
            array[i] = array[j];
            j++;
            i++;
        }
        bb.limit(limit - startIdx);
        return bb.limit();
    }
}

From source file:com.google.step2.util.EncodingUtil.java

public static byte[] getUtf8Bytes(String s) {
    if (s == null) {
        return ArrayUtils.EMPTY_BYTE_ARRAY;
    }//w w w  .ja  v  a2  s.co  m
    ByteBuffer bb = UTF8.encode(s);
    return ArrayUtils.subarray(bb.array(), 0, bb.limit());
}

From source file:Main.java

public static final boolean isPredessorEquals(final ByteBuffer bb1, final ByteBuffer bb2) {
    final int l1 = bb1.limit();
    final int l2 = bb2.limit();
    return isPredessorEquals(bb1, 0, l1, bb2, 0, l2);
}

From source file:org.apache.shindig.common.util.CharsetUtil.java

/**
 * @return UTF-8 byte array for the input string.
 *//* w  ww  .j  av a2s .  c  om*/
public static byte[] getUtf8Bytes(String s) {
    if (s == null) {
        return ArrayUtils.EMPTY_BYTE_ARRAY;
    }
    ByteBuffer bb = Charsets.UTF_8.encode(s);
    return ArrayUtils.subarray(bb.array(), 0, bb.limit());

}

From source file:Main.java

public static final boolean startsWith(final ByteBuffer bb, final byte[] prefix) {
    return startsWith(bb.array(), 0, bb.limit(), prefix, 0, prefix.length);
}

From source file:Main.java

public final static boolean contains(final ByteBuffer bb1, final ByteBuffer bb2) {
    return contains(bb1.array(), 0, bb1.limit(), bb2.array(), 0, bb2.limit());
}

From source file:Main.java

public final static int countP(final ByteBuffer bb, final byte[] text) {
    final int endIdx = bb.limit();
    final byte[] array = bb.array();
    return count(array, bb.position(), endIdx, text, 0, text.length);
}

From source file:Main.java

public final static int count(final ByteBuffer bb, final byte[] text) {
    final int endIdx = bb.limit();
    final byte[] array = bb.array();
    return count(array, 0, endIdx, text, 0, text.length);
}

From source file:Main.java

public final static int count(final ByteBuffer bb1, final ByteBuffer bb2) {
    final int end1 = bb1.limit();
    final int end2 = bb2.limit();
    final byte[] array1 = bb1.array();
    final byte[] array2 = bb2.array();
    return count(array1, 0, end1, array2, 0, end2);
}