Example usage for java.nio DoubleBuffer get

List of usage examples for java.nio DoubleBuffer get

Introduction

In this page you can find the example usage for java.nio DoubleBuffer get.

Prototype

public abstract double get();

Source Link

Document

Returns the double at the current position and increases the position by 1.

Usage

From source file:Main.java

public static void main(String[] args) {
    DoubleBuffer bb = DoubleBuffer.allocate(BSIZE);

    bb.put(98765);/*from   w w w .  ja  va2  s . c om*/
    System.out.println(bb.get());

}

From source file:Main.java

public static void main(String[] args) {
    ByteBuffer bb = ByteBuffer.wrap(new byte[] { 0, 0, 0, 0, 0, 0, 0, 'a' });
    bb.rewind();/* www . j  a va 2 s. co  m*/
    DoubleBuffer db = ((ByteBuffer) bb.rewind()).asDoubleBuffer();
    System.out.println("Double Buffer");
    while (db.hasRemaining())
        System.out.println(db.position() + " -> " + db.get());
}

From source file:Main.java

public static void main(String[] args) {
    ByteBuffer bb = ByteBuffer.wrap(new byte[] { 0, 0, 0, 0, 0, 0, 0, 'a' });
    bb.rewind();/* w  ww .  jav  a  2 s . c  om*/
    System.out.println("Byte Buffer");
    while (bb.hasRemaining())
        System.out.println(bb.position() + " -> " + bb.get());
    CharBuffer cb = ((ByteBuffer) bb.rewind()).asCharBuffer();
    System.out.println("Char Buffer");
    while (cb.hasRemaining())
        System.out.println(cb.position() + " -> " + cb.get());
    FloatBuffer fb = ((ByteBuffer) bb.rewind()).asFloatBuffer();
    System.out.println("Float Buffer");
    while (fb.hasRemaining())
        System.out.println(fb.position() + " -> " + fb.get());
    IntBuffer ib = ((ByteBuffer) bb.rewind()).asIntBuffer();
    System.out.println("Int Buffer");
    while (ib.hasRemaining())
        System.out.println(ib.position() + " -> " + ib.get());
    LongBuffer lb = ((ByteBuffer) bb.rewind()).asLongBuffer();
    System.out.println("Long Buffer");
    while (lb.hasRemaining())
        System.out.println(lb.position() + " -> " + lb.get());
    ShortBuffer sb = ((ByteBuffer) bb.rewind()).asShortBuffer();
    System.out.println("Short Buffer");
    while (sb.hasRemaining())
        System.out.println(sb.position() + " -> " + sb.get());
    DoubleBuffer db = ((ByteBuffer) bb.rewind()).asDoubleBuffer();
    System.out.println("Double Buffer");
    while (db.hasRemaining())
        System.out.println(db.position() + " -> " + db.get());
}

From source file:gephi.spade.panel.fcsFile.java

/**
 * readDoubleData ---//  w ww .  j  a v  a  2 s.  com
 * <p>
 * Reads double precision floating point values in list mode in the DATA
 * segment and updates eventList with the integer values of the values.
 * </p>
 *
 * @param data
 *            <code>ByteBuffer</code> containing the DATA segment of the
 *            underlying file.
 */
private void readDoubleData(ByteBuffer data) {
    // Allocate the eventList
    eventList = new double[parameters][totalEvents];

    if (littleEndianP) {
        data.order(ByteOrder.LITTLE_ENDIAN);
    }

    // Convert the byte buffer into a double buffer - doesn't get any easier
    DoubleBuffer db = data.asDoubleBuffer();

    final int totalEvents = this.totalEvents;
    final int parameters = this.parameters;

    for (int i = 0; i < totalEvents; i++) {
        for (int j = 0; j < parameters; j++) {
            // Store the value into the array
            eventList[j][i] = db.get();
        }
    }
}

From source file:org.bimserver.collada.ColladaSerializer.java

