@NotNull @Override public BytesStore<Bytes<Underlying>, Underlying> copy() { if (bytesStore.underlyingObject() instanceof ByteBuffer) { ByteBuffer bb = ByteBuffer.allocateDirect(Maths.toInt32(readRemaining())); ByteBuffer bbu = (ByteBuffer) bytesStore.underlyingObject(); ByteBuffer slice = bbu.slice(); slice.position((int) readPosition()); slice.limit((int) readLimit()); bb.put(slice); bb.clear(); return (BytesStore) BytesStore.wrap(bb); } else { return (BytesStore) NativeBytes.copyOf(this); } }
@NotNull @Override public BytesStore<NativeBytesStore<Underlying>, Underlying> copy() throws IllegalStateException { if (underlyingObject == null) { NativeBytesStore<Void> copy = of(realCapacity(), false, true); OS.memory().copyMemory(address, copy.address, capacity()); return (BytesStore) copy; } else if (underlyingObject instanceof ByteBuffer) { ByteBuffer bb = ByteBuffer.allocateDirect(Maths.toInt32(capacity())); bb.put((ByteBuffer) underlyingObject); bb.clear(); return (BytesStore) wrap(bb); } else { throw new UnsupportedOperationException(); } }