List of usage examples for java.nio ByteBuffer putLong
public abstract ByteBuffer putLong(long value);
From source file:org.openmrs.module.casereport.DocumentUtil.java
/** * Converts the specified uuid to its decimal representation * //from w w w .ja v a 2 s . co m * @param uuid the uuid to convert * @return a string representation of the decimal number */ public static String convertToDecimal(UUID uuid) { ByteBuffer bb = ByteBuffer.wrap(new byte[16]); bb.putLong(uuid.getMostSignificantBits()); bb.putLong(uuid.getLeastSignificantBits()); BigInteger bi = new BigInteger(bb.array()); //Get the unsigned representation for -ve numbers if (bi.compareTo(BigInteger.ZERO) < 0) { bi = DECIMAL_REP_COUNT.add(bi); } return bi.toString(); }
From source file:org.zper.ZPUtils.java
synchronized public static byte[] genTopicIdentity(String topic, int flag) { byte[] identity = new byte[1 + 2 + topic.length() + 16]; ByteBuffer buf = ByteBuffer.wrap(identity); UUID uuid = UUID.randomUUID(); buf.put((byte) topic.hashCode()); buf.put((byte) flag); buf.put((byte) topic.length()); buf.put(topic.getBytes());//from w w w. j av a 2 s. c om buf.putLong(uuid.getMostSignificantBits()); buf.putLong(uuid.getLeastSignificantBits()); return identity; }
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); return buffer.array(); // buffer.get(bytes); /*//from ww w .j a va 2 s.c o m 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:org.hobbit.core.rabbit.RabbitMQUtils.java
/** * Creates a byte array representing the given long value. * * @param value/*from w w w . java2s .co m*/ * the value that should be serialized * @return the byte array containing the given long value */ public static byte[] writeLong(long value) { ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES); buffer.putLong(value); return buffer.array(); }
From source file:com.datatorrent.contrib.hdht.HDHTDynamicPartitioningTest.java
static Slice getLongByteArray(long key) { ByteBuffer bb = ByteBuffer.allocate(8); bb.putLong(key); return new Slice(bb.array()); }
From source file:com.monitor.baseservice.utils.XCodeUtil.java
public static byte[] longToByteArray(long value) { ByteBuffer bb = ByteBuffer.allocate(Long.SIZE / Byte.SIZE); bb.order(ByteOrder.LITTLE_ENDIAN); bb.putLong(value); return bb.array(); }
From source file:com.codelanx.codelanxlib.util.auth.UUIDFetcher.java
/** * Converts a {@link UUID} into bytes//from w w w .jav a2s . c o m * * @since 0.0.1 * @version 0.0.1 * * @param uuid The {@link UUID} to convert * @return The new byte array */ public static byte[] toBytes(UUID uuid) { ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[16]); byteBuffer.putLong(uuid.getMostSignificantBits()); byteBuffer.putLong(uuid.getLeastSignificantBits()); return byteBuffer.array(); }
From source file:com.inmobi.messaging.util.AuditUtil.java
public static void attachHeaders(Message m, Long timestamp) { byte[] b = m.getData().array(); int messageSize = b.length; int totalSize = messageSize + HEADER_LENGTH; ByteBuffer buffer = ByteBuffer.allocate(totalSize); // writing version buffer.put((byte) currentVersion); // writing magic bytes buffer.put(magicBytes);/* w ww . jav a2s . com*/ // writing timestamp long time = timestamp; buffer.putLong(time); // writing message size buffer.putInt(messageSize); // writing message buffer.put(b); buffer.rewind(); m.set(buffer); // return new Message(buffer); }
From source file:io.stallion.utils.GeneralUtils.java
/** * Turn the given long id into a random base32 string token. This can be used for generating unique, secret strings * for accessing data, such as a web page only viewable by a secret string. By using the long id, of the * underlying object we guarantee uniqueness, by adding on random characters, we make the URL nigh * impossible to guess./*w ww. j a v a2 s .co m*/ * * @param id - a long id that will be convered to base32 and used as the first part of the string * @param length - the number of random base32 characters to add to the end of the string * @return */ public static String tokenForId(Long id, int length) { ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES); buffer.putLong(id); return StringUtils.stripStart(new Base32().encodeAsString(buffer.array()), "A").replace("=", "") .toLowerCase() + "8" + randomTokenBase32(length); }
From source file:edu.stanford.mobisocial.dungbeetle.model.DbObject.java
private static int colorFor(Long hash) { float[] baseHues = Feed.getBaseHues(); ByteBuffer bos = ByteBuffer.allocate(8); bos.putLong(hash); byte[] hashBytes = new byte[8]; bos.position(0);/*from w ww .j a v a 2 s .c o m*/ bos.get(hashBytes); SecureRandom r = new SecureRandom(hashBytes); float hsv[] = new float[] { baseHues[r.nextInt(baseHues.length)], r.nextFloat(), r.nextFloat() }; hsv[0] = hsv[0] + 20 * r.nextFloat() - 10; hsv[1] = hsv[1] * 0.2f + 0.8f; hsv[2] = hsv[2] * 0.2f + 0.8f; return Color.HSVToColor(hsv); }