Example usage for java.nio ByteBuffer getDouble

List of usage examples for java.nio ByteBuffer getDouble

Introduction

In this page you can find the example usage for java.nio ByteBuffer getDouble.

Prototype

public abstract double getDouble();

Source Link

Document

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

Usage

From source file:Main.java

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

    bb.asDoubleBuffer().put(99471142);//from   w w  w .ja  v  a  2 s  . co  m
    System.out.println(bb.getDouble());

}

From source file:Main.java

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

    bb.asDoubleBuffer().put(9947.1142);//from   w w w . j a v a  2 s  . co  m
    System.out.println(bb.getDouble());

}

From source file:Main.java

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

    bb.asDoubleBuffer().put(9947.1142);/*  w w w  .j a  va 2 s  .c om*/
    bb.rewind();
    System.out.println(bb.getDouble());

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    ByteBuffer buf = ByteBuffer.allocate(100);

    // Put values of different types
    buf.putDouble(12.3D);/*from   www  .  j a  va  2s  .c  o  m*/

    // Reset position for reading
    buf.flip();

    // Retrieve the values
    double d = buf.getDouble();

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    File aFile = new File("main.java");
    FileInputStream inFile = new FileInputStream(aFile);
    FileChannel inChannel = inFile.getChannel();
    ByteBuffer lengthBuf = ByteBuffer.allocate(8);
    while (true) {
        if (inChannel.read(lengthBuf) == -1) {
            break;
        }//  w  w w .  j  av a  2  s  .c  om
        lengthBuf.flip();
        int strLength = (int) lengthBuf.getDouble();
        ByteBuffer buf = ByteBuffer.allocate(2 * strLength + 8);
        if (inChannel.read(buf) == -1) {
            break;
        }
        buf.flip();
        byte[] strChars = new byte[2 * strLength];
        buf.get(strChars);
        System.out.println(strLength);
        System.out.println(ByteBuffer.wrap(strChars).asCharBuffer());
        System.out.println(buf.getLong());
        lengthBuf.clear();
    }
    inFile.close();
}

From source file:MainClass.java

public static void main(String[] args) {
    File aFile = new File("primes.txt");
    FileInputStream inFile = null;
    try {//from ww  w.j  a  v  a2 s. c  om
        inFile = new FileInputStream(aFile);
    } catch (FileNotFoundException e) {
        e.printStackTrace(System.err);
    }
    FileChannel inChannel = inFile.getChannel();
    try {
        ByteBuffer lengthBuf = ByteBuffer.allocate(8);
        while (true) {
            if (inChannel.read(lengthBuf) == -1) {
                break;
            }
            lengthBuf.flip();
            int strLength = (int) lengthBuf.getDouble();
            ByteBuffer buf = ByteBuffer.allocate(2 * strLength + 8);
            if (inChannel.read(buf) == -1) {
                break;
            }
            buf.flip();
            byte[] strChars = new byte[2 * strLength];
            buf.get(strChars);
            System.out.println(strLength);
            System.out.println(ByteBuffer.wrap(strChars).asCharBuffer());
            System.out.println(buf.getLong());
            lengthBuf.clear();
        }
        inFile.close();
    } catch (IOException e) {
        e.printStackTrace(System.err);
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    File aFile = new File("primes.txt");
    FileInputStream inFile = new FileInputStream(aFile);
    FileChannel inChannel = inFile.getChannel();
    ByteBuffer buf = ByteBuffer.allocateDirect(1024);
    buf.position(buf.limit());/*w  w  w  .ja va2 s  . c  o  m*/
    while (true) {
        if (buf.remaining() < 8) {
            if (inChannel.read(buf.compact()) == -1) {
                break;
            }
            buf.flip();
        }
        int strLength = (int) buf.getDouble();
        if (buf.remaining() < 2 * strLength) {
            if (inChannel.read(buf.compact()) == -1) {
                break;
            }
            buf.flip();
        }
        byte[] strChars = new byte[2 * strLength];
        buf.get(strChars);
        if (buf.remaining() < 8) {
            if (inChannel.read(buf.compact()) == -1) {
                break;
            }
            buf.flip();
        }
        System.out.println(strLength);
        System.out.println(ByteBuffer.wrap(strChars).asCharBuffer());
        System.out.println(buf.getLong());
    }
    inFile.close();
}

From source file:Main.java

public static void main(String[] args) {
    ByteBuffer bb = ByteBuffer.allocate(BSIZE);
    bb.asIntBuffer().put(99471142);//from w w  w .j  a va 2 s  .com
    System.out.println(bb.getInt());

    bb = ByteBuffer.allocate(BSIZE);
    bb.asLongBuffer().put(99472342341142L);
    System.out.println(bb.getLong());

    bb = ByteBuffer.allocate(BSIZE);

    bb.asFloatBuffer().put(99471142);
    System.out.println(bb.getFloat());

    bb = ByteBuffer.allocate(BSIZE);

    bb.asDoubleBuffer().put(99471142);
    System.out.println(bb.getDouble());

}

From source file:GetData.java

public static void main(String[] args) {
    ByteBuffer bb = ByteBuffer.allocate(BSIZE);
    // Allocation automatically zeroes the ByteBuffer:
    int i = 0;//from w ww  . ja  v  a  2  s.c  o m
    while (i++ < bb.limit())
        if (bb.get() != 0)
            System.out.println("nonzero");
    System.out.println("i = " + i);
    bb.rewind();
    // Store and read a char array:
    bb.asCharBuffer().put("Howdy!");
    char c;
    while ((c = bb.getChar()) != 0)
        System.out.print(c + " ");
    System.out.println();
    bb.rewind();
    // Store and read a short:
    bb.asShortBuffer().put((short) 471142);
    System.out.println(bb.getShort());
    bb.rewind();
    // Store and read an int:
    bb.asIntBuffer().put(99471142);
    System.out.println(bb.getInt());
    bb.rewind();
    // Store and read a long:
    bb.asLongBuffer().put(99471142);
    System.out.println(bb.getLong());
    bb.rewind();
    // Store and read a float:
    bb.asFloatBuffer().put(99471142);
    System.out.println(bb.getFloat());
    bb.rewind();
    // Store and read a double:
    bb.asDoubleBuffer().put(99471142);
    System.out.println(bb.getDouble());
    bb.rewind();

}

From source file:org.bimserver.utils.BinUtils.java

public static double byteArrayToDouble(byte[] data) {
    ByteBuffer byteBuffer = ByteBuffer.wrap(data);
    return byteBuffer.getDouble();
}