private List<String> doubleBufferToStringList(DoubleBuffer buffer, Format formatter) {
    // Transform the array into a list.
    List<Float> list = new ArrayList<Float>();
    while (buffer.hasRemaining())
        list.add(new Float(buffer.get()));
    // Get the data as a list of String objects.
    return listToStringList(list, formatter);
}

From source file:org.bimserver.collada.SupportFunctions.java

public static List<String> doubleBufferToStringList(DoubleBuffer buffer, Format formatter) {
    // Transform the array into a list.
    List<Float> list = new ArrayList<Float>();
    while (buffer.hasRemaining())
        list.add(new Float(buffer.get()));
    // Get the data as a list of String objects.
    return SupportFunctions.listToStringList(list, formatter);
}

From source file:org.mitre.math.linear.BufferRealMatrix.java

/**
 * Compute the sum of this and <code>m</code>.
 *
 * @param m    matrix to be added/*from   w  w  w  .  j  ava  2  s.  c om*/
 * @return     this + m
 * @throws  IllegalArgumentException if m is not the same size as this
 */
public BufferRealMatrix add(final BufferRealMatrix b) throws IllegalArgumentException {

    // safety checks
    if (b == this) {
        return this.addSelf();
    }
    MatrixUtils.checkAdditionCompatible(this, b);

    try {
        final BufferRealMatrix c = new BufferRealMatrix(rows, columns, null);

        // perform addition block-wise, to ensure good cache behavior
        for (int blockIndex = 0; blockIndex < this.blockRows * this.blockColumns; ++blockIndex) {
            // all the same size, so should all be the same blockOffsets and layout
            final long blockOffset = this.getBlockOffset(blockIndex);
            DoubleBuffer adb = this.dataFileChannel
                    .map(FileChannel.MapMode.READ_WRITE, blockOffset, BLOCK_BYTE_SIZE).asDoubleBuffer();
            adb.clear();
            DoubleBuffer bdb = b.dataFileChannel
                    .map(FileChannel.MapMode.READ_WRITE, blockOffset, BLOCK_BYTE_SIZE).asDoubleBuffer();
            bdb.clear();
            DoubleBuffer cdb = c.dataFileChannel
                    .map(FileChannel.MapMode.READ_WRITE, blockOffset, BLOCK_BYTE_SIZE).asDoubleBuffer();
            cdb.clear();
            for (int k = 0; k < BLOCK_BYTE_SIZE / DOUBLE_BYTE_SIZE; k++) {
                try {
                    cdb.put(adb.get() + bdb.get());
                } catch (BufferUnderflowException e) {
                    LOG.fatal(String.format("BufferUnderflowException while adding elements at %d in block %d",
                            k, blockIndex));
                    throw e;
                }
            }
        }
        return c;
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }
}

From source file:org.mitre.math.linear.BufferRealMatrix.java

/** Special case for adding to ourself */
private BufferRealMatrix addSelf() {
    try {//from   w  w w  .j  a va  2 s .c o  m
        final BufferRealMatrix c = new BufferRealMatrix(rows, columns, null);

        // perform addition block-wise, to ensure good cache behavior
        for (int blockIndex = 0; blockIndex < this.blockRows * this.blockColumns; ++blockIndex) {
            // all the same size, so should all be the same blockOffsets and layout
            final long blockOffset = this.getBlockOffset(blockIndex);
            DoubleBuffer adb = this.dataFileChannel
                    .map(FileChannel.MapMode.READ_WRITE, blockOffset, BLOCK_BYTE_SIZE).asDoubleBuffer();
            adb.clear();
            DoubleBuffer cdb = c.dataFileChannel
                    .map(FileChannel.MapMode.READ_WRITE, blockOffset, BLOCK_BYTE_SIZE).asDoubleBuffer();
            cdb.clear();
            for (int k = 0; k < BLOCK_BYTE_SIZE / DOUBLE_BYTE_SIZE; k++) {
                try {
                    double ad = adb.get();
                    cdb.put(ad + ad);
                } catch (BufferUnderflowException e) {
                    LOG.fatal(String.format("BufferUnderflowException while adding elements at %d in block %d",
                            k, blockIndex));
                    throw e;
                }
            }
        }
        return c;
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }
}

