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

private static byte[] longToBytes(long paramLong) {
    ByteBuffer localByteBuffer = ByteBuffer.allocate(8);
    localByteBuffer.putLong(paramLong);//from w w w .  j  ava 2 s .  co  m
    return localByteBuffer.array();
}

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

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

From source file:org.hawkular.metrics.core.api.AvailabilityType.java

public static AvailabilityType fromBytes(ByteBuffer bytes) {
    switch (bytes.array()[bytes.position()]) {
    case 0://from   w w  w  .j  av  a 2  s .c  o m
        return UP;
    case 1:
        return DOWN;
    case 2:
        return UNKNOWN;
    default:
        throw new IllegalArgumentException(bytes.array()[0] + " is not a recognized availability type");
    }
}

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 static byte[] bitmapToByteArray(Bitmap bitmap) {
    int bytes = bitmap.getByteCount();
    ByteBuffer buf = ByteBuffer.allocate(bytes);
    bitmap.copyPixelsToBuffer(buf);//from  w w  w.  ja v a2  s. com
    byte[] byteArray = buf.array();
    return byteArray;
}

From source file:Main.java

public static byte[] bitmapToByteArray(Bitmap bitmap) {
    //int numBytes = bitmap.getWidth() + bitmap.getHeight() * 4;
    int numBytes = bitmap.getByteCount();
    ByteBuffer byteBuffer = ByteBuffer.allocate(numBytes);
    bitmap.copyPixelsToBuffer(byteBuffer);
    return byteBuffer.array();
}

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 static byte[] getIntArray(int val) {
    ByteBuffer typeBuffer = ByteBuffer.allocate(4).order(ByteOrder.BIG_ENDIAN);
    typeBuffer.putInt(val);
    return typeBuffer.array();
}

From source file:Main.java

public final static void replaceP(final ByteBuffer lineBB, final byte from, final byte to) {
    final byte[] array = lineBB.array();
    final int offset = lineBB.position();
    final int limit = lineBB.limit();
    replace(array, offset, limit, from, to);
}

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());
}