java.nio.ByteBuffer#asDoubleBuffer ( )源码实例Demo

下面列出了java.nio.ByteBuffer#asDoubleBuffer ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: VideoAndroid   文件: Frame.java
/** Allocates a new packed image frame in native memory where rows are 8-byte aligned. */
public Frame(int width, int height, int depth, int channels) {
    int pixelSize = Math.abs(depth) / 8;
    this.imageWidth = width;
    this.imageHeight = height;
    this.imageDepth = depth;
    this.imageChannels = channels;
    this.imageStride = ((imageWidth * imageChannels * pixelSize + 7) & ~7) / pixelSize; // 8-byte aligned
    this.image = new Buffer[1];

    ByteBuffer buffer = ByteBuffer.allocateDirect(imageHeight * imageStride * pixelSize).order(ByteOrder.nativeOrder());
    switch (imageDepth) {
        case DEPTH_BYTE:
        case DEPTH_UBYTE:  image[0] = buffer;                  break;
        case DEPTH_SHORT:
        case DEPTH_USHORT: image[0] = buffer.asShortBuffer();  break;
        case DEPTH_INT:    image[0] = buffer.asIntBuffer();    break;
        case DEPTH_LONG:   image[0] = buffer.asLongBuffer();   break;
        case DEPTH_FLOAT:  image[0] = buffer.asFloatBuffer();  break;
        case DEPTH_DOUBLE: image[0] = buffer.asDoubleBuffer(); break;
        default: throw new UnsupportedOperationException("Unsupported depth value: " + imageDepth);
    }
}
 
源代码2 项目: icafe   文件: ArrayUtils.java
public static double[] toDoubleArray(byte[] data, int offset, int len, boolean bigEndian) {
	
	ByteBuffer byteBuffer = ByteBuffer.wrap(data, offset, len);
	
	if (bigEndian) {
		byteBuffer.order(ByteOrder.BIG_ENDIAN);
	} else {
		byteBuffer.order(ByteOrder.LITTLE_ENDIAN);
	}
	
	DoubleBuffer doubleBuf = byteBuffer.asDoubleBuffer();
	double[] array = new double[doubleBuf.remaining()];
	doubleBuf.get(array);
	
	return array;
}
 
源代码3 项目: libcommon   文件: ChannelHelper.java
/**
 * ByteChannelからdouble配列を読み込む
 * @param channel
 * @return
 * @throws IOException
 */
public static double[] readDoubleArray(@NonNull final ByteChannel channel)
	throws IOException {
	
	final int n = readInt(channel);
	final ByteBuffer buf = ByteBuffer.allocate(n * 8).order(ByteOrder.BIG_ENDIAN);
	final int readBytes = channel.read(buf);
	if (readBytes != n * 8) throw new IOException();
	buf.clear();
	final DoubleBuffer result = buf.asDoubleBuffer();
	if (result.hasArray()) {
		return result.array();
	}  else {
		final double[] b = new double[n];
		result.get(b);
		return b;
	}
}
 
源代码4 项目: j2objc   文件: BufferTest.java
private void testBuffersIndependentLimit(ByteBuffer b) {
    CharBuffer c = b.asCharBuffer();
    b.limit(b.capacity()); c.put(1, (char)1);
    b.limit(0);  c.put(1, (char)1);

    b.limit(b.capacity());
    ShortBuffer s = b.asShortBuffer();
    b.limit(b.capacity()); s.put(1, (short)1);
    b.limit(0);  s.put(1, (short)1);

    b.limit(b.capacity());
    IntBuffer i = b.asIntBuffer();
    i.put(1, (int)1);
    b.limit(0);  i.put(1, (int)1);

    b.limit(b.capacity());
    LongBuffer l = b.asLongBuffer();
    l.put(1, (long)1);
    b.limit(0);  l.put(1, (long)1);

    b.limit(b.capacity());
    FloatBuffer f = b.asFloatBuffer();
    f.put(1, (float)1);
    b.limit(0);  f.put(1, (float)1);

    b.limit(b.capacity());
    DoubleBuffer d = b.asDoubleBuffer();
    d.put(1, (double)1);
    b.limit(0);  d.put(1, (double)1);
}
 
源代码5 项目: netcdf-java   文件: CdmrfWriter.java
CdmrFeatureProto.CoordAxis.Builder encodeCoordAxis(CoverageCoordAxis axis) {
  CdmrFeatureProto.CoordAxis.Builder builder = CdmrFeatureProto.CoordAxis.newBuilder();
  builder.setName(axis.getName());
  builder.setDataType(NcStream.convertDataType(axis.getDataType()));
  builder.setAxisType(convertAxisType(axis.getAxisType()));
  builder.setNvalues(axis.getNcoords());
  if (axis.getUnits() != null)
    builder.setUnits(axis.getUnits());
  if (axis.getDescription() != null)
    builder.setDescription(axis.getDescription());
  builder.setDepend(convertDependenceType(axis.getDependenceType()));
  for (String s : axis.getDependsOnList())
    builder.addDependsOn(s);

  if (axis instanceof LatLonAxis2D) {
    LatLonAxis2D latlon2D = (LatLonAxis2D) axis;
    for (int shape : latlon2D.getShape())
      builder.addShape(shape);
  }

  for (Attribute att : axis.getAttributes())
    builder.addAtts(NcStream.encodeAtt(att));

  builder.setSpacing(convertSpacing(axis.getSpacing()));
  builder.setStartValue(axis.getStartValue());
  builder.setEndValue(axis.getEndValue());
  builder.setResolution(axis.getResolution());

  if (!axis.isRegular() && axis.getNcoords() < MAX_INLINE_NVALUES) {
    double[] values = axis.getValues();
    ByteBuffer bb = ByteBuffer.allocate(8 * values.length);
    DoubleBuffer db = bb.asDoubleBuffer();
    db.put(values);
    builder.setValues(ByteString.copyFrom(bb.array()));
  }

  return builder;
}
 
