Java 8 FloatBuffer - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 FloatBuffer class.

This code example shows how to use the following methods:hasRemaining, rewind
    return numInserted;
  } 
 
  public void add(float value) throws IOException
  { 
    if (! endBuffer.hasRemaining()) {
      endBuffer.rewind();
      flattener.write(StupidResourceHolder.create(endBuffer));
      endBuffer = FloatBuffer.allocate(sizePer);
      endBuffer.mark();
    } 
 
    endBuffer.put(value);
    ++numInserted;
  } 
 
  public void closeAndConsolidate(OutputSupplier<? extends OutputStream> consolidatedOut) throws IOException
  { 
    endBuffer.limit(endBuffer.position());
    endBuffer.rewind();
8
CodeRank
This code example shows how to use the following methods:position, put
This code example shows how to use the following methods:position, put
This code example shows how to use the following methods:get
		alListener(k, (FloatBuffer) createFloatBuffer(3).put(v.toArray()).flip());
	} 
 
	private Vector3f getVector3(int k) {
		FloatBuffer buff = createFloatBuffer(3);
		alGetListener(k, buff);
		return new Vector3f(buff.get(0), buff.get(1), buff.get(2));
	} 
 
	private void setFloatArray(int k, float[] v) {
		alListener(k, (FloatBuffer) createFloatBuffer(v.length).put(v).flip());
	} 
 
	private float[] getFloatArray(int k, int bufferSize) {
		FloatBuffer buff = createFloatBuffer(bufferSize);
		alGetListener(k, buff);
		return buff.array();
	} 
} 
7
CodeRank
This code example shows how to use the following methods:sleep, flip, position, put
 
	public static void main(String[] args) {
		try { PServer v = null; //new PServer(4444);
		ByteBuffer b = ByteBuffer.allocate(20);
		FloatBuffer fb = b.asFloatBuffer();
		fb.put(0.1f); fb.flip();
		System.out.println(fb.position() + "=fpos   bpos=" + b.position());
		Thread t = new Thread(v);
		t.start();
		try {Thread.sleep(100); } catch (Exception e ) {}
		PServerClient psc = new PServerClient("localhost",4444);
		{	int[] e = {201, 202, 203, 1000000, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2,2, 2,2,2,2,2,2,2,2,2,2,2,2,2};
			int[] f = {101, 102, 103, 104, 105, 106,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,3,2,3,5,3,4,2,3,4,5,3,2,5,6,7,12345,34};
			PhrasePair pp = new PhrasePair(new Phrase(e, 0), new Phrase(f, 1));
			psc.query(pp, true);
		} 
		//try {Thread.sleep(500); } catch (Exception ex){} 
		{int[] e = {201, 202, 203,2,2,2};
		int[] f = {101, 102, 103,6,7,12345,34};
			PhrasePair pp = new PhrasePair(new Phrase(f, 0), new Phrase(e, 1));

7
CodeRank
This code example shows how to use the following methods:position, put
        gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
 
    } 
 
    public static void fillFloatBuffer(FloatBuffer fb, float[] arr) {
        fb.position(0);
        fb.put(arr);
    } 
 
    public static FloatBuffer makeFloatBuffer(float[] arr) {
        ByteBuffer bb = BufferProvider.allocateDirect(arr.length * 4);
        bb.order(ByteOrder.nativeOrder());
        FloatBuffer fb = bb.asFloatBuffer();
        fb.put(arr);
        fb.position(0);
        return fb;
    } 
 
    public static FloatBuffer createFloatBuffer(int arrayElementCount) {
        ByteBuffer temp = BufferProvider.allocateDirect(4 * arrayElementCount);
7
CodeRank
This code example shows how to use the following methods:capacity, position
This code example shows how to use the following methods:position, put
        mVertexBuffer.position(0);
 
        vbb = ByteBuffer.allocateDirect(colors.length*4);
        vbb.order(ByteOrder.nativeOrder());
        mColorBuffer = vbb.asFloatBuffer();
        mColorBuffer.put(colors);
        mColorBuffer.position(0);
 
        mIndexBuffer = ByteBuffer.allocateDirect(indices.length);
        mIndexBuffer.put(indices);
        mIndexBuffer.position(0);
    } 
 
    public void onAccuracyChanged(Sensor sensor, int accuracy) {
    } 
 
    public void onSensorChanged(SensorEvent event) {
        int type = event.sensor.getType();
        float[] data;
        if (type == Sensor.TYPE_ACCELEROMETER) {
7
CodeRank
This code example shows how to use the following methods:position, put
	public Triangle() { 
		// 
		ByteBuffer byteBuf = ByteBuffer.allocateDirect(vertices.length * 4);
		byteBuf.order(ByteOrder.nativeOrder());
		vertexBuffer = byteBuf.asFloatBuffer();
		vertexBuffer.put(vertices);
		vertexBuffer.position(0);
	} 
 
	/** 
	 * The object own drawing function. Called from the renderer to redraw this 
	 * instance with possible changes in values. 
	 *  
	 * @param gl 
	 *            - The GL context 
	 */ 
	public void draw(GL10 gl) {
		// Set the face rotation 
		gl.glFrontFace(GL10.GL_CCW);
 
7
CodeRank
This code example shows how to use the following methods:capacity, rewind, get, hasArray
	 * @param buffer {@link FloatBuffer} the data source. 
	 * @return float array containing the data of the buffer. 
	 */ 
	public static float[] getFloatArrayFromBuffer(FloatBuffer buffer) {
		float[] array = null;
		if (buffer.hasArray()) {
			array = buffer.array();
		} else { 
			buffer.rewind();
			array = new float[buffer.capacity()];
			buffer.get(array);		
		} 
		return array;
	} 
 
	/** 
	 * Creates an int array from the provided {@link IntBuffer} or {@link ShortBuffer}. 
	 *  
	 * @param buffer {@link Buffer} the data source. Should be either a {@link IntBuffer}  
	 * or {@link ShortBuffer}. 
7
CodeRank

Related Java 8 FloatBuffer Questions & Answers:

See Code Examples for Java 8 FloatBuffer Methods: