in src/main/java/org/apache/datasketches/memory/internal/WritableMemoryImpl.java [300:323]
private WritableBuffer asWritableBufferImpl(final boolean localReadOnly, final ByteOrder byteOrder) {
if (!this.isAlive()) { throw new IllegalStateException("This Memory is not alive."); }
Objects.requireNonNull(byteOrder, "byteOrder must be non-null");
final boolean readOnly = isReadOnly() || localReadOnly;
final MemorySegment seg2 = (readOnly && !seg.isReadOnly()) ? seg.asReadOnly() : seg;
final boolean regionType = isRegion();
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
| (readOnly ? READONLY : 0)
| (regionType ? REGION : 0)
| (duplicateType ? DUPLICATE : 0)
| (directType ? DIRECT : 0)
| (mapType ? MAP : 0)
| (nativeBOType ? NATIVE_BO : NONNATIVE_BO)
| (byteBufferType ? BYTEBUF : 0);
final WritableBuffer wbuf = selectBuffer(seg2, type, memReqSvr, byteBufferType, mapType, nativeBOType);
wbuf.setStartPositionEnd(0, 0, wbuf.getCapacity());
return wbuf;
}