Example usage for java.nio FloatBuffer remaining

List of usage examples for java.nio FloatBuffer remaining

Introduction

In this page you can find the example usage for java.nio FloatBuffer remaining.

Prototype

public final int remaining() 

Source Link

Document

Returns the number of remaining elements in this buffer, that is limit - position .

Usage

From source file:Main.java

public static ByteBuffer copyFloatBufferAsByteBuffer(FloatBuffer buf) {
    ByteBuffer dest = newByteBuffer(buf.remaining() * SIZEOF_FLOAT);
    buf.mark();//from  w w  w.ja v  a  2s  .c  o  m
    dest.asFloatBuffer().put(buf);
    buf.reset();
    dest.rewind();
    return dest;
}

From source file:Main.java

public static FloatBuffer ensureLargeEnough(FloatBuffer buf, final int required) {
    if (buf == null || (buf.remaining() < required)) {
        final int position = (buf != null ? buf.position() : 0);
        final FloatBuffer newVerts = createFloatBuffer(position + required);
        if (buf != null) {
            buf.rewind();/* ww w . j  ava2  s.  c  om*/
            newVerts.put(buf);
            newVerts.position(position);
        }
        buf = newVerts;
    }
    return buf;
}

From source file:Main.java

public static FloatBuffer ensureLargeEnough(FloatBuffer buffer, final int required) {
    if (buffer == null || (buffer.remaining() < required)) {
        final int position = (buffer != null ? buffer.position() : 0);
        final FloatBuffer newVerts = createFloatBuffer(position + required);
        if (buffer != null) {
            buffer.rewind();//from  w w w. jav a2  s .c  om
            newVerts.put(buffer);
            newVerts.position(position);
        }
        buffer = newVerts;
    }
    return buffer;
}

From source file:Main.java

private static String formatFloats(byte[] data) {
    FloatBuffer bb = ByteBuffer.wrap(data).order(ByteOrder.LITTLE_ENDIAN).asFloatBuffer();

    StringBuilder sb = new StringBuilder(bb.capacity() * 3);

    while (bb.remaining() > 0) {
        sb.append(String.format("%.4f", bb.get()));
        sb.append(',');
        sb.append('\n');
    }//from   w w  w  . ja v a2  s . co  m

    return sb.toString();
}

From source file:ubic.gemma.core.loader.expression.arrayDesign.AffyChipTypeExtractor.java

private static String parseGenericCCHeader(DataInputStream str) throws IOException {

    /*/*from   w  ww.j av a 2s.  c  o m*/
     * acquisition data, intensity data etc. Usually "intensity data" for the first header.
     */
    String datatypeIdentifier = readString(str);

    AffyChipTypeExtractor.log.debug(datatypeIdentifier);

    String guid = readString(str);

    AffyChipTypeExtractor.log.debug(guid);

    // we just need to read thsee off, even if we aren't using it.
    @SuppressWarnings("unused")
    String createDate = readUnicodeString(str); // blank?
    @SuppressWarnings("unused")
    String locale = readUnicodeString(str); // e.g. en-US
    int numKeyValuePairs = readIntBigEndian(str); // e.g. 55
    String result = null;
    for (int i = 0; i < numKeyValuePairs; i++) {
        String name = readUnicodeString(str);
        byte[] value = readBytes(str);
        String type = readUnicodeString(str);
        Object v;

        switch (type) {
        case "text/x-calvin-float": {
            FloatBuffer intBuf = ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN).asFloatBuffer();
            float[] array = new float[intBuf.remaining()];
            intBuf.get(array);
            break;
        }
        case "text/plain":
        case "text/ascii":
            // text/ascii is undocumented, but needed.
            v = new String(value, "US-ASCII");
            String vv = new String(((String) v).getBytes(), "UTF-16").trim();

            if (name.equals("affymetrix-array-type")) {
                return vv;
            }

            break;
        case "text-x-calvin-unsigned-integer-8": {
            ShortBuffer intBuf = ByteBuffer.wrap(value).asShortBuffer();
            short[] array = new short[intBuf.remaining()];
            intBuf.get(array);

            break;
        }
        case "text/x-calvin-integer-16": {
            IntBuffer intBuf = ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN).asIntBuffer(); // wrong?

            int[] array = new int[intBuf.remaining()];
            intBuf.get(array);
            break;
        }
        case "text/x-calvin-integer-32": {
            IntBuffer intBuf = ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN).asIntBuffer();
            int[] array = new int[intBuf.remaining()];
            intBuf.get(array);

            break;
        }
        case "text/x-calvin-unsigned-integer-8": {
            ShortBuffer intBuf = ByteBuffer.wrap(value).asShortBuffer();
            short[] array = new short[intBuf.remaining()];
            intBuf.get(array);

            break;
        }
        case "text/x-calvin-unsigned-integer-16": {
            IntBuffer intBuf = ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN).asIntBuffer();// wrong?

            int[] array = new int[intBuf.remaining()];
            intBuf.get(array);

            break;
        }
        case "text/x-calvin-unsigned-integer-32": {
            IntBuffer intBuf = ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN).asIntBuffer();
            int[] array = new int[intBuf.remaining()];
            intBuf.get(array);

            break;
        }
        default:
            throw new IOException("Unknown mime type:" + type);
        }

    }

    @SuppressWarnings("unused")
    int numParentHeaders = readIntBigEndian(str);
    return result;
}

