List of usage examples for java.nio ByteBuffer array
public final byte[] array()
From source file:Main.java
/** * /*from www . ja v a 2 s .c o m*/ * @param bb1 * @param offset1 * @param l1 * relative length * @param bb2 * @param offset2 * @param l2 * relative length * @return */ public static final boolean isSuccessor(final ByteBuffer bb1, final int offset1, final int l1, final ByteBuffer bb2, final int offset2, final int l2) { // return v1.compareToIgnoreCase(v2) > 0; if (l1 <= 0) { return true; } else if (l2 <= 0) { return false; } return compareTo(bb1.array(), offset1, l1, bb2.array(), offset2, l2) > 0; }
From source file:ConversionUtil.java
public static byte[] convertToByteArray(float value) { byte[] bytes = new byte[4]; ByteBuffer buffer = ByteBuffer.allocate(bytes.length); buffer.putFloat(value);//from ww w . j av a2 s . com return buffer.array(); // buffer.get(bytes); // return bytes; // return convertToByteArray(Float.floatToIntBits(value)); }
From source file:com.amazonaws.services.sqs.MessageMD5ChecksumHandler.java
/** * Update the digest using a sequence of bytes that consists of the length * (in 4 bytes) of the input String and the actual utf8-encoded byte values. *//*from w ww . j a va 2s . c o m*/ private static void updateLengthAndBytes(MessageDigest digest, String str) throws UnsupportedEncodingException { byte[] utf8Encoded = str.getBytes(UTF8); ByteBuffer lengthBytes = ByteBuffer.allocate(INTEGER_SIZE_IN_BYTES).putInt(utf8Encoded.length); digest.update(lengthBytes.array()); digest.update(utf8Encoded); }
From source file:ConversionUtil.java
public static byte[] convertToByteArray(double value) { byte[] bytes = new byte[8]; ByteBuffer buffer = ByteBuffer.allocate(bytes.length); buffer.putDouble(value);/*from w w w . ja va2s. com*/ return buffer.array(); // buffer.get(bytes); // return bytes; //return convertToByteArray(Double.doubleToLongBits(value)); }
From source file:com.scf.utils.UUIDUtilies.java
protected static String base58Uuid(UUID uuid) { ByteBuffer bb = ByteBuffer.wrap(new byte[16]); bb.putLong(uuid.getMostSignificantBits()); bb.putLong(uuid.getLeastSignificantBits()); return Base58.encode(bb.array()); }
From source file:ConversionUtil.java
public static byte[] convertToByteArray(int value) { byte[] bytes = new byte[4]; ByteBuffer buffer = ByteBuffer.allocate(bytes.length); buffer.putInt(value);// w w w.j av a 2 s.c om return buffer.array(); // buffer.get(bytes); /* for (int i =0;i<bytes.length; ++i) { int offset = (bytes.length -i-1) *8; bytes[i] = (byte)((value & (0xff << offset)) >>> offset); } */ // return bytes; }
From source file:domain.Employee.java
private static String uuidToBase64(String str) { UUID uuid = UUID.fromString(str); ByteBuffer bb = ByteBuffer.wrap(new byte[16]); bb.putLong(uuid.getMostSignificantBits()); bb.putLong(uuid.getLeastSignificantBits()); return Base64.encodeBase64URLSafeString(bb.array()); }
From source file:ConversionUtil.java
public static byte[] convertToByteArray(char value) { byte[] bytes = new byte[2]; ByteBuffer buffer = ByteBuffer.allocate(bytes.length); buffer.putChar(value);/*from w w w . j a v a 2 s .com*/ return buffer.array(); // buffer.get(bytes); /* for (int i =0;i<bytes.length; ++i) { int offset = (bytes.length -i-1) *8; bytes[i] = (byte)((value & (0xff << offset)) >>> offset); } **/ // return bytes; }
From source file:ConversionUtil.java
public static byte[] convertToByteArray(long value) { byte[] bytes = new byte[8]; ByteBuffer buffer = ByteBuffer.allocate(bytes.length); buffer.putLong(value);/*from w w w . ja v a 2s . c om*/ return buffer.array(); // buffer.get(bytes); /* for (int i =0;i<bytes.length; ++i) { int offset = (bytes.length -i-1) *8; bytes[i] = (byte)((value & (0xff << offset)) >>> offset); } */ // return bytes; }
From source file:ConversionUtil.java
public static byte[] convertToByteArray(short value) { byte[] bytes = new byte[2]; ByteBuffer buffer = ByteBuffer.allocate(bytes.length); buffer.putShort(value);// w ww . j a v a2 s .c om return buffer.array(); // buffer.get(bytes); /* for (int i =0;i<bytes.length; ++i) { int offset = (bytes.length -i-1) *8; bytes[i] = (byte)((value & (0xff << offset)) >>> offset); } */ // return bytes; }