Example usage for java.nio ByteBuffer wrap

List of usage examples for java.nio ByteBuffer wrap

Introduction

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

Prototype

public static ByteBuffer wrap(byte[] array) 

Source Link

Document

Creates a new byte buffer by wrapping the given byte array.

Usage

From source file:jp.queuelinker.system.util.SerializeUtil.java

/**
 * Serializes an object to a ByteBuffer.
 * @param obj An object to be serialized.
 * @return A ByteBuffer maintains the serialized data.
 *///from   ww  w. j a  v  a2 s. com
public static ByteBuffer serializeToByteBuffer(final Object obj) {
    return ByteBuffer.wrap(serializeToBytes(obj));
}

From source file:haxball.util.Serializer.java

public static float byteArrayToFloat(@NonNull byte data[]) {
    return ByteBuffer.wrap(data).getFloat();
}

From source file:com.amazonaws.mobileconnectors.kinesis.kinesisrecorder.JSONRecordAdapter.java

/**
 * returns data from json object which was made via translateFromRecord.
 *
 * @param jsonObject the json./*from   w  w  w .  j av  a2  s. c om*/
 * @throws JSONException
 */
public static ByteBuffer getData(JSONObject jsonObject) throws JSONException {
    return ByteBuffer.wrap(Base64.decode(jsonObject.getString(DATA_FIELD_KEY), Base64.DEFAULT));
}

From source file:com.willetinc.hadoop.mapreduce.dynamodb.AttributeValueIOUtils.java

public static AttributeValue read(Types type, DataInput in) throws IOException {
    AttributeValue value = new AttributeValue();
    switch (type) {
    case STRING:/*from  w w w  . j ava 2  s  .  c  om*/
        value.withS(Text.readString(in));
        break;
    case NUMBER:
        value.withN(Text.readString(in));
        break;
    case BINARY:
        byte[] bytes = WritableUtils.readCompressedByteArray(in);
        ByteBuffer buf = ByteBuffer.wrap(bytes);
        value.withB(buf);
    case STRING_SET:
    case NUMBER_SET:
    case BINARY_SET: {
        // handle sets
        int size = in.readInt();
        List<AttributeValue> values = new ArrayList<AttributeValue>(size);
        for (int i = 0; i < size; i++) {
            switch (type) {
            case STRING_SET:
                values.add(read(Types.STRING, in));
                break;
            case NUMBER_SET:
                values.add(read(Types.NUMBER, in));
                break;
            case BINARY_SET:
                values.add(read(Types.BINARY, in));
                break;
            default:
                throw new IOException("Nested sets of sets are not permitted");
            }
        }
        break;
    }
    }

    return value;
}

From source file:info.gehrels.flockDBClient.ByteHelper.java

static long[] toLongArray(byte[] ids) {
    LongBuffer buffy = ByteBuffer.wrap(ids).order(ByteOrder.LITTLE_ENDIAN).asLongBuffer();
    long[] result = new long[buffy.capacity()];

    int i = 0;/*from   www .j  a v a 2  s  .co m*/
    while (buffy.hasRemaining()) {
        result[i++] = buffy.get();
    }

    return result;
}

From source file:com.networknt.utility.Util.java

/**
 * Generate UUID across the entire app and it is used for correlationId.
 *
 * @return String correlationId/*ww  w  . jav  a 2  s . co  m*/
 */
public static String getUUID() {
    UUID id = UUID.randomUUID();
    ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
    bb.putLong(id.getMostSignificantBits());
    bb.putLong(id.getLeastSignificantBits());
    return Base64.encodeBase64URLSafeString(bb.array());
}

From source file:com.github.koraktor.steamcondenser.PacketBuffer.java

/**
 * Creates a new packet buffer from the given byte array
 *
 * @param data The data wrap into the underlying byte buffer
 *///from   w  ww .  j av a2s  .co m
public PacketBuffer(byte[] data) {
    this.byteBuffer = ByteBuffer.wrap(data);
}

From source file:com.shuffle.p2p.Bytestring.java

public Bytestring prepend(Bytestring pre) {
    ByteBuffer target = ByteBuffer.wrap(new byte[bytes.length + pre.bytes.length]);
    target.put(pre.bytes);//from   w  w w  . j  a  v  a2s. c  o  m
    target.put(bytes);
    return new Bytestring(target.array());
}

From source file:com.srotya.tau.nucleus.Utils.java

public static long byteToLong(byte[] x) {
    ByteBuffer buffer = ByteBuffer.wrap(x);
    return buffer.getLong();
}

From source file:com.eventsourcing.layout.types.ByteArrayTypeHandler.java

@Override
public int hashCode() {
    return ByteBuffer.wrap(getFingerprint()).hashCode();
}