Summary
-------
The `compact()`, `duplicate()`, and `slice()` methods of `java.nio.MappedByteBuffer` are changed to covariant overrides returning a `MappedByteBuffer` instead of a `ByteBuffer`.
Problem
-------
The `compact()`, `duplicate()`, and `slice()` methods of `MappedByteBuffer` return a `ByteBuffer` thereby precluding the ability to use these methods in chain invocations except as the terminal invocation.
Solution
--------
Provide covariant overrides for the `MappedByteBuffer` methods `compact()`, `duplicate()`, and `slice()`.
Specification
-------------
--- a/src/java.base/share/classes/java/nio/MappedByteBuffer.java
+++ b/src/java.base/share/classes/java/nio/MappedByteBuffer.java
@@ -205,7 +215,10 @@ public abstract class MappedByteBuffer
/**
* Forces any changes made to this buffer's content to be written to the
- * storage device containing the mapped file.
+ * storage device containing the mapped file. The region starts at index
+ * zero in this buffer and is {@code capacity()} bytes. An invocation of
+ * this method behaves in exactly the same way as the invocation
+ * {@link force(int,int) force(0,capacity())}.
*
* <p> If the file mapped into this buffer resides on a local storage
* device then when this method returns it is guaranteed that all changes
@@ -362,4 +375,41 @@ public abstract class MappedByteBuffer
super.rewind();
return this;
}
+
+ /**
+ * {@inheritDoc}
+ *
+ * <p> Reading bytes into physical memory by invoking {@code load()} on the
+ * returned buffer, or writing bytes to the storage device by invoking
+ * {@code force()} on the returned buffer, will only act on the sub-range
+ * of this buffer that the returned buffer represents, namely
+ * {@code [position(),limit())}.
+ */
+ @Override
+ public abstract MappedByteBuffer slice();
+
+ /**
+ * {@inheritDoc}
+ *
+ * <p> Reading bytes into physical memory by invoking {@code load()} on the
+ * returned buffer, or writing bytes to the storage device by invoking
+ * {@code force()} on the returned buffer, will only act on the sub-range
+ * of this buffer that the returned buffer represents, namely
+ * {@code [index,index+length)}, where {@code index} and {@code length} are
+ * assumed to satisfy the preconditions.
+ */
+ @Override
+ public abstract MappedByteBuffer slice(int index, int length);
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public abstract MappedByteBuffer duplicate();
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public abstract MappedByteBuffer compact();
}