本文整理汇总了Java中java.nio.ByteBuffer.asDoubleBuffer方法的典型用法代码示例。如果您正苦于以下问题:Java ByteBuffer.asDoubleBuffer方法的具体用法?Java ByteBuffer.asDoubleBuffer怎么用?Java ByteBuffer.asDoubleBuffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.ByteBuffer
的用法示例。
在下文中一共展示了ByteBuffer.asDoubleBuffer方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setTransformationMatrix
import java.nio.ByteBuffer; //导入方法依赖的package包/类
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());
}
示例2: printMatrix
import java.nio.ByteBuffer; //导入方法依赖的package包/类
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>");
}
示例3: setTransformationMatrix
import java.nio.ByteBuffer; //导入方法依赖的package包/类
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());
}
示例4: doubleToByteArray
import java.nio.ByteBuffer; //导入方法依赖的package包/类
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;
}
示例5: bufferToDoubleArray
import java.nio.ByteBuffer; //导入方法依赖的package包/类
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;
}
}
示例6: asDoubleBuffer
import java.nio.ByteBuffer; //导入方法依赖的package包/类
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;
}
示例7: testGetDouble
import java.nio.ByteBuffer; //导入方法依赖的package包/类
@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) {
}
}
示例8: testGetDoubleInt
import java.nio.ByteBuffer; //导入方法依赖的package包/类
@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) {
}
}
示例9: asView
import java.nio.ByteBuffer; //导入方法依赖的package包/类
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");
}
示例10: createNativeDoubleBuffer
import java.nio.ByteBuffer; //导入方法依赖的package包/类
public static DoubleBuffer createNativeDoubleBuffer(int numberOfElements) {
ByteBuffer res = ByteBuffer.allocateDirect(numberOfElements * 8);
res.order(ByteOrder.nativeOrder());
return res.asDoubleBuffer();
}
示例11: createArrayData
import java.nio.ByteBuffer; //导入方法依赖的package包/类
@Override
public Float64ArrayData createArrayData(final ByteBuffer nb, final int start, final int length) {
return new Float64ArrayData(nb.asDoubleBuffer(), start, length);
}