Add createShortBuffer() to TestUtil

PiperOrigin-RevId: 730875642
This commit is contained in:
ivanbuper 2025-02-25 07:18:38 -08:00 committed by Copybara-Service
parent cc44de8757
commit 1399e77249

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 =