Package java.nio

Examples of java.nio.ByteBuffer.asFloatBuffer()


 
  public static FloatBuffer newFloatBuffer (int numFloats) {
    if (GWT.isProdMode()) {
      ByteBuffer buffer = ByteBuffer.allocateDirect(numFloats * 4);
      buffer.order(ByteOrder.nativeOrder());
      return buffer.asFloatBuffer();
    } else {
      return FloatBuffer.wrap(new float[numFloats]);
    }
  }

View Full Code Here


  public static FloatBuffer newFloatBuffer (int numFloats) {
    if (GWT.isProdMode()) {
      ByteBuffer buffer = ByteBuffer.allocateDirect(numFloats * 4);
      buffer.order(ByteOrder.nativeOrder());
      return buffer.asFloatBuffer();
    } else {
      return FloatBuffer.wrap(new float[numFloats]);
    }
  }

View Full Code Here

          ByteArrayInputStream bis = new ByteArrayInputStream(buf.array());
          return bis;
        } else if (type.getName().equals(CAS.TYPE_NAME_FLOAT_ARRAY)) {
          arrayStart = getArrayStartAddress(fs.getAddress());
          buf = ByteBuffer.allocate(arraySize * 4);
          FloatBuffer floatbuf = buf.asFloatBuffer();
          float[] floatArray = new float[arraySize];
          for (int i = arrayStart; i < arrayStart + arraySize; i++) {
            floatArray[i - arrayStart] = Float.intBitsToFloat(this.getHeap().heap[i]);
          }
          floatbuf.put(floatArray);
View Full Code Here

    }
    public void testFloatBufferGet() {
        final float MAGIC = 1234.5678f;
        Memory m = new Memory(8);
        ByteBuffer buf = m.getByteBuffer(0, m.getSize()).order(ByteOrder.nativeOrder());
        FloatBuffer fb = buf.asFloatBuffer();
        m.setFloat(0, MAGIC);
        assertEquals("Float not read from memory", MAGIC,
                fb.get(0));
    }
    public void testDoubleBufferGet() {
View Full Code Here

        assertEquals("IntBuffer Pointer does not match",
                     p, Native.getDirectBufferPointer(b.asIntBuffer()));
        assertEquals("LongBuffer Pointer does not match",
                     p, Native.getDirectBufferPointer(b.asLongBuffer()));
        assertEquals("FloatBuffer Pointer does not match",
                     p, Native.getDirectBufferPointer(b.asFloatBuffer()));
        assertEquals("DoubleBuffer Pointer does not match",
                     p, Native.getDirectBufferPointer(b.asDoubleBuffer()));
    }

    public static void main(String[] args) {
View Full Code Here

    }
    public void testFloatBufferPut() {
        final float MAGIC = 1234.5678f;
        Memory m = new Memory(8);
        ByteBuffer buf = m.getByteBuffer(0, m.getSize()).order(ByteOrder.nativeOrder());
        FloatBuffer fb = buf.asFloatBuffer();
        fb.put(MAGIC).flip();
        assertEquals("Int not written to memory", MAGIC,
                m.getFloat(0));
    }
    public void testDoubleBufferPut() {
View Full Code Here

          ByteArrayInputStream bis = new ByteArrayInputStream(buf.array());
          return bis;
        } else if (type.getName().equals(CAS.TYPE_NAME_FLOAT_ARRAY)) {
          arrayStart = getArrayStartAddress(fs.getAddress());
          buf = ByteBuffer.allocate(arraySize * 4);
          FloatBuffer floatbuf = buf.asFloatBuffer();
          float[] floatArray = new float[arraySize];
          for (int i = arrayStart; i < arrayStart + arraySize; i++) {
            floatArray[i - arrayStart] = Float.intBitsToFloat(this.getHeap().heap[i]);
          }
          floatbuf.put(floatArray);
View Full Code Here

        if(byteBuffer.remaining() < byteLen) {
            throw new EOFException();
        }

        // Get the view Buffer.
        FloatBuffer viewBuffer = byteBuffer.asFloatBuffer();

        // Get the floats.
        viewBuffer.get(f, off, len);

        // Update the position.
View Full Code Here

    if(inChannel.read(buf)!=50*triangleCount)
      throw new RuntimeException("could not read "+(50*triangleCount)+"bytes!");
   
    for(int i=0;i<triangleCount;i++){
      buf.position(50*i);
      buf.asFloatBuffer().get(triangleEdgeData, i*12, 12);
    }
   
    fis.close();
   
    return new TriangleMeshModel(triangleEdgeData);
View Full Code Here

    }
    public void testFloatBufferPut() {
        final float MAGIC = 1234.5678f;
        Memory m = new Memory(8);
        ByteBuffer buf = m.getByteBuffer(0, m.getSize()).order(ByteOrder.nativeOrder());
        FloatBuffer fb = buf.asFloatBuffer();
        fb.put(MAGIC).flip();
        assertEquals("Int not written to memory", MAGIC,
                m.getFloat(0));
    }
    public void testDoubleBufferPut() {
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.