当前位置: 首页>>代码示例>>Java>>正文


Java ByteBuffer.putDouble方法代码示例

本文整理汇总了Java中java.nio.ByteBuffer.putDouble方法的典型用法代码示例。如果您正苦于以下问题:Java ByteBuffer.putDouble方法的具体用法?Java ByteBuffer.putDouble怎么用?Java ByteBuffer.putDouble使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.nio.ByteBuffer的用法示例。


在下文中一共展示了ByteBuffer.putDouble方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: unalignedWriteSnippet

import java.nio.ByteBuffer; //导入方法依赖的package包/类
byte[] unalignedWriteSnippet(byte a, short b, int c, long d, double e, float f) {
    byte[] ret = new byte[27];
    ByteBuffer buffer = makeDirect(27, byteOrder);

    buffer.put(a);
    buffer.putShort(b);
    buffer.putInt(c);
    buffer.putLong(d);
    buffer.putDouble(e);
    buffer.putFloat(f);

    buffer.position(0);
    buffer.get(ret);

    return ret;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:DirectByteBufferTest.java

示例2: toBytes

import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
 * This method serialize the metric sample using a simple protocol.
 * 1 byte  - version
 * 4 bytes - brokerId
 * 8 bytes - CPU Utilization
 * 8 bytes - DISK Utilization
 * 8 bytes - Network Inbound Utilization
 * 8 bytes - Network Outbound Utilization.
 * 8 bytes - Produce Request Rate
 * 8 bytes - Fetch Request Rate
 * 8 bytes - Messages In Per Sec
 * 8 bytes - Replication Bytes In Per Sec
 * 8 bytes - Replication Bytes Out Per Sec
 * 8 bytes - Sample time
 * 4 bytes - partition id
 * N bytes - topic string bytes
 */
public byte[] toBytes() {
  byte[] topicStringBytes = _tp.topic().getBytes(UTF_8);
  // Allocate memory:
  ByteBuffer buffer = ByteBuffer.allocate(89 + topicStringBytes.length);
  buffer.put(CURRENT_VERSION);
  buffer.putInt(_brokerId);
  buffer.putDouble(_metrics.get(Resource.CPU));
  buffer.putDouble(_metrics.get(Resource.DISK));
  buffer.putDouble(_metrics.get(Resource.NW_IN));
  buffer.putDouble(_metrics.get(Resource.NW_OUT));
  buffer.putDouble(_produceRequestRate);
  buffer.putDouble(_fetchRequestRate);
  buffer.putDouble(_messagesInPerSec);
  buffer.putDouble(_replicationBytesInPerSec);
  buffer.putDouble(_replicationBytesOutPerSec);
  buffer.putLong(_sampleTime);
  buffer.putInt(_tp.partition());
  buffer.put(topicStringBytes);
  return buffer.array();
}
 
开发者ID:linkedin,项目名称:cruise-control,代码行数:38,代码来源:PartitionMetricSample.java

示例3: toBuffer

import java.nio.ByteBuffer; //导入方法依赖的package包/类
public ByteBuffer toBuffer(int headerPos) {
  byte[] topic = topic().getBytes(StandardCharsets.UTF_8);
  ByteBuffer buffer = ByteBuffer.allocate(headerPos + 1 /* version */ + 1 /* metric type */ +
                                              Long.BYTES /* time */ + Integer.BYTES /* broker id */ +
                                              Integer.BYTES /* topic length */ + topic.length /* topic */ +
                                              Integer.BYTES /* partition */ + Double.BYTES /* value */);
  buffer.position(headerPos);
  buffer.put(METRIC_VERSION);
  buffer.put(metricType().id());
  buffer.putLong(time());
  buffer.putInt(brokerId());
  buffer.putInt(topic.length);
  buffer.put(topic);
  buffer.putInt(_partition);
  buffer.putDouble(value());
  return buffer;
}
 
开发者ID:linkedin,项目名称:cruise-control,代码行数:18,代码来源:PartitionMetric.java

示例4: copyDoubles

import java.nio.ByteBuffer; //导入方法依赖的package包/类
private static boolean copyDoubles(double[] data, ByteBuffer targetBuffer, SerializeState state) {
  int totalBytes = state.getTotalBytes();
  int remainingCapacity = targetBuffer.remaining();
  int bytesCopied = state.getBytesCopied();

  int remainingToCopy = data.length - bytesCopied / 8;
  int canCopy = (remainingCapacity > remainingToCopy ? remainingToCopy : remainingCapacity) / 8;
  // copy
  int offSet = bytesCopied / 8;
  for (int i = 0; i < canCopy; i++) {
    targetBuffer.putDouble(data[i + offSet]);
  }
  totalBytes += canCopy * 8;
  // we set the tolal bytes copied so far
  state.setTotalBytes(totalBytes);
  // we copied everything
  if (canCopy == remainingToCopy) {
    state.setData(null);
    state.setBytesCopied(0);
    return true;
  } else {
    state.setBytesCopied(canCopy * 8 + bytesCopied);
    return false;
  }
}
 
开发者ID:DSC-SPIDAL,项目名称:twister2,代码行数:26,代码来源:DataSerializer.java

示例5: handleWrite

import java.nio.ByteBuffer; //导入方法依赖的package包/类
@Override
public void handleWrite ( final Variant value )
{
    final MemoryRequestBlock block = this.block;

    if ( block == null )
    {
        throw new IllegalStateException ( "Device is not connected" );
    }

    final Double d = value.asDouble ( null );
    if ( d != null )
    {
        final ByteBuffer b = ByteBuffer.allocate ( 8 );
        b.putDouble ( d );
        block.writeData ( toAddress ( this.index ), b.array () );
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:19,代码来源:DoubleFloatAttribute.java

示例6: handleWrite

import java.nio.ByteBuffer; //导入方法依赖的package包/类
@Override
protected NotifyFuture<WriteResult> handleWrite ( final Variant value )
{
    final MemoryRequestBlock block = this.block;
    if ( block == null )
    {
        return new InstantErrorFuture<> ( new IllegalStateException ( "Device is not connected" ) );
    }

    final Double d = value.asDouble ( null );
    if ( d != null )
    {
        final ByteBuffer b = ByteBuffer.allocate ( 8 );
        b.putDouble ( d );
        block.writeData ( toAddress ( this.index ), b.array () );
        return new InstantFuture<WriteResult> ( new WriteResult () );
    }
    else
    {
        return new InstantErrorFuture<WriteResult> ( new IllegalArgumentException ( String.format ( "Can only write doubles: %s is not a double", value ) ) );
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:23,代码来源:DoubleFloatVariable.java

示例7: toDbb

import java.nio.ByteBuffer; //导入方法依赖的package包/类
public ByteBuffer toDbb(ByteBuffer res, int index) {
    res.putDouble(index + 0, m00);
    res.putDouble(index + 1, m01);
    res.putDouble(index + 2, m02);
    res.putDouble(index + 3, m03);
    res.putDouble(index + 4, m10);
    res.putDouble(index + 5, m11);
    res.putDouble(index + 6, m12);
    res.putDouble(index + 7, m13);
    res.putDouble(index + 8, m20);
    res.putDouble(index + 9, m21);
    res.putDouble(index + 10, m22);
    res.putDouble(index + 11, m23);
    res.putDouble(index + 12, m30);
    res.putDouble(index + 13, m31);
    res.putDouble(index + 14, m32);
    res.putDouble(index + 15, m33);
    return res;
}
 
开发者ID:jfcameron,项目名称:G2Dj,代码行数:20,代码来源:Mat4d.java

示例8: fillBuffer

import java.nio.ByteBuffer; //导入方法依赖的package包/类
void fillBuffer(ByteBuffer buffer, Random random) {
	byte[] bytes = new byte[20];
	random.nextBytes(bytes);
	long l = random.nextLong();
	int n = random.nextInt();
	double d = random.nextDouble();
	float f = random.nextFloat();
	buffer.clear();
	buffer.put(bytes);
	buffer.putLong(l);
	buffer.putInt(n);
	buffer.putDouble(d);
	buffer.putFloat(f);
}
 
开发者ID:michaelliao,项目名称:cryptoexchange,代码行数:15,代码来源:HashStatusTest.java

示例9: getBytes

import java.nio.ByteBuffer; //导入方法依赖的package包/类
public byte[] getBytes() {
    int size = Double.SIZE / 8 * 3 + Long.SIZE/8;
    ByteBuffer buffer = ByteBuffer.allocate(size);
    buffer.clear();
    buffer.putDouble(lat);
    buffer.putDouble(lon);
    buffer.putDouble(acc);
    buffer.putLong(gettime);
    return buffer.array();
}
 
开发者ID:jphacks,项目名称:TK_1701,代码行数:11,代码来源:LocationData.java

示例10: toByteArray

import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
 * Gets a byte array representation of this instance.
 *
 * <p><b>Note:</b> No guarantees are made regarding stability of the representation between
 * versions.
 */
public byte[] toByteArray() {
  ByteBuffer buffer = ByteBuffer.allocate(BYTES).order(ByteOrder.LITTLE_ENDIAN);
  xStats.writeTo(buffer);
  yStats.writeTo(buffer);
  buffer.putDouble(sumOfProductsOfDeltas);
  return buffer.array();
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:14,代码来源:PairedStats.java

示例11: getBytes

import java.nio.ByteBuffer; //导入方法依赖的package包/类
@Override
public byte[] getBytes() {
    ByteBuffer dataBuffer = ByteBuffer.allocate(SIZE);
    dataBuffer.put(AmfType.NUMBER.getValue());
    dataBuffer.putDouble(value);
    return dataBuffer.array();
}
 
开发者ID:wuyisheng,项目名称:libRtmp,代码行数:8,代码来源:AmfNumber.java

示例12: serialize

import java.nio.ByteBuffer; //导入方法依赖的package包/类
@Override
public void serialize(ByteBuffer buffer) {
    switch (getJavaKind()) {
        case Byte:
        case Boolean:
            buffer.put((byte) primitive);
            break;
        case Short:
            buffer.putShort((short) primitive);
            break;
        case Char:
            buffer.putChar((char) primitive);
            break;
        case Int:
            buffer.putInt(asInt());
            break;
        case Long:
            buffer.putLong(asLong());
            break;
        case Float:
            buffer.putFloat(asFloat());
            break;
        case Double:
            buffer.putDouble(asDouble());
            break;
        default:
            throw new IllegalArgumentException("unexpected kind " + getJavaKind());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:PrimitiveConstant.java

示例13: binEncode_DOUBLE_ARRAY

import java.nio.ByteBuffer; //导入方法依赖的package包/类
private ByteBuffer binEncode_DOUBLE_ARRAY(ByteBuffer buffer, Collection<Double> value) {
    ByteBuffer buf = ByteBuffer.allocate(3 + 8 * value.size());
    buf.put((byte) DataType.DOUBLE_ARRAY.typeID);
    buf.putShort((short) value.size());
    Iterator<Double> var6 = value.iterator();

    while (var6.hasNext()) {
        double item = ((Double) var6.next()).doubleValue();
        buf.putDouble(item);
    }

    return this.addData(buffer, buf.array());
}
 
开发者ID:zerosoft,项目名称:CodeBroker,代码行数:14,代码来源:DefaultSFSDataSerializer.java

示例14: alignedWriteSnippet

import java.nio.ByteBuffer; //导入方法依赖的package包/类
byte[] alignedWriteSnippet(byte a, byte b, short c, int d, long e, double f, float g) {
    byte[] ret = new byte[28];
    ByteBuffer buffer = ByteBuffer.wrap(ret).order(byteOrder);

    buffer.put(a);
    buffer.put(b);
    buffer.putShort(c);
    buffer.putInt(d);
    buffer.putLong(e);
    buffer.putDouble(f);
    buffer.putFloat(g);

    return ret;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:ByteBufferTest.java

示例15: binEncode_DOUBLE

import java.nio.ByteBuffer; //导入方法依赖的package包/类
private ByteBuffer binEncode_DOUBLE(ByteBuffer buffer, Double value) {
    ByteBuffer buf = ByteBuffer.allocate(9);
    buf.put((byte) DataType.DOUBLE.typeID);
    buf.putDouble(value.doubleValue());
    return this.addData(buffer, buf.array());
}
 
开发者ID:zerosoft,项目名称:CodeBroker,代码行数:7,代码来源:DefaultSFSDataSerializer.java


注:本文中的java.nio.ByteBuffer.putDouble方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。