Refine search
@Override public void close() { bytes.release(); } }
private void entriesFor0(@NotNull SubscriptionConsumer<MapEvent<String, BytesStore>> kvConsumer) throws InvalidSubscriberException { getFiles().forEach(p -> { @Nullable BytesStore fileContents = null; try { // in case the file has been deleted in the meantime. fileContents = getFileContents(p, null); if (fileContents != null) { @NotNull InsertedEvent e = InsertedEvent.of(asset.fullName(), p.getFileName().toString(), fileContents, false); kvConsumer.accept(e); } } catch (InvalidSubscriberException ise) { throw Jvm.rethrow(ise); } finally { if (fileContents != null) fileContents.release(); } }); }
@Nullable @Override public String getAndPut(String key, @NotNull String value) { Buffers b = BUFFERS.get(); Bytes<ByteBuffer> bytes = b.valueBuffer; bytes.clear(); bytes.appendUtf8(value); @Nullable BytesStore retBytes = kvStore.getAndPut(key, bytes); if (retBytes == null) return null; else { String s = retBytes.toString(); retBytes.release(); return s; } }
public static boolean equalBytesAny(@org.jetbrains.annotations.NotNull @NotNull BytesStore b1, @org.jetbrains.annotations.NotNull @NotNull BytesStore b2, long readRemaining) throws BufferUnderflowException { @org.jetbrains.annotations.Nullable BytesStore bs1 = b1.bytesStore(); @org.jetbrains.annotations.Nullable BytesStore bs2 = b2.bytesStore(); long i = 0; for (; i < readRemaining - 7 && canReadBytesAt(bs1, b1.readPosition() + i, 8) && canReadBytesAt(bs2, b2.readPosition() + i, 8); i += 8) { long l1 = bs1.readLong(b1.readPosition() + i); long l2 = bs2.readLong(b2.readPosition() + i); if (l1 != l2) return false; canReadBytesAt(bs1, b1.readPosition() + i, 4) && canReadBytesAt(bs2, b2.readPosition() + i, 4)) { int i1 = bs1.readInt(b1.readPosition() + i); int i2 = bs2.readInt(b2.readPosition() + i); if (i1 != i2) return false; canReadBytesAt(bs1, b1.readPosition() + i, 1) && canReadBytesAt(bs2, b2.readPosition() + i, 1); i++) { byte i1 = bs1.readByte(b1.readPosition() + i); byte i2 = bs2.readByte(b2.readPosition() + i); if (i1 != i2) return false;
@NotNull WatchEvent<Path> ev = (WatchEvent<Path>) event; Path fileName = ev.context(); String mapKey = fileName.toString(); @Nullable BytesStore mapVal = getFileContentsFromDisk(p, null); @Nullable BytesStore prevContents = prev == null ? null : prev.contents(); try { if (mapVal != null && mapVal.contentEquals(prevContents)) { } else { lastFileRecordMap.put(p.toFile(), new FileRecord<>(p.toFile().lastModified(), mapVal.copy())); prevContents.release(); @Nullable BytesStore lastVal = prev == null ? null : prev.contents(); try { subscriptions.notifyEvent(RemovedEvent.of(asset.fullName(), p.toFile().getName(), lastVal, false)); } finally { if (lastVal != null) lastVal.release();
protected void acceptNewBytesStore(@NotNull final BytesStore bytes) { if (this.bytes != null) { this.bytes.release(); } this.bytes = bytes.bytesStore(); this.bytes.reserve(); }
@NotNull @Override public Bytes<Underlying> writeDouble(long offset, double d) throws BufferOverflowException { writeCheckOffset(offset, 8); bytesStore.writeDouble(offset, d); return this; }
static long applyAsLong1to7(@NotNull BytesStore store, int remaining) { final long address = store.addressForRead(store.readPosition()); return hash(readIncompleteLong(address, remaining)); }
/** * Check if a portion of a BytesStore matches this one. * * @param bytesStore to match against * @param length to match. * @return true if the bytes up to min(length, this.length(), bytesStore.length()) matched. */ default boolean equalBytes(@NotNull BytesStore bytesStore, long length) throws BufferUnderflowException { return length == 8 && bytesStore.length() >= 8 ? readLong(readPosition()) == bytesStore.readLong(bytesStore.readPosition()) : BytesInternal.equalBytesAny(this, bytesStore, length); }
/** * @return a Bytes to wrap this ByteStore from the start() to the realCapacity(). * @throws IllegalStateException if this Bytes has been released. */ @Override @NotNull default Bytes<Underlying> bytesForRead() throws IllegalStateException { try { return bytesForWrite() .readLimit(writeLimit()) .readPosition(start()); } catch (BufferUnderflowException e) { throw new IllegalStateException(e); } }
/** * Fill the BytesStore with zeros * * @param start first byte inclusive * @param end last byte exclusive. * @return this. */ @Override @NotNull default B zeroOut(long start, long end) { if (end <= start) return (B) this; if (start < start()) start = start(); if (end > capacity()) end = capacity(); long i = start; try { for (; i < end - 7; i += 8L) writeLong(i, 0L); for (; i < end; i++) writeByte(i, 0); } catch (BufferOverflowException | IllegalArgumentException e) { throw new AssertionError(e); } return (B) this; }
@NotNull private net.openhft.lang.io.Bytes toLangBytes(@NotNull BytesStore b, @NotNull Bytes tmpBytes, @NotNull net.openhft.lang.io.NativeBytes lb) { if (b.isDirectMemory()) { // check(b); lb.setStartPositionAddress(b.address(b.start()), b.address(b.readLimit())); // check(lb); } else { tmpBytes.clear(); tmpBytes.write(b); lb.setStartPositionAddress(tmpBytes.address(tmpBytes.start()), tmpBytes.address(tmpBytes.readLimit())); } return lb; }
public static void assignBytesStoreToByteBuffer(@org.jetbrains.annotations.NotNull BytesStore bytesStore, @org.jetbrains.annotations.NotNull ByteBuffer byteBuffer) throws BufferUnderflowException { long address = bytesStore.addressForRead(bytesStore.readPosition()); long capacity = bytesStore.readRemaining(); ByteBuffers.setAddressCapacity(byteBuffer, address, capacity); byteBuffer.clear(); }