List of usage examples for java.nio ByteBuffer array
public final byte[] array()
From source file:Main.java
public static byte[] longToBytes(long x) { ByteBuffer buffer = ByteBuffer.allocate(8); buffer.putLong(0, x);// www . j a va 2 s.c o m return buffer.array(); }
From source file:Main.java
public static void setServiceDataIntoEnv(String serviceName, ByteBuffer metaData, Map<String, String> env) { byte[] byteData = metaData.array(); env.put(getPrefixServiceName(serviceName), Base64.encodeBase64String(byteData)); }
From source file:Main.java
/** * Converts an int value into an array of 4 bytes. * * @param x The int./* w w w . ja v a 2 s . c o m*/ * @return The bytes. */ public static byte[] intToBytes(final int x) { final ByteBuffer buffer = ByteBuffer.allocate(4); buffer.putInt(x); return buffer.array(); }
From source file:Main.java
public static byte[] toArray(int value) { ByteBuffer buffer = ByteBuffer.allocate(4); buffer.order(ByteOrder.LITTLE_ENDIAN); buffer.putInt(value);//from w w w.j a v a 2 s. c o m return buffer.array(); }
From source file:Main.java
public static byte[] longToBytes(long x) { ByteBuffer buffer = ByteBuffer.allocate(Long.SIZE / 8); buffer.putLong(0, x);//from www . ja va 2s . c o m return buffer.array(); }
From source file:Main.java
public static final int stripP(ByteBuffer bb, final byte crimpChar) { final byte[] array = bb.array(); final int position = bb.position(); final int limit = bb.limit(); return bb.limit(strip(array, position, limit, crimpChar)).limit(); }
From source file:Main.java
public static void toString(ByteBuffer bb, StringBuilder sb) { byte[] buf = bb.array(); int arrayOffset = bb.arrayOffset(); int offset = arrayOffset + bb.position(); int origLimit = arrayOffset + bb.limit(); int limit = (origLimit - offset > 128) ? offset + 128 : origLimit; for (int i = offset; i < limit; i++) { if (i > offset) { sb.append(" "); }//w w w.ja va2 s . c o m sb.append(paddedByteString(buf[i])); } if (origLimit != limit) { sb.append("..."); } }
From source file:Main.java
public final static void writeP(final OutputStream out, final ByteBuffer bb) throws IOException { out.write(bb.array(), bb.position(), bb.remaining()); }
From source file:Main.java
public static byte[] intToBytes(int x) { ByteBuffer buffer = ByteBuffer.allocate(4); buffer.putInt(0, x);//from ww w. jav a 2 s. com byte[] array = buffer.array(); reverseArray(array); return array; }
From source file:Main.java
private static byte[] longToBytes(long value) { ByteBuffer buffer = ByteBuffer.allocate(BYTE_BUFFER_CAPACITY); buffer.putLong(value);/*from w w w . j ava2 s . c o m*/ return buffer.array(); }