List of usage examples for java.nio ByteBuffer asDoubleBuffer
public abstract DoubleBuffer asDoubleBuffer();
From source file:Main.java
public static void main(String[] args) { ByteBuffer bb = ByteBuffer.allocate(BSIZE); bb.asDoubleBuffer().put(99471142); 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); System.out.println(bb.getDouble(0)); }
From source file:Main.java
public static void main(String[] args) { ByteBuffer bb = ByteBuffer.allocate(BSIZE); bb.asDoubleBuffer().put(9947.1142); 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); bb.rewind();//from w w w. j a va 2 s. c o m System.out.println(bb.getDouble()); }
From source file:Main.java
public static void main(String[] argv) throws Exception { ByteBuffer buf = ByteBuffer.allocate(15); DoubleBuffer dbuf = buf.asDoubleBuffer(); }
From source file:MainClass.java
public static void main(String[] args) { long[] primes = new long[] { 1, 2, 3, 5, 7 }; File aFile = new File("C:/test/primes.txt"); FileOutputStream outputFile = null; try {//from w w w . j a va 2 s. com outputFile = new FileOutputStream(aFile); } catch (FileNotFoundException e) { e.printStackTrace(System.err); } FileChannel file = outputFile.getChannel(); final int BUFFERSIZE = 100; ByteBuffer buf = ByteBuffer.allocate(BUFFERSIZE); DoubleBuffer doubleBuf = buf.asDoubleBuffer(); buf.position(8); CharBuffer charBuf = buf.asCharBuffer(); for (long prime : primes) { String primeStr = "prime = " + prime; doubleBuf.put(0, (double) primeStr.length()); charBuf.put(primeStr); buf.position(2 * charBuf.position() + 8); LongBuffer longBuf = buf.asLongBuffer(); longBuf.put(prime); buf.position(buf.position() + 8); buf.flip(); try { file.write(buf); } catch (IOException e) { e.printStackTrace(System.err); } buf.clear(); doubleBuf.clear(); charBuf.clear(); } try { System.out.println("File written is " + file.size() + "bytes."); outputFile.close(); } catch (IOException e) { e.printStackTrace(System.err); } }
From source file:Main.java
public static void main(String[] args) { ByteBuffer bb = ByteBuffer.allocate(BSIZE); bb.asIntBuffer().put(99471142);/*from ww w .ja v a 2 s. c om*/ 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;// w w w. java 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:Main.java
public static DoubleBuffer newDoubleBuffer(int numElements) { ByteBuffer bb = newByteBuffer(numElements * SIZEOF_DOUBLE); return bb.asDoubleBuffer(); }
From source file:Main.java
public static ByteBuffer copyDoubleBufferAsByteBuffer(DoubleBuffer buf) { ByteBuffer dest = newByteBuffer(buf.remaining() * SIZEOF_DOUBLE); buf.mark();/*from w w w . j av a 2s . c om*/ dest.asDoubleBuffer().put(buf); buf.reset(); dest.rewind(); return dest; }