本文整理匯總了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);
}