From source file:haven.Utils.java

public static FloatBuffer bufcp(FloatBuffer a) {
    a.rewind();/*from ww  w. j  av a 2  s  .c o m*/
    FloatBuffer ret = mkfbuf(a.remaining());
    ret.put(a).rewind();
    return (ret);
}

From source file:ubic.gemma.core.analysis.preprocess.batcheffects.AffyScanDateExtractor.java

@SuppressWarnings({ "unused", "WeakerAccess" }) // Possible external use
public Date parseGenericCCHeader(DataInputStream str) throws IOException {

    /*//from ww  w  .j a v  a 2  s .c  o  m
     * acquisition data, intensity data etc. Usually "intensity data" for the first header.
     */
    String datatypeIdentifier = this.readString(str);

    AffyScanDateExtractor.log.debug(datatypeIdentifier);

    String guid = this.readString(str);

    AffyScanDateExtractor.log.debug(guid);

    @SuppressWarnings("unused")
    String createDate = this.readUnicodeString(str); // blank?
    @SuppressWarnings("unused")
    String locale = this.readUnicodeString(str); // e.g. en-US
    int numKeyValuePairs = this.readIntBigEndian(str); // e.g. 55
    Date result = null;
    for (int i = 0; i < numKeyValuePairs; i++) {
        String name = this.readUnicodeString(str);
        byte[] value = this.readBytes(str);
        String type = this.readUnicodeString(str);
        Object v;

        switch (type) {
        case "text/x-calvin-float": {
            FloatBuffer intBuf = ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN).asFloatBuffer();
            float[] array = new float[intBuf.remaining()];
            intBuf.get(array);
            break;
        }
        case "text/plain":
        case "text/ascii":
            // text/ascii is undocumented, but needed.
            v = new String(value, "US-ASCII");

            if (name.equals("affymetrix-scan-date")) {
                result = this.parseISO8601(new String(((String) v).getBytes(), "UTF-16"));
                AffyScanDateExtractor.log.info("Scan date = " + result);
            }

            if (name.equals("affymetrix-Hyb-Start-Time")) {
                // We don't use this but I'm curious to start looking at it.
                AffyScanDateExtractor.log
                        .info("Hyb start date = " + new String(((String) v).getBytes(), "UTF-16"));
            }

            break;
        case "text-x-calvin-unsigned-integer-8": {
            ShortBuffer intBuf = ByteBuffer.wrap(value).asShortBuffer();
            short[] array = new short[intBuf.remaining()];
            intBuf.get(array);

            break;
        }
        case "text/x-calvin-integer-16": {
            IntBuffer intBuf = ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN).asIntBuffer(); // wrong?

            int[] array = new int[intBuf.remaining()];
            intBuf.get(array);
            break;
        }
        case "text/x-calvin-integer-32": {
            IntBuffer intBuf = ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN).asIntBuffer();
            int[] array = new int[intBuf.remaining()];
            intBuf.get(array);

            break;
        }
        case "text/x-calvin-unsigned-integer-8": {
            ShortBuffer intBuf = ByteBuffer.wrap(value).asShortBuffer();
            short[] array = new short[intBuf.remaining()];
            intBuf.get(array);

            break;
        }
        case "text/x-calvin-unsigned-integer-16": {
            IntBuffer intBuf = ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN).asIntBuffer();// wrong?

            int[] array = new int[intBuf.remaining()];
            intBuf.get(array);

            break;
        }
        case "text/x-calvin-unsigned-integer-32": {
            IntBuffer intBuf = ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN).asIntBuffer();
            int[] array = new int[intBuf.remaining()];
            intBuf.get(array);

            break;
        }
        default:
            throw new IOException("Unknown mime type:" + type);
        }

    }

    @SuppressWarnings("unused")
    int numParentHeaders = this.readIntBigEndian(str);
    return result;
}