Java Utililty Methods ByteBuffer to Float

List of utility methods to do ByteBuffer to Float

Description

The list of methods to do ByteBuffer to Float are organized into topic(s).

Method

floatreadFloat(ByteBuffer buffer)
read Float
return Float.intBitsToFloat(readInt(buffer));
float[]readFloatArray(ByteBuffer bb, int length)
read Float Array
float[] a = new float[length];
for (int i = 0; i < length; i++) {
    a[i] = bb.getFloat();
return a;
float[]readFloats(final ByteBuffer bb, final int length)
read Floats
final float[] result = new float[length];
for (int index = 0; index < length; index++) {
    result[index] = bb.getFloat();
return result;
inttoFloat(AudioFormat format, ByteBuffer buf, float[] floatBuf)
to Float
if (format.isBigEndian()) {
    if (format.getSampleSizeInBits() == 16) {
        return toFloat16BE(buf, floatBuf);
    } else {
        return toFloat24BE(buf, floatBuf);
} else {
    if (format.getSampleSizeInBits() == 16) {
...
floattoFloat(ByteBuffer buffer)
to Float
return toByteBuffer(buffer, Float.BYTES).getFloat();
floattoFloat(ByteBuffer bytes)
to Float
return bytes.getFloat(bytes.position());
floattoFloat(ByteBuffer value)
to Float
float result = 0f;
try {
    if (value != null) {
        int originPos = value.position();
        result = value.getFloat();
        value.position(originPos);
} catch (Exception ex) {
...
voidtoFloat16BE(ByteBuffer buf, FloatBuffer out)
to Float BE
while (buf.remaining() >= 2 && out.hasRemaining()) {
    out.put(r16 * (short) (((buf.get() & 0xff) << 8) | (buf.get() & 0xff)));
inttoFloat24BE(ByteBuffer buf, float[] out)
to Float BE
int samples = 0;
while (buf.remaining() >= 3 && samples < out.length) {
    out[samples++] = r24
            * ((((buf.get() & 0xff) << 24) | ((buf.get() & 0xff) << 16) | ((buf.get() & 0xff) << 8)) >> 8);
return samples;