From source file:org.mitre.math.linear.BufferRealMatrix.java

/** {@inheritDoc} */
public BufferRealMatrix subtract(final BufferRealMatrix b) throws IllegalArgumentException {

    //        if (b == this) {
    //    return this.subtractSelf();
    // }//www  . java  2 s . c om
    // safety check
    MatrixUtils.checkSubtractionCompatible(this, b);

    try {
        final BufferRealMatrix c = new BufferRealMatrix(rows, columns, null);

        // perform addition block-wise, to ensure good cache behavior
        for (int blockIndex = 0; blockIndex < this.blockRows * this.blockColumns; ++blockIndex) {
            // all the same size, so should all be the same blockOffsets and layout
            final long blockOffset = this.getBlockOffset(blockIndex);
            DoubleBuffer adb = this.dataFileChannel
                    .map(FileChannel.MapMode.READ_WRITE, blockOffset, BLOCK_BYTE_SIZE).asDoubleBuffer();
            adb.clear();
            DoubleBuffer bdb = b.dataFileChannel
                    .map(FileChannel.MapMode.READ_WRITE, blockOffset, BLOCK_BYTE_SIZE).asDoubleBuffer();
            bdb.clear();
            DoubleBuffer cdb = c.dataFileChannel
                    .map(FileChannel.MapMode.READ_WRITE, blockOffset, BLOCK_BYTE_SIZE).asDoubleBuffer();
            cdb.clear();
            for (int k = 0; k < BLOCK_BYTE_SIZE / DOUBLE_BYTE_SIZE; k++) {
                try {
                    cdb.put(adb.get() - bdb.get());
                } catch (BufferUnderflowException e) {
                    LOG.fatal(String.format("BufferUnderflowException while adding elements at %d in block %d",
                            k, blockIndex));
                    throw e;
                }
            }
        }
        return c;
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }
}

From source file:org.mitre.math.linear.BufferRealMatrix.java

/** {@inheritDoc} */
public BufferRealMatrix scalarAdd(final double d) {
    try {// w  ww  . ja  v  a2  s .  co  m
        final BufferRealMatrix c = new BufferRealMatrix(rows, columns, null);

        // perform addition block-wise, to ensure good cache behavior
        for (int blockIndex = 0; blockIndex < this.blockRows * this.blockColumns; ++blockIndex) {
            // all the same size, so should all be the same blockOffsets and layout
            final long blockOffset = this.getBlockOffset(blockIndex);
            DoubleBuffer adb = this.dataFileChannel
                    .map(FileChannel.MapMode.READ_WRITE, blockOffset, BLOCK_BYTE_SIZE).asDoubleBuffer();
            adb.clear();
            DoubleBuffer cdb = c.dataFileChannel
                    .map(FileChannel.MapMode.READ_WRITE, blockOffset, BLOCK_BYTE_SIZE).asDoubleBuffer();
            cdb.clear();
            for (int k = 0; k < BLOCK_BYTE_SIZE / DOUBLE_BYTE_SIZE; k++) {
                try {
                    double ad = adb.get();
                    cdb.put(ad + d);
                } catch (BufferUnderflowException e) {
                    LOG.fatal(String.format("BufferUnderflowException while adding elements at %d in block %d",
                            k, blockIndex));
                    throw e;
                }
            }
        }
        return c;
    } catch (IllegalArgumentException ex) {
        LOG.fatal(ex);
        throw new RuntimeException(ex);
    } catch (IOException ex) {
        LOG.fatal(ex);
        throw new RuntimeException(ex);
    }
}