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:Main.java

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

From source file:com.ebay.nest.io.sede.lazy.LazyDate.java

/**
 * Writes a Date in SQL date format to the output stream.
 * @param out// w w  w  . jav a2 s .  c o  m
 *          The output stream
 * @param i
 *          The Date to write
 * @throws IOException
 */
public static void writeUTF8(OutputStream out, DateWritable d) throws IOException {
    ByteBuffer b = Text.encode(d.toString());
    out.write(b.array(), 0, b.limit());
}

From source file:Main.java

public static byte[] computeSHA1(ByteBuffer convertme, int offset, int len) {
    int oldp = convertme.position();
    int oldl = convertme.limit();
    try {/*from  w w w.  j  a va 2 s.  c  om*/
        MessageDigest md = MessageDigest.getInstance("SHA-1");
        convertme.position(offset);
        convertme.limit(len);
        md.update(convertme);
        return md.digest();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        convertme.limit(oldl);
        convertme.position(oldp);
    }
    return new byte[20];
}

From source file:Main.java

/**
 * //w  w  w.j a  v  a 2 s  .  co m
 * @param bb1
 * @param bb2
 * @return
 */
public static final boolean isSuccessor(final ByteBuffer bb1, final ByteBuffer bb2) {
    final int l1 = bb1.limit();
    final int l2 = bb2.limit();
    return isSuccessor(bb1, 0, l1, bb2, 0, l2);
}

From source file:Main.java

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

From source file:Main.java

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

From source file:com.amazon.janusgraph.diskstorage.dynamodb.builder.AbstractBuilder.java

public static String encodeKeyBuffer(StaticBuffer input) {
    if (input == null || input.length() == 0) {
        return null;
    }//from   w ww . j a va2  s.  c  o  m
    ByteBuffer buf = input.asByteBuffer();
    byte[] bytes = Arrays.copyOf(buf.array(), buf.limit());
    return Hex.encodeHexString(bytes);
}

From source file:Main.java

public static byte[] getByteArray(final ByteBuffer buff) {
    if (buff == null) {
        return null;
    }//from   w w w  . j a  v  a  2  s  .  c om
    buff.clear();
    final byte[] inds = new byte[buff.limit()];
    for (int x = 0; x < inds.length; x++) {
        inds[x] = buff.get();
    }
    return inds;
}

From source file:Main.java

public static final int stripP(ByteBuffer bb, final byte crimpChar) {
    final byte[] array = bb.array();
    final int position = bb.position();
    final int limit = bb.limit();
    return bb.limit(strip(array, position, limit, crimpChar)).limit();
}

From source file:Main.java

public final static int copyP(final ByteBuffer from, final ByteBuffer to) {
    final int offset1 = from.position();
    final int offset2 = to.position();
    final int len = from.limit() - offset1;
    return copy(from, offset1, to, offset2, len);
}