List of usage examples for java.nio ByteBuffer array
public final byte[] array()
From source file:Main.java
public static byte[] floatsToBytes(float[] floats) { ByteBuffer byteBuffer = ByteBuffer.allocate(floats.length * 4); byteBuffer.asFloatBuffer().put(floats); return byteBuffer.array(); }
From source file:Main.java
public final static boolean equalsP(final ByteBuffer bb, final byte[] bytes) { return equals(bb.array(), bb.position(), bytes); }
From source file:Main.java
public final static boolean equals(final ByteBuffer bb1, final ByteBuffer bb2) { final byte[] array1 = bb1.array(); final byte[] array2 = bb2.array(); final int end1 = bb1.limit(); final int end2 = bb2.limit(); return equals(array1, 0, end1, array2, 0, end2); }
From source file:Main.java
public static String convertBitmapToBase64(Bitmap bitmap) { final int size = bitmap.getByteCount(); ByteBuffer dst = ByteBuffer.allocate(size); bitmap.copyPixelsToBuffer(dst);// w ww . ja v a 2 s.co m return Base64.encodeToString(dst.array(), Base64.DEFAULT); }
From source file:Main.java
/** * Returns an MD-5 digest of the database encryption password. * <blockquote>This algorithm performs an MD-5 hash on a UTF-8 representation of the password.</blockquote> * * @param pass The plain encryption password * * @return The database encryption password digest * * @throws NoSuchAlgorithmException If the platform doesn't support MD-5 *//*w w w. j a va 2 s .c o m*/ public static byte[] passToDigest(char[] pass) throws NoSuchAlgorithmException { // FIXME: Enhance security for this method Charset cs = Charset.forName("UTF-8"); MessageDigest md = MessageDigest.getInstance("MD5"); ByteBuffer bbuf = cs.encode(CharBuffer.wrap(pass)); byte[] bpass = Arrays.copyOf(bbuf.array(), bbuf.remaining()); return md.digest(bpass); }
From source file:Main.java
public static byte[] byteBufferToByteArray(ByteBuffer byteBuffer) { if (wrapsFullArray(byteBuffer)) { return byteBuffer.array(); }//from w w w . jav a 2s. com byte[] target = new byte[byteBuffer.remaining()]; byteBufferToByteArray(byteBuffer, target, 0); return target; }
From source file:Main.java
/** * Converts a given integer to byte, in little endian * @param i An integer to be converted to byte * @return A byte array stores byte representation of given integer *///from w w w . j a v a 2 s .com public static byte[] intToByte(int i) { ByteBuffer b = ByteBuffer.allocate(4); b.order(ByteOrder.LITTLE_ENDIAN); b.putInt(i); byte buf[] = b.array(); return buf; }
From source file:com.moscona.dataSpace.debug.ByteBufferTest.java
public static void print(String label, ByteBuffer buf) { System.out.println(label + ":"); ArrayList<String> l = new ArrayList<String>(); for (byte b : buf.array()) { l.add(Byte.toString(b));// w w w . j a v a 2 s . c o m } System.out.println(" " + StringUtils.join(l, ", ")); }
From source file:com.ebay.nest.io.sede.lazy.LazyDate.java
/** * Writes a Date in SQL date format to the output stream. * @param out// ww w .j a va 2 s . c o m * The output stream * @param i * The Date to write * @throws IOException */ public static void writeUTF8(OutputStream out, DateWritable d) throws IOException { ByteBuffer b = Text.encode(d.toString()); out.write(b.array(), 0, b.limit()); }
From source file:Main.java
public static byte[] shortToByteArray(int value) { ByteBuffer bb = ByteBuffer.allocate(2); bb.order(ByteOrder.LITTLE_ENDIAN); bb.putShort((short) value); return bb.array(); }