Java Utililty Methods FloatBuffer to Array

List of utility methods to do FloatBuffer to Array

Description

The list of methods to do FloatBuffer to Array are organized into topic(s).

Method

float[]convertFloatBufferToArray(java.nio.FloatBuffer buf)
convert Float Buffer To Array
if (buf.hasArray()) {
    return buf.array();
} else {
    buf.rewind();
    float[] array = new float[buf.remaining()];
    int index = 0;
    while (buf.hasRemaining()) {
        array[index++] = buf.get();
...
FloatBufferfloatArrayToFloatBuffer(float[] data)
Converts an array of primitive floats to a java.nio.FloatBuffer .
FloatBuffer ret = ByteBuffer.allocateDirect(data.length << 2).order(ByteOrder.nativeOrder())
        .asFloatBuffer();
ret.put(data).flip();
return ret;
voidfloatBufferToHistogram(FloatBuffer ib, int width, int height, int widthStep, float[] histogram)
float Buffer To Histogram
Arrays.fill(histogram, 0);
ib.rewind();
int totalPoints = 0;
for (int y = 0; y < height; y++)
    for (int x = 0; x < width; x++) {
        int v = (int) ib.get(y * widthStep + x);
        if (v > 0 && v < histogram.length) {
            histogram[v]++;
...
StringfloatBufferToString(FloatBuffer buffer)
float Buffer To String
StringBuilder out = new StringBuilder();
for (int i = 0; i < buffer.capacity(); i++) {
    out.append(i).append("=").append(buffer.get(i)).append(" ");
return out.toString();
float[]getFloatArray(final FloatBuffer buff)
get Float Array
if (buff == null) {
    return null;
buff.clear();
final float[] inds = new float[buff.limit()];
for (int x = 0; x < inds.length; x++) {
    inds[x] = buff.get();
return inds;
float[]getFloatArray(FloatBuffer buff)
Create a new float[] array and populate it with the given FloatBuffer's contents.
if (buff == null) {
    return null;
buff.clear();
float[] inds = new float[buff.limit()];
for (int x = 0; x < inds.length; x++) {
    inds[x] = buff.get();
return inds;