Add createShortBuffer() to TestUtil

PiperOrigin-RevId: 730875642
(cherry picked from commit 1399e772490b3ee602b298d58f5683ae0a00f688)
This commit is contained in:
ivanbuper 2025-02-25 07:18:38 -08:00 committed by tonihei
parent 24b3bf21b8
commit f2739302af

View File

@ -78,6 +78,7 @@ import java.lang.reflect.Modifier;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.nio.ShortBuffer;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
@ -175,6 +176,14 @@ public class TestUtil {
return content;
}
/** Gets the underlying data of the {@link ByteBuffer} as a {@code short[]}. */
public static short[] createShortArray(ByteBuffer byteBuffer) {
ShortBuffer buffer = byteBuffer.asShortBuffer();
short[] content = new short[buffer.remaining()];
buffer.get(content);
return content;
}
/** Creates a {@link ByteBuffer} containing the {@code data}. */
public static ByteBuffer createByteBuffer(float[] data) {
ByteBuffer buffer =