Example usage for java.nio DoubleBuffer put

List of usage examples for java.nio DoubleBuffer put

Introduction

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

Prototype

public DoubleBuffer put(double[] src, int off, int len) 

Source Link

Document

Writes doubles from the given double array, starting from the specified offset, to the current position and increases the position by the number of doubles written.

Usage

From source file:Main.java

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

    bb.put(new double[] { 98765, 12345 }, 0, 1);

    System.out.println(Arrays.toString(bb.array()));

}

From source file:org.cytobank.fcs_files.events.MemoryEvents.java

protected synchronized boolean writeOut() {
    if (memoryEventsArray == null)
        return false;

    File memoryEventsArrayOnDisk = null;

    synchronized (memoryEventsArray) {
        memoryEventsArrayOnDisk = memoryEventsArray.getOnDisk();

        if (memoryEventsArrayOnDisk != null || events == null)
            return false;

        RandomAccessFile randomAccessFile = null;
        FileChannel fileChannel = null;

        try {/*from   ww  w . ja  v a  2s .co m*/
            memoryEventsArrayOnDisk = File.createTempFile("memoryEventsArrayOnDisk", "evt");
            memoryEventsArrayOnDisk.deleteOnExit();
            randomAccessFile = new RandomAccessFile(memoryEventsArrayOnDisk, "rw");
            fileChannel = randomAccessFile.getChannel();

            MappedByteBuffer mappedByteBuffer = fileChannel.map(MapMode.READ_WRITE, 0,
                    numberOfEvents * BYTES_PER_DOUBLE);
            DoubleBuffer doubleBuffer = mappedByteBuffer.asDoubleBuffer();
            doubleBuffer.put(events, 0, numberOfEvents);
            mappedByteBuffer.force();
            fileChannel.close();
            randomAccessFile.close();

            memoryEventsArray.setOnDisk(memoryEventsArrayOnDisk);

        } catch (IOException ioe) {
            logger.log(Level.INFO, "::::: Failed to write out MemoryEventsArray :::::", ioe);
            if (memoryEventsArrayOnDisk != null) {
                memoryEventsArrayOnDisk.delete();
                memoryEventsArrayOnDisk = null;
            }
        } finally {
            memoryEventsArrayOnDisk.delete();
        }
    }

    return true;

}