源代码6 项目: MeteoInfo   文件: ArrayComplex.java
@Override
public ByteBuffer getDataAsByteBuffer() {
    ByteBuffer bb = ByteBuffer.allocate((int) (8 * getSize()));
    DoubleBuffer ib = bb.asDoubleBuffer();
    ib.put((double[]) get1DJavaArray(double.class)); // make sure its in canonical order
    return bb;
}
 
源代码7 项目: BIMserver   文件: StreamingGeometryGenerator.java
void setTransformationMatrix(VirtualObject geometryInfo, double[] transformationMatrix) throws BimserverDatabaseException {
	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());
}
 
源代码8 项目: BIMserver   文件: OfflineGeometryGenerator.java
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());
}
 
源代码9 项目: BIMserver   文件: GeometryUtils.java
public static double[] toDoubleArray(byte[] data) {
	ByteBuffer buffer = ByteBuffer.wrap(data);
	buffer.order(ByteOrder.LITTLE_ENDIAN);
	DoubleBuffer doubleBuffer = buffer.asDoubleBuffer();
	double[] result = new double[data.length / 8];
	for (int i=0; i<data.length / 8; i++) {
		result[i] = doubleBuffer.get();
	}
	return result;
}
 
源代码10 项目: OpenDA   文件: ThriftBmiBridge.java
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;
	}
}
 
源代码11 项目: BIMserver   文件: BinUtils.java
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;
}
 
源代码12 项目: BIMserver   文件: LittleEndianBinUtils.java
public static byte[] doubleToByteArray(Double inDouble) {
	byte[] bArray = new byte[8];
	ByteBuffer bBuffer = ByteBuffer.wrap(bArray);
	bBuffer.order(ByteOrder.LITTLE_ENDIAN);
	DoubleBuffer lBuffer = bBuffer.asDoubleBuffer();
	lBuffer.put(inDouble);
	return bArray;
}
 
源代码13 项目: es6draft   文件: TypedArrayFunctions.java
private static final DoubleBuffer asDoubleBuffer(TypedArrayObject typedArray) {
    ByteBuffer data = byteBuffer(typedArray);
    int byteOffset = byteOffset(typedArray);
    int byteLength = byteLength(typedArray);

    data.limit(byteOffset + byteLength).position(byteOffset);
    DoubleBuffer view = data.asDoubleBuffer();
    data.clear();
    return view;
}
 
源代码14 项目: BIMserver   文件: GeometryUtils.java
public static byte[] doubleArrayToByteArray(double[] vertices) {
	if (vertices == null) {
		return null;
	}
	ByteBuffer buffer = ByteBuffer.wrap(new byte[vertices.length * 4]);
	buffer.order(ByteOrder.LITTLE_ENDIAN);
	DoubleBuffer asDoubleBuffer = buffer.asDoubleBuffer();
	for (double d : vertices) {
		asDoubleBuffer.put(d);
	}
	return buffer.array();
}
 
源代码15 项目: netcdf-java   文件: ArrayDouble.java
public ByteBuffer getDataAsByteBuffer() {
  ByteBuffer bb = ByteBuffer.allocate((int) (8 * getSize()));
  DoubleBuffer ib = bb.asDoubleBuffer();
  ib.put((double[]) get1DJavaArray(DataType.DOUBLE)); // make sure its in canonical order
  return bb;
}
 
源代码16 项目: TencentKona-8   文件: NativeFloat64Array.java
@Override
public Float64ArrayData createArrayData(final ByteBuffer nb, final int start, final int length) {
    return new Float64ArrayData(nb.asDoubleBuffer(), start, length);
}
 
源代码17 项目: jdk8u60   文件: NativeFloat64Array.java
@Override
public Float64ArrayData createArrayData(final ByteBuffer nb, final int start, final int length) {
    return new Float64ArrayData(nb.asDoubleBuffer(), start, length);
}
 
源代码18 项目: OpenDA   文件: WflowPythonToJavaAdapter.java
public static DoubleBuffer createNativeDoubleBuffer(int numberOfElements) {
    ByteBuffer res = ByteBuffer.allocateDirect(numberOfElements * 8);
    res.order(ByteOrder.nativeOrder());
    return res.asDoubleBuffer();
}
 
源代码19 项目: hottub   文件: NativeFloat64Array.java
@Override
public Float64ArrayData createArrayData(final ByteBuffer nb, final int start, final int length) {
    return new Float64ArrayData(nb.asDoubleBuffer(), start, length);
}
 
源代码20 项目: jdk8u_nashorn   文件: NativeFloat64Array.java
@Override
public Float64ArrayData createArrayData(final ByteBuffer nb, final int start, final int length) {
    return new Float64ArrayData(nb.asDoubleBuffer(), start, length);
}