@Override public RandomDataInput bytes() { return bytes.bytesStore(); }
@Override public RandomDataInput bytes() { return bytes.bytesStore(); }
@Override public RandomDataInput bytes() { return bytes.bytesStore(); }
/** * @return the size which can be safely read. If this isElastic() it can be lower than the * point it can safely write. */ @Override default long safeLimit() { return bytesStore().safeLimit(); }
@Override public RandomDataInput bytes() { initBytes(); return bytes.bytesStore(); }
@Override default boolean readWrite() { return bytesStore().readWrite(); }
@Override default boolean sharedMemory() { return bytesStore().sharedMemory(); }
@NotNull @Override public final T read(@NotNull Bytes in, long size, @Nullable T using) { if (using == null) using = createInstance(); using.bytesStore(in.bytesStore(), in.readPosition(), size); return using; } }
@Override public RandomDataInput bytes() { if (!bytesInit) { bytes.clear(); sizedWriter.write(bytes, size, instance); bytesInit = true; } return bytes.bytesStore(); }
@Override public void ensureCapacity(long size) throws IllegalArgumentException { if (size > realCapacity()) { underlyingBytes.ensureCapacity(size); bytesStore = (NativeBytesStore<Underlying>) underlyingBytes.bytesStore(); } }
@Override public void ensureCapacity(long size) throws IllegalArgumentException { if (size > realCapacity()) { underlyingBytes.ensureCapacity(size); bytesStore = underlyingBytes.bytesStore(); } }
public static void parseUtf8( @NotNull RandomDataInput input, long offset, Appendable appendable, int utflen) throws UTFDataFormatRuntimeException, BufferUnderflowException { if (appendable instanceof StringBuilder) { if (input instanceof NativeBytesStore) { parseUtf8_SB1((NativeBytesStore) input, offset, (StringBuilder) appendable, utflen); return; } else if (input instanceof Bytes && ((Bytes) input).bytesStore() instanceof NativeBytesStore) { @org.jetbrains.annotations.Nullable NativeBytesStore bs = (NativeBytesStore) ((Bytes) input).bytesStore(); parseUtf8_SB1(bs, offset, (StringBuilder) appendable, utflen); return; } } parseUtf81(input, offset, appendable, utflen); }
public UncheckedBytes(@NotNull Bytes underlyingBytes) throws IllegalStateException { super(underlyingBytes.bytesStore(), underlyingBytes.writePosition(), underlyingBytes.writeLimit()); this.underlyingBytes = underlyingBytes; readPosition(underlyingBytes.readPosition()); }
@NotNull @Override public T read(Bytes in, @Nullable T using) { if (using != null && using.getClass() == nativeClass) { ((Byteable) using).bytesStore(in.bytesStore(), in.readPosition(), nativeReference.maxSize()); return using; } if (using == null) using = createInstance(); nativeReference.bytesStore(in.bytesStore(), in.readPosition(), nativeReference.maxSize()); ((Copyable) using).copyFrom(nativeReference); return using; }
public static void parse8bit(@NotNull StreamingDataInput bytes, Appendable appendable, int utflen) throws BufferUnderflowException, IOException { if (appendable instanceof StringBuilder) { @org.jetbrains.annotations.NotNull final StringBuilder sb = (StringBuilder) appendable; if (bytes instanceof Bytes && ((Bytes) bytes).bytesStore() instanceof NativeBytesStore) { parse8bit_SB1((Bytes) bytes, sb, utflen); } else { BytesInternal.parse8bit1(bytes, sb, utflen); } } else { BytesInternal.parse8bit1(bytes, appendable, utflen); } }
public static void parse8bit_SB1(@org.jetbrains.annotations.NotNull @NotNull Bytes bytes, @org.jetbrains.annotations.NotNull @NotNull StringBuilder sb, int utflen) throws BufferUnderflowException { if (utflen > bytes.readRemaining()) throw new BufferUnderflowException(); @Nullable NativeBytesStore nbs = (NativeBytesStore) bytes.bytesStore(); long offset = bytes.readPosition(); int count = BytesInternal.parse8bit_SB1(offset, nbs, sb, utflen); bytes.readSkip(count); }
public UncheckedNativeBytes(@NotNull Bytes<Underlying> underlyingBytes) throws IllegalStateException { this.underlyingBytes = underlyingBytes; this.bytesStore = (NativeBytesStore<Underlying>) underlyingBytes.bytesStore(); assert bytesStore.start() == 0; writePosition = underlyingBytes.writePosition(); writeLimit = underlyingBytes.writeLimit(); readPosition = underlyingBytes.readPosition(); capacity = bytesStore.capacity(); }
/** * Return a Bytes which is optionally unchecked. This allows bounds checks to be turned off. * Note: this means that the result is no longer elastic, even if <code>this</code> is elastic. * * @param unchecked if true, minimal bounds checks will be performed. * @return Bytes without bounds checking. * @throws IllegalStateException if the underlying BytesStore has been released */ @NotNull default Bytes<Underlying> unchecked(boolean unchecked) throws IllegalStateException { if (unchecked) { if (isElastic()) Jvm.debug().on(getClass(), "Wrapping elastic bytes with unchecked() will require calling ensureCapacity() as needed!"); return start() == 0 && bytesStore().isDirectMemory() ? new UncheckedNativeBytes<>(this) : new UncheckedBytes<>(this); } return this; }
public void setBytes(@NotNull Bytes bytes) throws IllegalStateException { BytesStore underlyingBytes = bytes.bytesStore(); if (bytesStore != underlyingBytes) { bytesStore.release(); this.bytesStore = underlyingBytes; bytesStore.reserve(); } readPosition(bytes.readPosition()); this.uncheckedWritePosition(bytes.writePosition()); this.writeLimit = bytes.writeLimit(); assert !bytesStore.isDirectMemory() || BytesUtil.register(this); this.underlyingBytes = bytes; }
@Override public void readMarshallable(BytesIn bytes) throws IORuntimeException { long position = bytes.readPosition(); long capacity = bytes.readLong(); long used = bytes.readLong(); if (capacity < 0 || capacity > bytes.readRemaining() >> 3) throw new IORuntimeException("Corrupt used capacity"); if (used < 0 || used > capacity) throw new IORuntimeException("Corrupt used value"); bytes.readSkip(capacity * 8); long length = bytes.readPosition() - position; bytesStore(((Bytes) bytes).bytesStore(), position, length); }