From 73b81c7842c000efb68b269c9dc97ea012ba9b65 Mon Sep 17 00:00:00 2001 From: Colin Alworth Date: Wed, 15 May 2024 11:49:18 -0500 Subject: [PATCH] Provide a helper method to wrap an ArrayBufferView --- src/main/java/java/nio/ByteBuffer.java | 3 +++ src/main/java/org/gwtproject/nio/TypedArrayHelper.java | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/main/java/java/nio/ByteBuffer.java b/src/main/java/java/nio/ByteBuffer.java index 6dff8854..ce074673 100644 --- a/src/main/java/java/nio/ByteBuffer.java +++ b/src/main/java/java/nio/ByteBuffer.java @@ -66,6 +66,9 @@ public static ByteBuffer allocateDirect (int capacity) { public static ByteBuffer wrapArrayBuffer(ArrayBuffer arrayBuffer) { return new ByteBuffer(arrayBuffer); } + public static ByteBuffer wrapArrayBuffer(ArrayBuffer arrayBuffer, int capacity, int offset) { + return new ByteBuffer(arrayBuffer, capacity, offset); + } public ByteBuffer wrap(ArrayBuffer arrayBuffer) { return new ByteBuffer(arrayBuffer); } diff --git a/src/main/java/org/gwtproject/nio/TypedArrayHelper.java b/src/main/java/org/gwtproject/nio/TypedArrayHelper.java index 8a64d570..b4e13506 100644 --- a/src/main/java/org/gwtproject/nio/TypedArrayHelper.java +++ b/src/main/java/org/gwtproject/nio/TypedArrayHelper.java @@ -28,6 +28,9 @@ public class TypedArrayHelper { public static ByteBuffer wrap(ArrayBuffer ab) { return ByteBuffer.wrapArrayBuffer(ab); } + public static ByteBuffer wrap(ArrayBufferView ab) { + return ByteBuffer.wrapArrayBuffer(ab.buffer, ab.byteLength, ab.byteOffset); + } public static ArrayBufferView unwrap(ByteBuffer bb) { return bb.getTypedArray(); }