private boolean fillBuffer(AudioStream stream, int bufferId) {
        int totalBytesRead = 0;
        int bytesRead;

        while (totalBytesRead < arrayBuf.length) {
            bytesRead = stream.readSamples(arrayBuf, totalBytesRead, arrayBuf.length - totalBytesRead);

            if (bytesRead > 0) {
                totalBytesRead += bytesRead;
            } else {
                break;
            }
        }

        if (totalBytesRead == 0) {
            return false;
        }

        // Copy data from arrayBuf to nativeBuf
        nativeBuf.clear();
        nativeBuf.put(arrayBuf, 0, totalBytesRead);
        nativeBuf.flip();

        // Upload data to the OpenAL buffer
        int format = getOpenALFormat(stream);
        int sampleRate = stream.getSampleRate();
        al.alBufferData(bufferId, format, nativeBuf, totalBytesRead, sampleRate);

        return true;
    }
Fills a single OpenAL buffer with data from the audio stream.
Uses the shared nativeBuf and arrayBuf.

@param stream   The AudioStream to read from.
@param bufferId The OpenAL buffer ID to fill.
@return True if the buffer was filled with data, false if stream EOF was reached before filling.
jme3-core/src/main/java/com/jme3/audio/openal/ALAudioRenderer.java