List of usage examples for java.nio ByteBuffer getLong
public abstract long getLong();
From source file:com.palantir.atlasdb.ptobject.EncodingUtils.java
public static UUID decodeUUID(byte[] bytes, int offset) { ByteBuffer buf = ByteBuffer.wrap(bytes, offset, 2 * Longs.BYTES).order(ByteOrder.BIG_ENDIAN); long mostSigBits = buf.getLong(); long leastSigBits = buf.getLong(); return new UUID(mostSigBits, leastSigBits); }
From source file:com.palantir.atlasdb.ptobject.EncodingUtils.java
public static UUID decodeFlippedUUID(byte[] bytes, int offset) { ByteBuffer buf = ByteBuffer.wrap(bytes, offset, 2 * Longs.BYTES).order(ByteOrder.BIG_ENDIAN); long mostSigBits = -1L ^ buf.getLong(); long leastSigBits = -1L ^ buf.getLong(); return new UUID(mostSigBits, leastSigBits); }
From source file:com.github.nlloyd.hornofmongo.util.BSONizer.java
@SuppressWarnings("deprecation") private static Object convertScriptableMongoToBSON(ScriptableMongoObject jsMongoObj, boolean isJsObj, String dateFormat) {/* w w w .jav a 2 s. co m*/ Object bsonObject = null; if (jsMongoObj instanceof ObjectId) { bsonObject = ((ObjectId) jsMongoObj).getRealObjectId(); } else if (jsMongoObj instanceof BinData) { BinData binData = (BinData) jsMongoObj; byte type = new Integer(binData.getType()).byteValue(); byte[] data = binData.getDataBytes(); if (type == BSON.B_UUID) { ByteBuffer dataBuffer = ByteBuffer.wrap(data); // mongodb wire protocol is little endian dataBuffer.order(ByteOrder.LITTLE_ENDIAN); long mostSigBits = dataBuffer.getLong(); long leastSigBits = dataBuffer.getLong(); bsonObject = new UUID(mostSigBits, leastSigBits); } else bsonObject = new org.bson.types.Binary(type, data); } else if (jsMongoObj instanceof MinKey) { bsonObject = new org.bson.types.MinKey(); } else if (jsMongoObj instanceof MaxKey) { bsonObject = new org.bson.types.MaxKey(); } else if (jsMongoObj instanceof NumberInt) { bsonObject = Integer.valueOf(((NumberInt) jsMongoObj).getRealInt()); } else if (jsMongoObj instanceof NumberLong) { bsonObject = Long.valueOf(((NumberLong) jsMongoObj).getRealLong()); } else if (jsMongoObj instanceof DBRef) { DBRef jsRef = (DBRef) jsMongoObj; Object id = convertJStoBSON(jsRef.getId(), isJsObj, dateFormat); bsonObject = new com.mongodb.DBRef(jsRef.getNs(), id); } else if (jsMongoObj instanceof Timestamp) { bsonObject = convertTimestampToBSONTimestamp((Timestamp) jsMongoObj); } return bsonObject; }
From source file:org.wso2.carbon.analytics.data.commons.utils.AnalyticsCommonUtils.java
public static String generateRecordID() { byte[] data = new byte[16]; secureRandom.get().nextBytes(data);//www . j a va2 s. co m ByteBuffer buff = ByteBuffer.wrap(data); return new UUID(buff.getLong(), buff.getLong()).toString(); }
From source file:co.cask.cdap.data.tools.ReplicationStatusTool.java
private static Long getTimeFromResult(Result result, String rowType) { Long timestamp = 0L;/*from www . j ava 2s .c om*/ ByteBuffer timestampBuffer = result.getValueAsByteBuffer( Bytes.toBytes(ReplicationConstants.ReplicationStatusTool.TIME_FAMILY), Bytes.toBytes(rowType)); if (timestampBuffer != null) { timestamp = timestampBuffer.getLong(); } return timestamp; }
From source file:org.lenskit.data.packed.BinaryIndexTable.java
/** * Create a binary index table.// www.j a va 2 s. c o m * @param nentries The number of entries in the table. * @param buffer The table buffer. Its position will be advanced to the end of the table. * @return The index table. */ public static BinaryIndexTable fromBuffer(int nentries, ByteBuffer buffer) { logger.debug("reading table of {} entries", nentries); long[] keys = new long[nentries]; int[] offsets = new int[nentries]; int[] sizes = new int[nentries]; // Read the index table's header (IDs, offsets, and counts/sizes). int nextExpectedOffset = 0; for (int i = 0; i < nentries; i++) { keys[i] = buffer.getLong(); if (i > 0 && keys[i - 1] >= keys[i]) { logger.error("key {} is not greater than previous key {}", keys[i], keys[i - 1]); throw new IllegalArgumentException("corrupted index table"); } offsets[i] = buffer.getInt(); sizes[i] = buffer.getInt(); if (offsets[i] != nextExpectedOffset) { logger.error("expected offset {}, got {}", nextExpectedOffset, offsets[i]); throw new IllegalArgumentException("corrupted index table"); } nextExpectedOffset += sizes[i]; } // Set up the integer store if (buffer.remaining() < nextExpectedOffset * 4) { throw new IllegalArgumentException("buffer not large enough"); } int end = buffer.position() + nextExpectedOffset * 4; ByteBuffer dup = buffer.duplicate(); dup.limit(end); // update input indexStore's position buffer.position(end); // create index table object LongKeyDomain dom = LongKeyDomain.wrap(keys, keys.length, true); return new BinaryIndexTable(dom, offsets, sizes, dup.asIntBuffer()); }
From source file:com.palantir.atlasdb.keyvalue.cassandra.CassandraKeyValueServices.java
static Pair<byte[], Long> decompose(ByteBuffer composite) { composite = composite.slice().order(ByteOrder.BIG_ENDIAN); short len = composite.getShort(); byte[] colName = new byte[len]; composite.get(colName);// ww w. jav a 2 s . c o m short shouldBeZero = composite.getShort(); Validate.isTrue(shouldBeZero == 0); byte shouldBe8 = composite.get(); Validate.isTrue(shouldBe8 == 8); long ts = composite.getLong(); return Pair.create(colName, (~ts)); }
From source file:org.cloudata.core.commitlog.pipe.CommitLogFileChannel.java
public static long readLastIndex(FileChannel ch) throws IOException { ByteBuffer buf = ByteBuffer.allocate(Long.SIZE / 8); long chSize = ch.size(); if (chSize > 0) { ch.position(chSize > (Long.SIZE / 8) ? chSize - (Long.SIZE / 8) : 0); ch.read(buf);//from ww w .ja va2s. com buf.flip(); return buf.getLong(); } else { return 0; } }
From source file:com.easemob.dataexport.utils.ConversionUtils.java
/** * @param uuid/* ww w . j a va2 s .c o m*/ * @param offset * @return */ public static UUID uuid(byte[] uuid, int offset) { ByteBuffer bb = ByteBuffer.wrap(uuid, offset, 16); return new UUID(bb.getLong(), bb.getLong()); }
From source file:com.easemob.dataexport.utils.ConversionUtils.java
public static UUID uuid(ByteBuffer bb) { if (bb == null) { return null; }//from w w w .ja v a2 s. c o m if (bb.remaining() < 16) { return null; } bb = bb.slice(); return new UUID(bb.getLong(), bb.getLong()); }