List of usage examples for java.nio ByteBuffer array
public final byte[] array()
From source file:Main.java
public static final int compareTo(ByteBuffer bb1, ByteBuffer bb2) { return compareTo(bb1.array(), 0, bb1.limit(), bb2.array(), 0, bb2.limit()); }
From source file:Main.java
public static Object getObject(ByteBuffer byteBuffer) throws ClassNotFoundException, IOException { InputStream input = new ByteArrayInputStream(byteBuffer.array()); ObjectInputStream oi = new ObjectInputStream(input); Object obj = oi.readObject(); input.close();//from w ww . j a v a 2s .c o m oi.close(); byteBuffer.clear(); return obj; }
From source file:Main.java
public final static boolean equalsP(final ByteBuffer bb1, final ByteBuffer bb2) { final byte[] array1 = bb1.array(); final byte[] array2 = bb2.array(); final int offset1 = bb1.position(); final int offset2 = bb2.position(); final int end1 = bb1.limit(); final int end2 = bb2.limit(); return equals(array1, offset1, end1, array2, offset2, end2); }
From source file:crocserver.app.CrocSecurity.java
private static byte[] toByteArray(long value) { ByteBuffer buffer = ByteBuffer.allocate(8); buffer.putLong(value);//from w w w. j a v a2 s . c om return buffer.array(); }
From source file:net.sf.jml.util.DigestUtils.java
private static void update(MessageDigest digest, ByteBuffer buffer) { if (buffer.hasArray()) { digest.update(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining()); } else {/* w w w . j a v a2s .c om*/ byte[] b = new byte[buffer.remaining()]; buffer.get(b); digest.update(b); } }
From source file:Main.java
public static byte[] sumByte(byte[] bytes1, byte[] bytes2) { ByteBuffer byteBuffer = ByteBuffer.allocate(bytes1.length + bytes2.length); byteBuffer.put(bytes1);//from w w w . j a v a 2 s. c o m byteBuffer.put(bytes2); return byteBuffer.array(); }
From source file:com.amazon.janusgraph.diskstorage.dynamodb.builder.AbstractBuilder.java
public static String encodeKeyBuffer(StaticBuffer input) { if (input == null || input.length() == 0) { return null; }//from w w w. j a v a2s . c o m ByteBuffer buf = input.asByteBuffer(); byte[] bytes = Arrays.copyOf(buf.array(), buf.limit()); return Hex.encodeHexString(bytes); }
From source file:Main.java
/** * //from ww w. j a v a2s .c om * @param bb * @param offset * @param len * relative * @return */ public final static byte[] toBytes(final ByteBuffer bb, int offset, int len) { final byte[] result = new byte[len]; System.arraycopy(bb.array(), offset, result, 0, len); return result; }
From source file:Main.java
public static void putMessageLength(byte[] message) { ByteBuffer lengthBuffer = ByteBuffer.allocate(4).order(ByteOrder.BIG_ENDIAN); lengthBuffer.putInt(message.length); byte[] lenArray = lengthBuffer.array(); for (int i = 0; i < 4; i++) message[i] = lenArray[i];/*from w w w . j av a 2 s. c om*/ }
From source file:Main.java
public static byte[] shortToByteArray(short value) { ByteBuffer buffer = ByteBuffer.allocate(Short.SIZE / Byte.SIZE); buffer.order(ByteOrder.BIG_ENDIAN); buffer.putShort(value);/*from w w w. ja v a 2 s . c om*/ return buffer.array(); }