當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。