List of usage examples for java.nio ByteBuffer getLong
public abstract long getLong();
From source file:com.hengyi.japp.tools.UuidUtils.java
public static String decodeBase58Uuid(String base58uuid) { byte[] byUuid = Base58.decode(base58uuid); ByteBuffer bb = ByteBuffer.wrap(byUuid); UUID uuid = new UUID(bb.getLong(), bb.getLong()); return uuid.toString(); }
From source file:Main.java
/** * Converts an array of 8 bytes into a long. * * @param bytes The bytes.//from w ww. java 2 s .c o m * @return The long. */ public static long bytesToLong(final byte[] bytes) { final ByteBuffer buffer = ByteBuffer.allocate(8); buffer.put(bytes, 0, 8); buffer.flip(); return buffer.getLong(); }
From source file:Main.java
public static long ReadlittleEndianLong(InputStream dis) throws IOException { byte[] bytes = new byte[8]; int re = dis.read(bytes); if (re == -1) { return -1; }//from ww w .j a v a2 s. c o m ByteBuffer bytebuffer = ByteBuffer.wrap(bytes); bytebuffer.order(ByteOrder.LITTLE_ENDIAN); long result = bytebuffer.getLong(); return result; }
From source file:Main.java
public static long Uint64FromBuffer(byte[] buffer, int offset) { ByteBuffer bb = ByteBuffer.wrap(buffer, offset, 8); bb.order(ByteOrder.BIG_ENDIAN); long result = bb.getLong(); return result; }
From source file:com.srotya.tau.nucleus.Utils.java
public static long byteToLong(byte[] x) { ByteBuffer buffer = ByteBuffer.wrap(x); return buffer.getLong(); }
From source file:Main.java
static long md5sum(String text) { byte[] defaultBytes = text.getBytes(); try {//from ww w .jav a2s . c om MessageDigest algorithm = MessageDigest.getInstance("MD5"); algorithm.reset(); algorithm.update(defaultBytes); byte digest[] = algorithm.digest(); ByteBuffer buffer = ByteBuffer.wrap(digest); return buffer.getLong(); } catch (NoSuchAlgorithmException e) { Log.e("udt", "md5 failed: " + e); return 0; } }
From source file:Main.java
public static long bytesToLong(byte[] bytes) { long l = 0;/* w w w. java2s . c o m*/ try { ByteBuffer buffer = ByteBuffer.allocate(8); buffer.put(bytes, 0, bytes.length); buffer.flip();//need flip l = buffer.getLong(); } catch (Exception e) { } return l; }
From source file:com.nestedbird.util.UUIDConverter.java
/** * Converts a Base64 encoded string to a string represented UUID * * @param base64String Base64 Representation of the UUID * @return String represented UUID/*from ww w .j av a2s . c om*/ * @throws NullPointerException String must not be null * @throws IllegalArgumentException String should be 22 characters long */ public static String fromBase64(final String base64String) { if (base64String == null) throw new NullPointerException("String cannot be null"); if (base64String.length() != 22) throw new IllegalArgumentException("String should be 22 characters long"); final byte[] bytes = Base64.decodeBase64(base64String); final ByteBuffer bb = ByteBuffer.wrap(bytes); final UUID uuid = new UUID(bb.getLong(), bb.getLong()); return uuid.toString(); }
From source file:com.inmobi.messaging.util.AuditUtil.java
private static boolean isValidTimestamp(ByteBuffer buffer) { long timestamp = buffer.getLong(); if (timestamp < BASE_TIME) { LOG.debug("Invalid TimeStamp in headers [" + timestamp + "]"); return false; }//from ww w . j a v a2s .c om return true; }
From source file:Main.java
public static long bytesToLong(byte[] bytes) { ByteBuffer buffer = ByteBuffer.allocate(8); reverseArray(bytes);/* w ww . j a v a2s .c om*/ buffer.put(bytes, 0, bytes.length); buffer.flip();// need flip return buffer.getLong(); }