List of usage examples for java.nio ByteBuffer getLong
public abstract long getLong();
From source file:com.act.lcms.v2.fullindex.Searcher.java
private static Set<Long> unionIdBuffers(byte[][] idBytes) { /* TODO: this doesn't take advantage of the fact that all of the ids are in sorted order in every idBytes sub-array. * We should be able to exploit that. For now, we'll just start by hashing the ids. */ Set<Long> uniqueIds = new HashSet<>(); for (int i = 0; i < idBytes.length; i++) { assert (idBytes[i] != null); ByteBuffer idsBuffer = ByteBuffer.wrap(idBytes[i]); while (idsBuffer.hasRemaining()) { uniqueIds.add(idsBuffer.getLong()); }/* www . j a v a 2 s. c om*/ } return uniqueIds; }
From source file:io.warp10.quasar.trl.QuasarTokenRevocationListLoader.java
public static QuasarTokenRevocationListLoader getInstance(Properties config, byte[] appSipHashKey) { if (singleton.compareAndSet(false, true)) { ByteBuffer bb = ByteBuffer.wrap(appSipHashKey); bb.order(ByteOrder.BIG_ENDIAN); appIdSipHashKeyK0 = bb.getLong(); appIdSipHashKeyK1 = bb.getLong(); quasarTokenRevocationListLoader = new QuasarTokenRevocationListLoader(config); }/* w w w. ja v a2 s . c om*/ return quasarTokenRevocationListLoader; }
From source file:org.lic.ip.iplocator.IPv4RadixIntTree.java
private static long inet_aton(String ipStr) { try {/* www . j av a2s . com*/ ByteBuffer bb = ByteBuffer.allocate(8); bb.putInt(0); bb.put(InetAddress.getByName(ipStr).getAddress()); bb.rewind(); return bb.getLong(); } catch (UnknownHostException e) { logger.error(e.getMessage(), e); } return 0; }
From source file:com.twitter.distributedlog.DLSN.java
@VisibleForTesting static DLSN deserialize0(String dlsn) { byte[] data = Base64.decodeBase64(dlsn); ByteBuffer bb = ByteBuffer.wrap(data); byte version = bb.get(); if (VERSION0 != version || VERSION0_LEN != data.length) { throw new IllegalArgumentException("Invalid DLSN " + dlsn); }//from w w w.j a va 2s.c om return new DLSN(bb.getLong(), bb.getLong(), bb.getLong()); }
From source file:org.apache.bookkeeper.stream.SSN.java
/** * Deserialize SSN from the string <i>data</i>. * * @param data ssn string representation * @return ssn instance//from w w w .j a v a 2 s . c om */ public static SSN deserialize(String data) throws InvalidSSNException { byte[] dataBytes = Base64.decodeBase64(data); ByteBuffer bb = ByteBuffer.wrap(dataBytes); byte version = bb.get(); if (CUR_VERSION != version) { throw new InvalidSSNException(data, "Only support version not greater than " + CUR_VERSION + ", but found version " + version); } try { return new SSN(bb.getLong(), bb.getLong(), bb.getLong()); } catch (BufferUnderflowException bufe) { throw new InvalidSSNException(data, bufe); } }
From source file:com.ottogroup.bi.spqr.pipeline.statistics.MicroPipelineStatistics.java
/** * Converts the provided byte array into a {@link MicroPipelineStatistics} representation * @param statsContent//from w w w .ja va 2 s.co m * @return */ public static MicroPipelineStatistics fromByteArray(final byte[] statsContent) { MicroPipelineStatistics stats = new MicroPipelineStatistics(); ByteBuffer buf = ByteBuffer.wrap(statsContent); // ensure that the order is the same as when populating the array stats.setNumOfMessages(buf.getInt()); stats.setStartTime(buf.getLong()); stats.setEndTime(buf.getLong()); stats.setMinDuration(buf.getInt()); stats.setMaxDuration(buf.getInt()); stats.setAvgDuration(buf.getInt()); stats.setMinSize(buf.getInt()); stats.setMaxSize(buf.getInt()); stats.setAvgSize(buf.getInt()); stats.setErrors(buf.getInt()); byte[] procNodeId = new byte[buf.getInt()]; buf.get(procNodeId); byte[] pipelineId = new byte[buf.getInt()]; buf.get(pipelineId); byte[] componentId = new byte[buf.getInt()]; buf.get(componentId); stats.setProcessingNodeId(new String(procNodeId)); stats.setPipelineId(new String(pipelineId)); stats.setComponentId(new String(componentId)); return stats; }
From source file:org.energy_home.jemma.javagal.layers.data.implementations.Utils.DataManipulation.java
/** * Creates a long starting from eight given bytes. A long is composed of * eight bytes. Numbering them from 1 (the most important) to 8 (the least * important), the given bytes will be placed in the place indicated by * their respective names.//from w ww.j a v a2 s . co m * * @param _1 * byte placed in position 1 * @param _2 * byte placed in position 2 * @param _3 * byte placed in position 3 * @param _4 * byte placed in position 4 * @param _5 * byte placed in position 5 * @param _6 * byte placed in position 6 * @param _7 * byte placed in position 7 * @param _8 * byte placed in position 8 * @return the resulting long */ public static long toLong(byte _1, byte _2, byte _3, byte _4, byte _5, byte _6, byte _7, byte _8) { ByteBuffer bb = ByteBuffer.wrap(new byte[] { _1, _2, _3, _4, _5, _6, _7, _8 }); return bb.getLong(); }
From source file:org.grouplens.lenskit.data.dao.packed.BinaryIndexTable.java
/** * Create a binary index table./*www .ja v a 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]; 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]; } if (buffer.remaining() < nextExpectedOffset) { throw new IllegalArgumentException("buffer not large enough"); } int end = buffer.position() + nextExpectedOffset * 4; ByteBuffer dup = buffer.duplicate(); dup.limit(end); buffer.position(end); LongKeyDomain dom = LongKeyDomain.wrap(keys, keys.length, true); return new BinaryIndexTable(dom, offsets, sizes, dup.asIntBuffer()); }
From source file:org.zuinnote.hadoop.bitcoin.format.BitcoinUtil.java
/** * Converts a variable length integer (https://en.bitcoin.it/wiki/Protocol_documentation#Variable_length_integer) to long * * @param varInt byte array containing variable length integer * * @return long corresponding to variable length integer * *//*from ww w . ja v a 2 s . c o m*/ public static long getVarInt(byte[] varInt) { long result = 0; if (varInt.length == 0) return result; int unsignedByte = varInt[0] & 0xFF; if (unsignedByte < 0xFD) return unsignedByte; int intSize = 0; if (unsignedByte == 0xFD) intSize = 3; else if (unsignedByte == 0xFE) intSize = 5; else if (unsignedByte == 0XFF) intSize = 9; byte[] rawDataInt = reverseByteArray(Arrays.copyOfRange(varInt, 1, intSize)); ByteBuffer byteBuffer = ByteBuffer.wrap(rawDataInt); if (intSize == 3) result = byteBuffer.getShort(); else if (intSize == 5) result = byteBuffer.getInt(); else if (intSize == 9) result = byteBuffer.getLong(); // Need to handle sign - available only in JDK8 return result; }
From source file:org.apache.hadoop.hbase.filter.DirectoryRowFilter.java
public static DirectoryRowFilter parseFrom(final byte[] pbBytes) throws DeserializationException { ByteBuffer bb = ByteBuffer.wrap(pbBytes).order(ByteOrder.BIG_ENDIAN); DirectoryRowFilter filter = new DirectoryRowFilter(); filter.instanceModulus = bb.getLong(); filter.instanceRemainder = bb.getLong(); filter.threadModulus = bb.getLong(); filter.threadRemainder = bb.getLong(); return filter; }