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:edu.umass.cs.gigapaxos.paxospackets.RequestPacket.java
static int sizeof(Class<?> clazz) { switch (clazz.getSimpleName()) { case "int": return Integer.BYTES; case "long": return Long.BYTES; case "boolean": return 1; case "short": return Short.BYTES; case "InetSocketAddress": return Integer.BYTES + Short.BYTES; }// ww w. j a v a2 s. co m assert (false) : clazz; return -1; }
From source file:de.micromata.genome.logging.spi.ifiles.IndexDirectory.java
public String findLogFileNameByLogId(long logId) { int indexdir = (int) (logId >>> 32); int offset = indexdir + 2 * Long.BYTES; byte[] nameBuffer = new byte[LOG_FILE_NAME_SIZE]; indexByteBuffer.position(offset);/*from w ww . j av a 2 s . co m*/ indexByteBuffer.get(nameBuffer); String trimmed = new String(nameBuffer).trim(); return trimmed; }
From source file:de.micromata.genome.logging.spi.ifiles.IndexHeader.java
public void writLogEntryPosition(LogWriteEntry lwe, int position, OutputStream idxOut) throws IOException { ByteBuffer ibb = ByteBuffer.wrap(new byte[Integer.BYTES]); ByteBuffer lbb = ByteBuffer.wrap(new byte[Long.BYTES]); lbb.putLong(lwe.getTimestamp());//w ww. j av a 2 s .c o m idxOut.write(lbb.array()); ibb.putInt(position); idxOut.write(ibb.array()); idxOut.flush(); }
From source file:io.pravega.controller.store.stream.ZKStream.java
@Override CompletableFuture<Void> storeCreationTimeIfAbsent(final long creationTime) { byte[] b = new byte[Long.BYTES]; BitConverter.writeLong(b, 0, creationTime); return store.createZNodeIfNotExist(creationPath, b).thenApply(x -> cache.invalidateCache(creationPath)); }
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 w w.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:com.github.joulupunikki.math.random.BitsStreamGenerator64.java
/** * Will hash the seed with the SHA-512 digest. Enough bits are generated to * fill all the state bits of the generator. The digests will be chained so * that each new set of 512 bits receives the digest value of the previous * set as initial digest data. This should provide well mixed and * uncorrelated initial states with all seeds. Secure hashing is however * slower than less involved methods of state initialization. * * @param seed_in the seed/*from w w w . j ava 2 s . co m*/ * @return hashed state array of longs */ public long[] hashSeed(long[] seed_in) { // prepare to hash seed int seed_len = seed_in.length; long[] seed_out = new long[STATE_WORDS]; MessageDigest md = null; try { md = MessageDigest.getInstance("SHA-512"); } catch (Exception e) { //SHA-512 should be available in java 1.5+ throw new RuntimeException(null, e); } int digest_count = (STATE_BITS - 1) / md.getDigestLength() + 1; int digest_bytes = md.getDigestLength() / Byte.SIZE; if (seed_len > digest_count) { seed_len = digest_count; } byte[] hashed_seed = new byte[STATE_WORDS * Long.BYTES]; int s = 0; byte[] r = null; // hash seed for (; s < seed_len; s++) { r = md.digest(PrimitiveConversion.longToByteArray(seed_in[s])); System.arraycopy(r, 0, hashed_seed, s * digest_bytes, digest_bytes); md.update(r); // chain digests } // if out of seed just chain digests for (; s < digest_count; s++) { r = md.digest(); System.arraycopy(r, 0, hashed_seed, s * digest_bytes, digest_bytes); md.update(r); } // convert digest bytes to longs byte[] t = new byte[Long.BYTES]; for (int i = 0; i < STATE_WORDS; i++) { System.arraycopy(hashed_seed, i * Long.BYTES, t, 0, Long.BYTES); seed_out[i] = PrimitiveConversion.byteArrayToLong(t); } return seed_out; }
From source file:org.hobbit.core.rabbit.RabbitMQUtils.java
/** * Creates a byte array representing the given long value. * * @param value/*from w w w. j a va2 s .c om*/ * 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:io.druid.segment.data.V3CompressedVSizeColumnarMultiIntsSerializerTest.java
private void checkV2SerializedSizeAndData(int offsetChunkFactor, int valueChunkFactor) throws Exception { File tmpDirectory = Files.createTempDirectory(StringUtils.format("CompressedVSizeIndexedV3WriterTest_%d_%d", offsetChunkFactor, offsetChunkFactor)).toFile(); FileSmoosher smoosher = new FileSmoosher(tmpDirectory); int maxValue = vals.size() > 0 ? getMaxValue(vals) : 0; try (SegmentWriteOutMedium segmentWriteOutMedium = new OffHeapMemorySegmentWriteOutMedium()) { CompressedColumnarIntsSerializer offsetWriter = new CompressedColumnarIntsSerializer( segmentWriteOutMedium, offsetChunkFactor, byteOrder, compressionStrategy, GenericIndexedWriter.ofCompressedByteBuffers(segmentWriteOutMedium, "offset", compressionStrategy, Long.BYTES * 250000)); GenericIndexedWriter genericIndexed = GenericIndexedWriter.ofCompressedByteBuffers( segmentWriteOutMedium, "value", compressionStrategy, Long.BYTES * 250000); CompressedVSizeColumnarIntsSerializer valueWriter = new CompressedVSizeColumnarIntsSerializer( segmentWriteOutMedium, maxValue, valueChunkFactor, byteOrder, compressionStrategy, genericIndexed);/*from www . j a v a2 s . c om*/ V3CompressedVSizeColumnarMultiIntsSerializer writer = new V3CompressedVSizeColumnarMultiIntsSerializer( offsetWriter, valueWriter); writer.open(); for (int[] val : vals) { writer.addValues(new ArrayBasedIndexedInts(val)); } final SmooshedWriter channel = smoosher.addWithSmooshedWriter("test", writer.getSerializedSize()); writer.writeTo(channel, smoosher); channel.close(); smoosher.close(); SmooshedFileMapper mapper = Smoosh.map(tmpDirectory); V3CompressedVSizeColumnarMultiIntsSupplier supplierFromByteBuffer = V3CompressedVSizeColumnarMultiIntsSupplier .fromByteBuffer(mapper.mapFile("test"), byteOrder); ColumnarMultiInts columnarMultiInts = supplierFromByteBuffer.get(); assertEquals(columnarMultiInts.size(), vals.size()); for (int i = 0; i < vals.size(); ++i) { IndexedInts subVals = columnarMultiInts.get(i); assertEquals(subVals.size(), vals.get(i).length); for (int j = 0, size = subVals.size(); j < size; ++j) { assertEquals(subVals.get(j), vals.get(i)[j]); } } CloseQuietly.close(columnarMultiInts); mapper.close(); } }
From source file:io.warp10.quasar.encoder.QuasarTokenEncoder.java
public String getTokenIdent(String token, byte[] tokenSipHashkey) { long ident = SipHashInline.hash24_palindromic(tokenSipHashkey, token.getBytes()); ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES); buffer.order(ByteOrder.BIG_ENDIAN); buffer.putLong(ident);//from w w w . j a v a2 s . com return Hex.encodeHexString(buffer.array()); }
From source file:org.hobbit.core.rabbit.RabbitMQUtils.java
/** * Reads a long value from the given byte array. * * @param data//www.ja va 2s .c o m * a serialized long value * @param offset * position at which the parsing will start * @param length * number of bytes that should be parsed (should equal * {@link Long#BYTES}) * @return the value read from the array */ public static long readLong(byte[] data, int offset, int length) { if (length < Long.BYTES) { LOGGER.error("Cant read a long value from {} bytes. Returning 0.", length); return 0; } ByteBuffer buffer = ByteBuffer.wrap(data, offset, length); return buffer.getLong(); }