Java Code Examples for java.nio.ByteBuffer.asDoubleBuffer()

The following are Jave code examples for showing how to use asDoubleBuffer() of the java.nio.ByteBuffer class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: BIMplatform   File: StreamingGeometryGenerator.java   View Source Code Vote up 5 votes
private void setTransformationMatrix(VirtualObject geometryInfo, double[] transformationMatrix)
		throws DatabaseException {
	ByteBuffer byteBuffer = ByteBuffer.allocate(16 * 8);
	byteBuffer.order(ByteOrder.nativeOrder());
	DoubleBuffer asDoubleBuffer = byteBuffer.asDoubleBuffer();
	for (double d : transformationMatrix) {
		asDoubleBuffer.put(d);
	}
	geometryInfo.setAttribute(GeometryPackage.eINSTANCE.getGeometryInfo_Transformation(), byteBuffer.array());
}
 
Example 2
Project: BIMplatform   File: ColladaSerializer.java   View Source Code Vote up 5 votes
private void printMatrix(PrintWriter out, GeometryInfo geometryInfo) {
	ByteBuffer transformation = ByteBuffer.wrap(geometryInfo.getTransformation());
	transformation.order(ByteOrder.LITTLE_ENDIAN);
	DoubleBuffer doubleBuffer = transformation.asDoubleBuffer();
	// Prepare to create the transform matrix.
	double[] matrix = new double[16];
	// Add the first 16 values of the buffer.
	for (int i = 0; i < matrix.length; i++)
		matrix[i] = doubleBuffer.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.
	out.println("    <matrix>" + doubleArrayToSpaceDelimitedString(matrix) + "</matrix>");
}
 
Example 3
Project: BIMplatform   File: GeometryGenerator.java   View Source Code Vote up 5 votes
private void setTransformationMatrix(GeometryInfo geometryInfo, double[] transformationMatrix) {
	ByteBuffer byteBuffer = ByteBuffer.allocate(16 * 8);
	byteBuffer.order(ByteOrder.nativeOrder());
	DoubleBuffer asDoubleBuffer = byteBuffer.asDoubleBuffer();
	for (double f : transformationMatrix) {
		asDoubleBuffer.put(f);
	}
	geometryInfo.setTransformation(byteBuffer.array());
}
 
Example 4
Project: BIMplatform   File: BinUtils.java   View Source Code Vote up 5 votes
public static byte[] doubleToByteArray(Double inDouble) {
	byte[] bArray = new byte[8];
	ByteBuffer bBuffer = ByteBuffer.wrap(bArray);
	DoubleBuffer lBuffer = bBuffer.asDoubleBuffer();
	lBuffer.put(inDouble);
	return bArray;
}
 
Example 5
Project: OpenDA   File: ThriftBmiBridge.java   View Source Code Vote up 5 votes
private static double[] bufferToDoubleArray(ByteBuffer buffer) {
	buffer.order(ByteOrder.nativeOrder());
	DoubleBuffer doubles = buffer.asDoubleBuffer();

	if (doubles.hasArray()) {
		return doubles.array();
	} else {
		double[] resultArray = new double[doubles.capacity()];
		doubles.get(resultArray);
		return resultArray;
	}
}
 
Example 6
Project: debug   File: RT.java   View Source Code Vote up 5 votes
public static DoubleBuffer asDoubleBuffer(ByteBuffer buf) {
    DoubleBuffer buffer = buf.asDoubleBuffer();
    Buffer viewedBuffer = bufferViews.get(buf);
    if (viewedBuffer != null) {
        bufferViews.put(buffer, viewedBuffer);
    } else {
        bufferViews.put(buffer, buf);
    }
    return buffer;
}
 
Example 7
Project: monarch   File: ByteSourceJUnitTest.java   View Source Code Vote up 5 votes
@Test
public void testGetDouble() {
  ByteBuffer bb = ByteBuffer.allocate(40);
  DoubleBuffer db = bb.asDoubleBuffer();
  db.put(1.1d);
  db.put(2.2d);
  db.put(3.3d);
  db.put(4.4d);
  db.put(5.5d);
  byte[] bytes = bb.array();
  ByteSource bs = createByteSource(bytes);
  double d = bs.getDouble();
  assertEquals(1.1d, d, 0.0001);
  assertEquals(8, bs.position());
  d = bs.getDouble();
  assertEquals(2.2d, d, 0.0001);
  assertEquals(16, bs.position());
  bs.position(4 * 8);
  d = bs.getDouble();
  assertEquals(5.5d, d, 0.0001);
  assertEquals(40, bs.position());
  try {
    bs.getDouble();
    fail("expected BufferUnderflowException");
  } catch (BufferUnderflowException expected) {
  }
}
 
Example 8
Project: monarch   File: ByteSourceJUnitTest.java   View Source Code Vote up 5 votes
@Test
public void testGetDoubleInt() {
  ByteBuffer bb = ByteBuffer.allocate(40);
  DoubleBuffer db = bb.asDoubleBuffer();
  db.put(1.1d);
  db.put(2.2d);
  db.put(3.3d);
  db.put(4.4d);
  db.put(5.5d);
  byte[] bytes = bb.array();
  ByteSource bs = createByteSource(bytes);
  bs.position(3);
  double d = bs.getDouble(0);
  assertEquals(1.1d, d, 0.0001);
  assertEquals(3, bs.position());
  d = bs.getDouble(8);
  assertEquals(2.2d, d, 0.0001);
  assertEquals(3, bs.position());
  d = bs.getDouble(4 * 8);
  assertEquals(5.5d, d, 0.0001);
  assertEquals(3, bs.position());
  try {
    bs.getDouble((4 * 8) + 1);
    fail("expected IndexOutOfBoundsException");
  } catch (IndexOutOfBoundsException expected) {
  }
}
 
Example 9
Project: openjdk-jdk10   File: ByteBufferTest.java   View Source Code Vote up 5 votes
Buffer asView(ByteBuffer b, PrimitiveType t) {
    switch (t) {
        case BYTE: return b;
        case CHAR: return b.asCharBuffer();
        case SHORT: return b.asShortBuffer();
        case INT: return b.asIntBuffer();
        case LONG: return b.asLongBuffer();
        case FLOAT: return b.asFloatBuffer();
        case DOUBLE: return b.asDoubleBuffer();
    }
    throw new InternalError("Should not reach here");
}
 
Example 10
Project: OpenDA   File: WflowPythonToJavaAdapter.java   View Source Code Vote up 4 votes
public static DoubleBuffer createNativeDoubleBuffer(int numberOfElements) {
    ByteBuffer res = ByteBuffer.allocateDirect(numberOfElements * 8);
    res.order(ByteOrder.nativeOrder());
    return res.asDoubleBuffer();
}
 
Example 11
Project: OpenJSharp   File: NativeFloat64Array.java   View Source Code Vote up 4 votes
@Override
public Float64ArrayData createArrayData(final ByteBuffer nb, final int start, final int length) {
    return new Float64ArrayData(nb.asDoubleBuffer(), start, length);
}
 
Example 12
Project: openjdk-jdk10   File: NativeFloat64Array.java   View Source Code Vote up 4 votes
@Override
public Float64ArrayData createArrayData(final ByteBuffer nb, final int start, final int length) {
    return new Float64ArrayData(nb.asDoubleBuffer(), start, length);
}