Skip to content

Commit

Permalink
improvement: Add most of missing JDK9+ methods for java.nio buffers (
Browse files Browse the repository at this point in the history
…scala-native#3681)

* Fix accessing mapped byte buffers if offset is not page alligned
* Use template to define base java nio buffer types
* Add JDK13 method Buffer.slice(Int,Int)
* Add absolute bulk offset get/put methods
* Add tests for alignment offsets/slices
* Move ALL java.nio buffer tests to require-jdk16 subdir due to problems with decoupling BufferAdapters for API introduced in JDK9+
* Fix build, move remaining buffer tests to required-jdk16 sources, exclude them in Build def
  • Loading branch information
WojciechMazur committed Jan 25, 2024
1 parent 5f8dee0 commit 3e8e447
Show file tree
Hide file tree
Showing 50 changed files with 2,386 additions and 1,194 deletions.
13 changes: 13 additions & 0 deletions javalib/src/main/scala/java/nio/Buffer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,12 @@ abstract class Buffer private[nio] (val _capacity: Int) {

def isDirect(): Boolean

// Since JDK 9
def slice(): Buffer
// Since JDK 13
def slice(index: Int, length: Int): Buffer

// Since JDK 9
def duplicate(): Buffer

override def toString(): String =
Expand Down Expand Up @@ -124,6 +128,15 @@ abstract class Buffer private[nio] (val _capacity: Int) {
// PointerByteBuffer specific
private[nio] def _rawDataPointer: unsafe.Ptr[Byte] = null

private[nio] def address: unsafe.Ptr[Byte] =
if (_rawDataPointer != null) _rawDataPointer
else if (_mappedData != null) _mappedData.data
else
_array
.asInstanceOf[scalanative.runtime.Array[_]]
.atUnsafe(_offset)
.asInstanceOf[unsafe.Ptr[Byte]]

// HeapByteBuffer specific
private[nio] def _byteArray: Array[Byte] =
throw new UnsupportedOperationException
Expand Down

0 comments on commit 3e8e447

Please sign in to comment.