List of usage examples for com.google.common.primitives Longs fromByteArray
public static long fromByteArray(byte[] bytes)
From source file:co.paralleluniverse.galaxy.berkeleydb.BerkeleyDB.java
@Override public void removeOwner(short node) { final boolean trace = LOG.isTraceEnabled(); final Transaction txn = null; // final Transaction txn = env.beginTransaction(null, TransactionConfig.DEFAULT); // try { final LongArrayList lines = new LongArrayList(); final DatabaseEntry sKey = new DatabaseEntry(Shorts.toByteArray(node)); final DatabaseEntry pKey = new DatabaseEntry(); final DatabaseEntry data = new DatabaseEntry(); try (SecondaryCursor cursor = ownerIndex.openCursor(txn, null)) { OperationStatus retVal = cursor.getSearchKey(sKey, pKey, data, LockMode.DEFAULT); while (retVal == OperationStatus.SUCCESS) { final long id = Longs.fromByteArray(pKey.getData()); if (trace) LOG.trace("Owner of {}: {} -> 0", id, node); lines.add(id); // cursor.getPrimaryDatabase().put(null, pKey, SERVER); - causes deadlock retVal = cursor.getNextDup(sKey, pKey, data, LockMode.DEFAULT); }/*from w w w.ja va 2 s . c om*/ } byte[] longArray = new byte[8]; for (LongIterator it = lines.iterator(); it.hasNext();) { toByteArray(it.next(), longArray); pKey.setData(longArray); ownerDirectory.put(null, pKey, SERVER); } // txn.commit(); // } catch (Exception e) { // LOG.error("Exception while removing. Aborting.", e); // txn.abort(); // throw Throwables.propagate(e); // } }
From source file:io.opencensus.exporter.trace.jaeger.JaegerExporterHandler.java
private long spanIdToLong(final @Nullable SpanId spanId) { if (spanId == null) { return 0L; }/*from w w w . j a v a 2 s . co m*/ // Attempt to minimise allocations, since SpanId#getBytes currently creates a defensive copy: spanId.copyBytesTo(spanIdBuffer, 0); return Longs.fromByteArray(spanIdBuffer); }
From source file:se.sics.datamodel.util.DMKeyFactory.java
private static Long deserializeLexicoLong(DataInputStream r) throws IOException { byte b_sign = r.readByte(); byte[] b_long = new byte[8]; r.read(b_long); Long val = Longs.fromByteArray(b_long); if (b_sign == (byte) 0) { //negative val = val * (-1); }//from w w w. j a v a2 s. c om return val; }
From source file:com.liaison.javabasics.serialization.BytesUtil.java
/** * TODO//w ww .ja v a 2s . c om * @param bytes TODO * @return TODO */ public static Instant toInstant(final byte[] bytes) { // TODO: determine constant values programmatically, or make them constant if (bytes != null && bytes.length >= 8 + 4) { long millisecs = Longs.fromByteArray(bytes); int nano = Ints.fromBytes(bytes[8], bytes[9], bytes[10], bytes[11]); return Instant.ofEpochSecond(millisecs, nano); } return null; }
From source file:co.paralleluniverse.galaxy.berkeleydb.BerkeleyDB.java
public void resetOwners() { final boolean trace = LOG.isTraceEnabled(); final DatabaseEntry key = new DatabaseEntry(); final DatabaseEntry data = new DatabaseEntry(); try (DiskOrderedCursor cursor = ownerDirectory .openCursor(new DiskOrderedCursorConfig().setKeysOnly(true))) { OperationStatus retVal = cursor.getNext(key, data, null); while (retVal == OperationStatus.SUCCESS) { if (trace) LOG.trace("Owner of {} -> 0", Longs.fromByteArray(key.getData())); ownerDirectory.put(null, key, SERVER); retVal = cursor.getNext(key, data, null); }//from w ww . j av a 2 s . com } }
From source file:org.opendedup.collections.LongByteArrayMap.java
@Override public SparseDataChunk nextValue(boolean index) throws IOException, FileClosedException { ReadLock l = this.hashlock.readLock(); l.lock();//from www . j av a 2 s. c o m try { if (this.isClosed()) { throw new FileClosedException("hashtable [" + this.filePath + "] is close"); } long _cpos = getInternalIterFPos(); while (_cpos < pbdb.size()) { try { if (nbuf == null) { nbuf = ByteBuffer.allocate(arrayLength); } nbuf.position(0); pbdb.read(nbuf, _cpos); // SDFSLogger.getLog().info("al=" + al + " cpos=" +_cpos // + " flen=" + flen + " fz=" +pbdb.size() + " nbfs=" + // nbuf.position()); nbuf.position(0); // SDFSLogger.getLog().info("arl=" + arrayLength + " // nbufsz=" + nbuf.capacity() + " rem="+ nbuf.remaining()); byte[] val = new byte[arrayLength]; nbuf.get(val); if (!Arrays.equals(val, FREE)) { SparseDataChunk ck = new SparseDataChunk(val, this.version); if (index) { for (HashLocPair p : ck.getFingers()) { DedupFileStore.addRef(p.hash, Longs.fromByteArray(p.hashloc)); } } return ck; } } finally { iterPos.incrementAndGet(); _cpos = (iterPos.get() * arrayLength) + this.offset; } } return null; } finally { l.unlock(); } }
From source file:org.opendedup.collections.LongByteArrayMap.java
public LongKeyValue nextKeyValue(boolean index) throws IOException, FileClosedException { ReadLock l = this.hashlock.readLock(); l.lock();//w ww. j a va 2 s . c o m try { if (this.isClosed()) { throw new FileClosedException("hashtable [" + this.filePath + "] is close"); } long _cpos = getInternalIterFPos(); while (_cpos < pbdb.size()) { try { ByteBuffer buf = ByteBuffer.wrap(new byte[arrayLength]); pbdb.read(buf, _cpos); byte[] val = buf.array(); if (!Arrays.equals(val, FREE)) { SparseDataChunk ck = new SparseDataChunk(val, this.version); if (index) { for (HashLocPair p : ck.getFingers()) { DedupFileStore.addRef(p.hash, Longs.fromByteArray(p.hashloc)); } } return new LongKeyValue(iterPos.get() * Main.CHUNK_LENGTH, ck); } } finally { iterPos.incrementAndGet(); _cpos = (iterPos.get() * arrayLength) + this.offset; } } return null; } finally { l.unlock(); } }
From source file:org.apache.apex.malhar.lib.wal.FSWindowDataManager.java
private long findLargestCompletedWindow(FSWindowReplayWAL wal, Long ceilingWindow) throws IOException { if (!wal.fileDescriptors.isEmpty()) { FileSystemWAL.FileSystemWALReader reader = wal.getReader(); //to find the largest window, we only need to look at the last file. NavigableSet<Integer> descendingParts = new TreeSet<>(wal.fileDescriptors.keySet()).descendingSet(); for (int part : descendingParts) { FSWindowReplayWAL.FileDescriptor last = wal.fileDescriptors.get(part).last(); reader.seek(new FileSystemWAL.FileSystemWALPointer(last.part, 0)); long endOffset = -1; long lastWindow = Stateless.WINDOW_ID; Slice slice = readNext(reader); while (slice != null) { boolean skipComplete = skipNext(reader); //skip the artifact because we need just the largest window id. if (!skipComplete) { //artifact not saved so this window was not finished. break; }//w w w . java 2s . c om long offset = reader.getCurrentPointer().getOffset(); long window = Longs.fromByteArray(slice.toByteArray()); if (ceilingWindow != null && window > ceilingWindow) { break; } endOffset = offset; lastWindow = window; slice = readNext(reader); //either null or next window } if (endOffset != -1) { wal.walEndPointerAfterRecovery = new FileSystemWAL.FileSystemWALPointer(last.part, endOffset); wal.windowWalParts.put(lastWindow, wal.walEndPointerAfterRecovery.getPartNum()); return lastWindow; } } } return Stateless.WINDOW_ID; }
From source file:org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.match.MatchUtil.java
public static Long ipv4ToLong(Ipv4Address ipv4) { Iterator<String> iterator = SPLITTER.split(ipv4.getValue()).iterator(); byte[] bytes = new byte[8]; for (int i = 0; i < bytes.length; i++) { if (i < 4) { bytes[i] = 0;/*ww w . jav a2 s . c om*/ } else { bytes[i] = UnsignedBytes.parseUnsignedByte((iterator.next())); } } Long result = Longs.fromByteArray(bytes); return result; }
From source file:co.paralleluniverse.galaxy.berkeleydb.BerkeleyDB.java
private long getMaxId(Database db) { final DatabaseEntry key = new DatabaseEntry(); final DatabaseEntry value = new DatabaseEntry(); try (Cursor cursor = db.openCursor(null, CursorConfig.DEFAULT)) { final OperationStatus status = cursor.getLast(key, value, null); if (status == OperationStatus.SUCCESS) return Longs.fromByteArray(key.getData()); else// w w w.j ava2s . c om return 0; } }