From 4b3ab93baaf118dea98cfb7b16ffd603faa28475 Mon Sep 17 00:00:00 2001 From: "Ray J. Greenwell" Date: Sun, 10 May 2026 18:33:59 -0700 Subject: [PATCH] Use modern API to read all the bytes rather than buggily hand-rolling it. --- .../com/threerings/openal/util/WaveData.java | 20 +++++-------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/core/src/main/java/com/threerings/openal/util/WaveData.java b/core/src/main/java/com/threerings/openal/util/WaveData.java index 98530887..9a35a3c4 100644 --- a/core/src/main/java/com/threerings/openal/util/WaveData.java +++ b/core/src/main/java/com/threerings/openal/util/WaveData.java @@ -205,28 +205,18 @@ public class WaveData { assert false : "Only mono or stereo is supported"; } - //read data into buffer - ByteBuffer buffer = null; + ByteBuffer buffer; try { - int available = ais.available(); - if(available <= 0) { - available = ais.getFormat().getChannels() * (int) ais.getFrameLength() * ais.getFormat().getSampleSizeInBits() / 8; - } - byte[] buf = new byte[available]; - int read = 0, total = 0; - while ((read = ais.read(buf, total, buf.length - total)) != -1 - && total < buf.length) { - total += read; - } - buffer = convertAudioBytes(buf, audioformat.getSampleSizeInBits() == 16, audioformat.isBigEndian() ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN); + buffer = convertAudioBytes(ais.readAllBytes(), + audioformat.getSampleSizeInBits() == 16, + audioformat.isBigEndian() ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN); } catch (IOException ioe) { return null; } //create our result - WaveData wavedata = - new WaveData(buffer, channels, (int) audioformat.getSampleRate()); + WaveData wavedata = new WaveData(buffer, channels, (int)audioformat.getSampleRate()); //close stream try {