in src/main/java/org/apache/datasketches/memory/internal/WritableBufferImpl.java [117:144]
private WritableBuffer regionImpl(
final long offsetBytes,
final long capacityBytes,
final boolean localReadOnly,
final ByteOrder byteOrder) {
if (!this.isAlive()) { throw new IllegalStateException("This Buffer is not alive."); }
Objects.requireNonNull(byteOrder, "byteOrder must be non-null.");
final boolean readOnly = isReadOnly() || localReadOnly;
final MemorySegment slice = (readOnly && !seg.isReadOnly())
? seg.asSlice(offsetBytes, capacityBytes).asReadOnly()
: seg.asSlice(offsetBytes, capacityBytes);
final boolean duplicateType = isDuplicate();
final boolean mapType = seg.isMapped();
final boolean directType = seg.isNative();
final boolean nativeBOType = byteOrder == ByteOrder.nativeOrder();
final boolean byteBufferType = hasByteBuffer();
final int type = BUFFER | REGION
| (readOnly ? READONLY : 0)
| (duplicateType ? DUPLICATE : 0)
| (mapType ? MAP : 0)
| (directType ? DIRECT : 0)
| (nativeBOType ? NATIVE_BO : NONNATIVE_BO)
| (byteBufferType ? BYTEBUF : 0);
final WritableBuffer wbuf = selectBuffer(slice, type, memReqSvr, byteBufferType, mapType, nativeBOType);
wbuf.setStartPositionEnd(0, 0, wbuf.getCapacity());
return wbuf;
}