List of usage examples for java.nio FloatBuffer get
public abstract float get();
From source file:Main.java
public static void main(String[] args) { FloatBuffer floatBuffer = FloatBuffer.allocate(10); floatBuffer.put(0, 1.23F);/*ww w .j ava 2s.c o m*/ floatBuffer.rewind(); System.out.println(floatBuffer.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();//from w w w . j ava 2s. co m FloatBuffer fb = ((ByteBuffer) bb.rewind()).asFloatBuffer(); System.out.println("Float Buffer"); while (fb.hasRemaining()) System.out.println(fb.position() + " -> " + fb.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();//from w w w . j a v a 2 s . com 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:Main.java
public static float toFloatEx(byte[] b, int pos) { try {//from w w w.java2 s . co m byte[] byteTmp = new byte[4]; for (int i = 0; i < 4; i++) { byteTmp[i] = b[pos + i]; } ByteBuffer bb = ByteBuffer.wrap(byteTmp); FloatBuffer fb = bb.asFloatBuffer(); return fb.get(); } catch (Exception e) { e.printStackTrace(); return 0.0f; } }
From source file:Main.java
/** * Create a new float[] array and populate it with the given FloatBuffer's * contents./* www . j a va 2 s . c o m*/ * * @param buff * the FloatBuffer to read from * @return a new float array populated from the FloatBuffer */ public static float[] getFloatArray(FloatBuffer buff) { if (buff == null) { return null; } buff.clear(); float[] inds = new float[buff.limit()]; for (int x = 0; x < inds.length; x++) { inds[x] = buff.get(); } return inds; }
From source file:Main.java
public static FloatBuffer createFloatBuffer(FloatBuffer buf, int start, int end) { final float[] inds = new float[buf.limit()]; for (int x = start - 1; x < end - 1; x++) { inds[x] = buf.get(); }/*from w w w .j a va2 s.c o m*/ return createFloatBuffer(inds); }
From source file:Main.java
public static FloatBuffer createFloatBuffer(FloatBuffer buffer, int start, int end) { final float[] inds = new float[buffer.limit()]; for (int x = start - 1; x < end - 1; x++) { inds[x] = buffer.get(); }// ww w.j a v a2 s . c o m return createFloatBuffer(inds); }
From source file:Main.java
public static float[] getFloatArray(final FloatBuffer buff) { if (buff == null) { return null; }/*from w w w . ja va2 s .c o m*/ buff.clear(); final float[] inds = new float[buff.limit()]; for (int x = 0; x < inds.length; x++) { inds[x] = buff.get(); } return inds; }
From source file:Main.java
private static String formatFloats(byte[] data) { FloatBuffer bb = ByteBuffer.wrap(data).order(ByteOrder.LITTLE_ENDIAN).asFloatBuffer(); StringBuilder sb = new StringBuilder(bb.capacity() * 3); while (bb.remaining() > 0) { sb.append(String.format("%.4f", bb.get())); sb.append(','); sb.append('\n'); }//from w ww . jav a2 s. c om return sb.toString(); }
From source file:org.bimserver.collada.SupportFunctions.java
public static void printMatrix(PrintWriter out, GeometryInfo geometryInfo) { ByteBuffer transformation = ByteBuffer.wrap(geometryInfo.getTransformation()); transformation.order(ByteOrder.LITTLE_ENDIAN); FloatBuffer floatBuffer = transformation.asFloatBuffer(); // Prepare to create the transform matrix. float[] matrix = new float[16]; // Add the first 16 values of the buffer. for (int i = 0; i < matrix.length; i++) matrix[i] = floatBuffer.get(); // Switch from column-major (x.x ... x.y ... x.z ... 0 ...) to row-major orientation (x.x x.y x.z 0 ...)? matrix = Matrix.changeOrientation(matrix); // List all 16 elements of the matrix as a single space-delimited String object. if (!matrix.equals(identity)) out.println(" <matrix>" + floatArrayToSpaceDelimitedString(matrix) + "</matrix>"); }