List of usage examples for java.nio ByteBuffer getFloat
public abstract float getFloat();
From source file:Main.java
public static void main(String[] args) { ByteBuffer bb = ByteBuffer.allocate(BSIZE); bb.asFloatBuffer().put(994.7F);//from w w w .ja v a 2 s .co m System.out.println(bb.getFloat()); }
From source file:Main.java
public static void main(String[] args) { ByteBuffer bb = ByteBuffer.allocate(BSIZE); bb.asFloatBuffer().put(99471142);//from w w w . ja v a2 s . c o m System.out.println(bb.getFloat()); }
From source file:Main.java
public static void main(String[] args) { ByteBuffer bb = ByteBuffer.allocate(BSIZE); bb.asFloatBuffer().put(994.7F);// ww w .j ava 2 s . co m bb.rewind(); System.out.println(bb.getFloat()); }
From source file:Main.java
public static void main(String[] argv) throws Exception { ByteBuffer buf = ByteBuffer.allocate(100); // Put values of different types buf.putFloat(12.3F);/*from w ww.j a v a 2s .co m*/ // Reset position for reading buf.flip(); // Retrieve the values float f = buf.getFloat(); }
From source file:Main.java
public static void main(String[] args) { ByteBuffer bb = ByteBuffer.allocate(BSIZE); bb.asIntBuffer().put(99471142);/* w ww . ja v a2 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;//from w w w . 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 float byteArrayToFloat(byte[] data) { ByteBuffer byteBuffer = ByteBuffer.wrap(data); return byteBuffer.getFloat(); }
From source file:ConversionUtil.java
public static float convertToFloat(byte[] array) { ByteBuffer buffer = ByteBuffer.wrap(array); return buffer.getFloat(); /*/*from w ww . ja v a 2 s . co m*/ int intValue = convertToInt(array); return Float.intBitsToFloat(intValue); */ }
From source file:org.bimserver.collada.SupportFunctions.java
public static List<String> floatBufferToStringList(ByteBuffer buffer, Format formatter) { // Transform the array into a list. List<Float> list = new ArrayList<Float>(); while (buffer.hasRemaining()) list.add(new Float(buffer.getFloat())); // Get the data as a list of String objects. return SupportFunctions.listToStringList(list, formatter); }
From source file:au.org.ala.layers.grid.GridCacheBuilder.java
static public float getNextValue(RandomAccessFile raf, Grid g) { float f = Float.NaN; try {//from ww w. j a va2 s.c o m int size; byte[] b; if (g.datatype.charAt(0) == 'B') {//"BYTE")) { f = raf.readByte(); } else if (g.datatype.charAt(0) == 'U') {//equalsIgnoreCase("UBYTE")) { f = raf.readByte(); if (f < 0) { f += 256; } } else if (g.datatype.charAt(0) == 'S') {//equalsIgnoreCase("SHORT")) { size = 2; b = new byte[size]; raf.read(b); if (g.byteorderLSB) { f = (short) (((0xFF & b[1]) << 8) | (b[0] & 0xFF)); } else { f = (short) (((0xFF & b[0]) << 8) | (b[1] & 0xFF)); } } else if (g.datatype.charAt(0) == 'I') {//equalsIgnoreCase("INT")) { size = 4; b = new byte[size]; raf.read(b); if (g.byteorderLSB) { f = ((0xFF & b[3]) << 24) | ((0xFF & b[2]) << 16) + ((0xFF & b[1]) << 8) + (b[0] & 0xFF); } else { f = ((0xFF & b[0]) << 24) | ((0xFF & b[1]) << 16) + ((0xFF & b[2]) << 8) + ((0xFF & b[3]) & 0xFF); } } else if (g.datatype.charAt(0) == 'L') {//equalsIgnoreCase("LONG")) { size = 8; b = new byte[size]; raf.read(b); if (g.byteorderLSB) { f = ((long) (0xFF & b[7]) << 56) + ((long) (0xFF & b[6]) << 48) + ((long) (0xFF & b[5]) << 40) + ((long) (0xFF & b[4]) << 32) + ((long) (0xFF & b[3]) << 24) + ((long) (0xFF & b[2]) << 16) + ((long) (0xFF & b[1]) << 8) + (0xFF & b[0]); } else { f = ((long) (0xFF & b[0]) << 56) + ((long) (0xFF & b[1]) << 48) + ((long) (0xFF & b[2]) << 40) + ((long) (0xFF & b[3]) << 32) + ((long) (0xFF & b[4]) << 24) + ((long) (0xFF & b[5]) << 16) + ((long) (0xFF & b[6]) << 8) + (0xFF & b[7]); } } else if (g.datatype.charAt(0) == 'F') {//.equalsIgnoreCase("FLOAT")) { size = 4; b = new byte[size]; raf.read(b); ByteBuffer bb = ByteBuffer.wrap(b); if (g.byteorderLSB) { bb.order(ByteOrder.LITTLE_ENDIAN); } f = bb.getFloat(); } else if (g.datatype.charAt(0) == 'D') {//.equalsIgnoreCase("DOUBLE")) { size = 8; b = new byte[8]; raf.read(b); ByteBuffer bb = ByteBuffer.wrap(b); if (g.byteorderLSB) { bb.order(ByteOrder.LITTLE_ENDIAN); } f = (float) bb.getDouble(); } //replace not a number if ((float) f == (float) g.nodatavalue) { f = Float.NaN; } } catch (Exception e) { } return f; }