List of usage examples for java.lang Long BYTES
int BYTES
To view the source code for java.lang Long BYTES.
Click Source Link
From source file:com.olacabs.fabric.compute.sources.kafka.impl.TransactionManager.java
public void initialize() throws Exception { try {// www . j a v a2 s .c o m if (null == curator.checkExists().forPath(txnIdPath())) { curator.create().creatingParentContainersIfNeeded().forPath(txnIdPath(), ByteBuffer.allocate(Long.BYTES).putLong(0L).array()); lastTransactionId = 0L; } } catch (KeeperException.NodeExistsException e) { LOGGER.info("Txn ID path exists: " + path()); } try { curator.create().creatingParentContainersIfNeeded().forPath(path()); } catch (KeeperException.NodeExistsException e) { LOGGER.info("Txn path exists: " + path()); } }
From source file:org.asynchttpclient.ntlm.NtlmTest.java
private static byte[] longToBytes(long x) { ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES); buffer.putLong(x);//from w w w . j a v a 2s .c om return buffer.array(); }
From source file:de.micromata.genome.logging.spi.ifiles.IndexDirectory.java
public int createNewLogIdxFile(File logFile) throws IOException { int pos = getWritePos(); int retpos = pos; String lwwrite = fileToStoredName(logFile); indexByteBuffer.putLong(pos, 0);/*from w w w. j a va 2 s. co m*/ pos += Long.BYTES; indexByteBuffer.putLong(pos, 0); pos += Long.BYTES; NIOUtils.write(indexByteBuffer, pos, lwwrite); pos += lwwrite.length(); setNewWritePos(pos); return retpos; }
From source file:com.olacabs.fabric.compute.sources.kafka.impl.TransactionManager.java
private void saveLastTransactionId(long transactionId) throws Exception { curator.setData().forPath(txnIdPath(), ByteBuffer.allocate(Long.BYTES).putLong(transactionId).array()); }
From source file:com.olacabs.fabric.compute.sources.kafka.impl.TransactionManager.java
private long readLastTransactionId() throws Exception { byte[] data = curator.getData().forPath(txnIdPath()); ByteBuffer read = ByteBuffer.allocate(Long.BYTES).put(data, 0, data.length); read.flip();/*w w w. j av a2 s. c o m*/ return read.getLong(); }
From source file:de.micromata.genome.logging.spi.ifiles.IndexHeader.java
private void parse(MappedByteBuffer mem, long fileSize) { fileType = new byte[INDEX_FILE_TYPE.length]; fileVersion = new byte[INDEX_FILE_VERSION.length]; // mem.position(0); int pos = 0;/*from ww w .j a v a 2 s .c om*/ NIOUtils.getBytes(mem, pos, fileType); pos += fileType.length; NIOUtils.getBytes(mem, pos, fileVersion); pos += fileVersion.length; created = mem.getLong(pos); pos += Long.BYTES; indexDirectoryIdx = mem.getInt(pos); pos += Integer.BYTES; startIndex = mem.getInt(pos); pos += Integer.BYTES; int max = startIndex - (Integer.BYTES + HEADER_NAME_LENGTH); int offset = 0; while (pos < max) { String headerName = NIOUtils.readAsciiString(mem, pos, HEADER_NAME_LENGTH); pos += HEADER_NAME_LENGTH; int fieldLength = mem.getInt(pos); pos += Integer.BYTES; headerName = StringUtils.trim(headerName); headerOrder.add(Pair.make(headerName, fieldLength)); searchFieldsLength.put(headerName, fieldLength); searchFieldsOffsets.put(headerName, offset); offset += fieldLength + 1; } }
From source file:com.act.lcms.v2.fullindex.BuilderTest.java
@Test public void testExtractTriples() throws Exception { // Verify all TMzI triples are stored correctly. Map<Long, TMzI> deserializedTriples = new HashMap<>(); assertEquals("All triples should have entries in the DB", 9, fakeDB.getFakeDB().get(ColumnFamilies.ID_TO_TRIPLE).size()); for (Map.Entry<List<Byte>, byte[]> entry : fakeDB.getFakeDB().get(ColumnFamilies.ID_TO_TRIPLE).entrySet()) { Long id = ByteBuffer.wrap(fakeDB.byteListToArray(entry.getKey())).getLong(); TMzI triple = TMzI.readNextFromByteBuffer(ByteBuffer.wrap(entry.getValue())); Float expectedTime = Double.valueOf(TIMES[id.intValue() / 3]).floatValue(); Double expectedMZ = MZS[id.intValue() / 3][id.intValue() % 3]; Float expectedIntensity = Double.valueOf(INTENSITIES[id.intValue() / 3][id.intValue() % 3]) .floatValue();/* w ww . ja v a 2 s . c o m*/ assertEquals("Time matches expected", expectedTime, triple.getTime(), FP_TOLERANCE); // No error expected assertEquals("M/z matches expected", expectedMZ, triple.getMz(), FP_TOLERANCE); assertEquals("Intensity matches expected", expectedIntensity, triple.getIntensity(), FP_TOLERANCE); deserializedTriples.put(id, triple); } for (Map.Entry<List<Byte>, byte[]> entry : fakeDB.getFakeDB().get(ColumnFamilies.WINDOW_ID_TO_TRIPLES) .entrySet()) { int windowId = ByteBuffer.wrap(fakeDB.byteListToArray(entry.getKey())).getInt(); MZWindow window = windowIdsToWindows.get(windowId); List<Long> tmziIds = new ArrayList<>(entry.getValue().length / Long.BYTES); ByteBuffer valBuffer = ByteBuffer.wrap(entry.getValue()); while (valBuffer.hasRemaining()) { tmziIds.add(valBuffer.getLong()); } for (Long tripleId : tmziIds) { TMzI triple = deserializedTriples.get(tripleId); assertTrue("Triple m/z falls within range of containing window", triple.getMz() >= window.getMin() && triple.getMz() <= window.getMax()); } } for (Map.Entry<List<Byte>, byte[]> entry : fakeDB.getFakeDB().get(ColumnFamilies.TIMEPOINT_TO_TRIPLES) .entrySet()) { float time = ByteBuffer.wrap(fakeDB.byteListToArray(entry.getKey())).getFloat(); List<Long> tmziIds = new ArrayList<>(entry.getValue().length / Long.BYTES); ByteBuffer valBuffer = ByteBuffer.wrap(entry.getValue()); while (valBuffer.hasRemaining()) { tmziIds.add(valBuffer.getLong()); } for (Long tripleId : tmziIds) { TMzI triple = deserializedTriples.get(tripleId); assertEquals("Triple time matches key time", time, triple.getTime(), FP_TOLERANCE); } } }
From source file:ie.peternagy.jcrypto.algo.EllipticCurveWrapper.java
/** * Extract header parameters from data/*from w w w. ja v a2s .co m*/ * @param data - content with header signature * @return */ public byte[] extractRawHeader(byte[] data) { int version = data[0]; int currentPosition = 1; int keyIdSize = ByteBuffer.wrap(ArrayUtils.subarray(data, currentPosition, currentPosition + Integer.BYTES)) .getInt(); currentPosition += Integer.BYTES; long crcSum = ByteBuffer.wrap(ArrayUtils.subarray(data, currentPosition, currentPosition + Long.BYTES)) .getLong(); currentPosition += Long.BYTES; byte[] keyId = ArrayUtils.subarray(data, currentPosition, currentPosition + keyIdSize); currentPosition += keyIdSize; byte[] content = ArrayUtils.subarray(data, currentPosition, data.length); if (version != 100 || !Arrays.equals(keyId, getKeyId()) || CryptoSignatureUtil.calculateCrc32(content) != crcSum) { String reason = version != 100 ? "Invalid version " : !Arrays.equals(keyId, getKeyId()) ? " Invalid key id" : " Invalid data checksum"; throw new RuntimeException("EC headers do not match - decrypt " + reason); } return content; }
From source file:org.apache.druid.query.aggregation.HistogramAggregatorFactory.java
@Override public int getMaxIntermediateSize() { return Long.BYTES * (breaks.length + 1) + Float.BYTES * 2; }
From source file:de.micromata.genome.logging.spi.ifiles.IndexDirectory.java
public void updateDate(int indexDirectoryIdx, long timestamp) { long start = indexByteBuffer.getLong(indexDirectoryIdx); long end = indexByteBuffer.getLong(indexDirectoryIdx + Long.BYTES); if (start == 0 || start > timestamp) { indexByteBuffer.putLong(indexDirectoryIdx, timestamp); }// ww w .j a va 2 s. c o m if (end < timestamp) { indexByteBuffer.putLong(indexDirectoryIdx + Long.BYTES, timestamp); } }