Here you can find the source of toByteBuffer(byte[] data)
Parameter | Description |
---|---|
data | The data to wrap |
public static ByteBuffer toByteBuffer(byte[] data)
//package com.java2s; //License from project: Open Source License import java.nio.ByteBuffer; public class Main { /**// w w w .j a v a2 s . co m * Wraps data into a ByteBuffer prefixed by its length. * If data.length > Integer.Max, the returned data will be incoherent. * * @param data The data to wrap * @return The allocated ByteBuffer */ public static ByteBuffer toByteBuffer(byte[] data) { ByteBuffer bb = ByteBuffer.allocate(4 + data.length); bb.putInt(data.length); bb.put(data); bb.rewind(); return bb; } }