本文整理汇总了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;
}
示例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();
}
示例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;
}
示例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;
}
}
示例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 () );
}
}
示例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 ) ) );
}
}
示例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;
}
示例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);
}
示例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();
}
示例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();
}
示例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();
}
示例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());
}
}
示例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());
}
示例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;
}
示例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());
}