List of usage examples for java.nio ByteBuffer put
public ByteBuffer put(ByteBuffer src)
From source file:com.alibaba.otter.shared.common.utils.ByteUtils.java
public static long bytes2long(byte[] b) { ByteBuffer buf = ByteBuffer.allocate(8); buf.put(b); buf.flip();/* www . ja v a 2 s . c om*/ return buf.getLong(); }
From source file:com.offbynull.portmapper.common.ByteBufferUtils.java
/** * Copy the remaining content of a {@link ByteBuffer} in to a new non-direct {@link ByteBuffer}. * @param src buffer to copy//from ww w . j a va 2s .c o m * @param incrementSrc of {@code true} increments {@code src}'s position * @param incrementDst of {@code true} increments {@code dst}'s position * @return new buffer with the remaining content in {@code src} * @throws NullPointerException if any arguments are {@code null} */ public static ByteBuffer copyContents(ByteBuffer src, boolean incrementSrc, boolean incrementDst) { Validate.notNull(src); if (!incrementSrc) { src.mark(); } ByteBuffer dst = ByteBuffer.allocate(src.remaining()); dst.put(src); if (!incrementSrc) { src.reset(); } if (!incrementDst) { dst.flip(); } return dst; }
From source file:Main.java
public static AdvertiseData createAllOffAdvertiseData() { byte[] manufacturerData = new byte[23]; ByteBuffer bb = ByteBuffer.wrap(manufacturerData); bb.order(ByteOrder.BIG_ENDIAN); bb.put((byte) 0x41); bb.put((byte) 0x6c); bb.put((byte) 0x6c); bb.put((byte) 0x4f); bb.put((byte) 0x66); bb.put((byte) 0x66); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); AdvertiseData.Builder builder = new AdvertiseData.Builder(); builder.addManufacturerData(0x006d, manufacturerData); AdvertiseData adv = builder.build(); return adv;// w ww .j a v a 2 s. c o m }
From source file:Main.java
/** create AdvertiseDate for iBeacon */ public static AdvertiseData createLightOnAdvertiseData() { byte[] manufacturerData = new byte[23]; ByteBuffer bb = ByteBuffer.wrap(manufacturerData); bb.order(ByteOrder.BIG_ENDIAN); bb.put((byte) 0x4c); bb.put((byte) 0x69); bb.put((byte) 0x67); bb.put((byte) 0x68); bb.put((byte) 0x74); bb.put((byte) 0x4f); bb.put((byte) 0x6e); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); AdvertiseData.Builder builder = new AdvertiseData.Builder(); builder.addManufacturerData(0x006d, manufacturerData); AdvertiseData adv = builder.build(); return adv;//www .j ava 2 s . c om }
From source file:Main.java
/** create AdvertiseDate for iBeacon */ public static AdvertiseData createAllOnAdvertiseData() { byte[] manufacturerData = new byte[23]; ByteBuffer bb = ByteBuffer.wrap(manufacturerData); bb.order(ByteOrder.BIG_ENDIAN); bb.put((byte) 0x41); bb.put((byte) 0x6c); bb.put((byte) 0x6c); bb.put((byte) 0x4f); bb.put((byte) 0x6e); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); AdvertiseData.Builder builder = new AdvertiseData.Builder(); builder.addManufacturerData(0x006d, manufacturerData); AdvertiseData adv = builder.build(); return adv;/* w ww. j a v a 2 s . c o m*/ }
From source file:Main.java
public static void writeVideoHeader(ByteBuffer buffer, int flvVideoFrameType, int codecID, int AVCPacketType) { byte first = (byte) (((flvVideoFrameType & 0x0F) << 4) | (codecID & 0x0F)); buffer.put(first); buffer.put((byte) AVCPacketType); buffer.put((byte) 0x00); buffer.put((byte) 0x00); buffer.put((byte) 0x00); }
From source file:Main.java
static void putString(final ByteBuffer buf, String value) { final int length = value.length(); putInt(buf, length);//from w w w . j a v a2 s. co m for (int i = 0; i < length; ++i) { buf.put((byte) value.charAt(i)); } buf.put((byte) 0); }
From source file:Main.java
private static ByteBuffer allocateMore(ByteBuffer output) { if (output.capacity() == 0) { return ByteBuffer.allocate(1); }//from w ww . j a v a2 s . c om ByteBuffer result = ByteBuffer.allocate(output.capacity() * 2); output.flip(); result.put(output); return result; }
From source file:Main.java
/** * Split int value into two byte buffer. First byte of int will be written to first byte buffer and second to second one. How many * bytes will be written to first buffer determines based on <code>buffer.remaining()</code> value * // w w w.ja v a 2s . c o m * @param buffer * to write first part of value * @param buffer1 * to write second part of value */ public static void splitIntToBuffers(ByteBuffer buffer, ByteBuffer buffer1, int iValue) { int remaining = buffer.remaining(); int i; for (i = 0; i < remaining; ++i) { buffer.put((byte) (MASK & (iValue >>> SIZE_OF_BYTE_IN_BITS * (SIZE_OF_INT - i - 1)))); } for (int j = 0; j < SIZE_OF_INT - remaining; ++j) { buffer1.put((byte) (MASK & (iValue >>> SIZE_OF_BYTE_IN_BITS * (SIZE_OF_INT - i - j - 1)))); } }
From source file:Main.java
/** * Split long value into two byte buffer. First byte of long will be written to first byte buffer and second to second one. How * many bytes will be written to first buffer determines based on <code>buffer.remaining()</code> value * /*from ww w . j a v a 2 s . com*/ * @param buffer * to write first part of value * @param buffer1 * to write second part of value */ public static void splitLongToBuffers(ByteBuffer buffer, ByteBuffer buffer1, long iValue) { int remaining = buffer.remaining(); int i; for (i = 0; i < remaining; ++i) { buffer.put((byte) (iValue >> SIZE_OF_BYTE_IN_BITS * (SIZE_OF_LONG - i - 1))); } for (int j = 0; j < SIZE_OF_LONG - remaining; ++j) { buffer1.put((byte) (iValue >> SIZE_OF_BYTE_IN_BITS * (SIZE_OF_LONG - i - j - 1))); } }