Example usage for java.nio ByteBuffer array

List of usage examples for java.nio ByteBuffer array

Introduction

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

Prototype

public final byte[] array() 

Source Link

Document

Returns the byte array which this buffer is based on, if there is one.

Usage

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:com.srotya.tau.nucleus.Utils.java

public static byte[] longToBytes(long x) {
    ByteBuffer buffer = ByteBuffer.allocate(8);
    buffer.putLong(x);//from ww  w.j av  a 2  s. c  o m
    return buffer.array();
}

From source file:mvm.rya.indexing.accumulo.freetext.ColumnPrefixes.java

private static Text concat(Text prefix, String str) {
    Text temp = new Text(prefix);

    try {/*from w  w w  .jav a2s .c  o m*/
        ByteBuffer buffer = Text.encode(str, false);
        temp.append(buffer.array(), 0, buffer.limit());
    } catch (CharacterCodingException cce) {
        throw new IllegalArgumentException(cce);
    }

    return temp;
}

From source file:Main.java

public static final int indexOfP(final ByteBuffer bb, final byte b) {
    return indexOf(bb.array(), bb.position(), bb.remaining(), b);
}

From source file:Main.java

public static final int indexOf(final ByteBuffer bb, final byte b) {
    return indexOf(bb.array(), 0, bb.limit(), b);
}

From source file:Main.java

public static byte[] bitmapToBytes(Bitmap b) {
    //calculate how many bytes our image consists of.
    int bytes = b.getByteCount();
    //or we can calculate bytes this way. Use a different value than 4 if you don't use 32bit images.
    //int bytes = b.getWidth()*b.getHeight()*4;

    ByteBuffer buffer = ByteBuffer.allocate(bytes); //Create a new buffer
    b.copyPixelsToBuffer(buffer); //Move the byte data to the buffer

    byte[] array = buffer.array();

    return array;
}

From source file:com.icloud.framework.core.nio.ByteBufferUtil.java

public static int compare(byte[] o1, ByteBuffer o2) {
    return compareUnsigned(o1, o2.array(), 0, o2.arrayOffset() + o2.position(), o1.length,
            o2.limit() + o2.arrayOffset());
}

From source file:com.images3.data.impl.ShortUUID.java

private static byte[] toByteArray(UUID uuid) {
    ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
    bb.putLong(uuid.getMostSignificantBits());
    bb.putLong(uuid.getLeastSignificantBits());
    return bb.array();
}

From source file:com.icloud.framework.core.nio.ByteBufferUtil.java

public static String string(ByteBuffer b, Charset charset) {
    return new String(b.array(), b.arrayOffset() + b.position(), b.remaining(), charset);
}