本文整理汇总了Java中java.nio.ByteBuffer.putLong方法的典型用法代码示例。如果您正苦于以下问题:Java ByteBuffer.putLong方法的具体用法?Java ByteBuffer.putLong怎么用?Java ByteBuffer.putLong使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.ByteBuffer
的用法示例。
在下文中一共展示了ByteBuffer.putLong方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPartialBytes
import java.nio.ByteBuffer; //导入方法依赖的package包/类
private ByteBuffer getPartialBytes() {
ByteBuffer bytes = ByteBuffer.allocate(ADDITIONAL_SECTION_SIZE);
bytes.order(ByteOrder.LITTLE_ENDIAN);
bytes.put(mediaType.value);
bytes.put(unknown);
bytes.putInt(chunkCount);
bytes.putInt(sectorsPerChunk);
bytes.putInt(bytesPerSector);
bytes.putLong(sectorCount);
bytes.putInt(cylinders);
bytes.putInt(heads);
bytes.putInt(sectors);
bytes.putInt(mediaFlag);
bytes.putInt(palmVolumeStartSector);
bytes.put(unknown2);
bytes.putInt(smartLogStartSector);
bytes.putInt(compressionLevel);
bytes.putInt(errorGranularity);
bytes.put(unknown3);
bytes.put(fileSetGUID);
bytes.put(unknown4);
bytes.put(signature);
return bytes;
}
示例2: processRequest
import java.nio.ByteBuffer; //导入方法依赖的package包/类
@Override
JSONStreamAware processRequest(HttpServletRequest req) {
JSONObject response = new JSONObject();
response.put("height", Long.toString(Nxt.getBlockchain().getHeight() + 1));
Block lastBlock = Nxt.getBlockchain().getLastBlock();
byte[] lastGenSig = lastBlock.getGenerationSignature();
Long lastGenerator = lastBlock.getGeneratorId();
ByteBuffer buf = ByteBuffer.allocate(32 + 8);
buf.put(lastGenSig);
buf.putLong(lastGenerator);
Shabal256 md = new Shabal256();
md.update(buf.array());
byte[] newGenSig = md.digest();
response.put("generationSignature", Convert.toHexString(newGenSig));
response.put("baseTarget", Long.toString(lastBlock.getBaseTarget()));
return response;
}
示例3: 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 = makeDirect(28, byteOrder);
buffer.put(a);
buffer.put(b);
buffer.putShort(c);
buffer.putInt(d);
buffer.putLong(e);
buffer.putDouble(f);
buffer.putFloat(g);
buffer.position(0);
buffer.get(ret);
return ret;
}
示例4: toBase64
import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
* Turns a UUID in string format to a Base64 encoded version
*
* @param uuidString String representation of the uuid
* @return base64 encoded version of the uuid
* @throws IllegalArgumentException String must be a valid uuid
* @throws NullPointerException String cannot be null
*/
public static String toBase64(final String uuidString) {
if (uuidString == null) throw new NullPointerException("String cannot be null");
if (!isUUID(uuidString)) throw new IllegalArgumentException("string must be a valid uuid");
final UUID uuid = UUID.fromString(uuidString);
final ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
bb.putLong(uuid.getMostSignificantBits());
bb.putLong(uuid.getLeastSignificantBits());
return Base64.encodeBase64URLSafeString(bb.array());
}
示例5: generateApkSigningBlock
import java.nio.ByteBuffer; //导入方法依赖的package包/类
private static byte[] generateApkSigningBlock(byte[] apkSignatureSchemeV2Block) {
// FORMAT:
// uint64: size (excluding this field)
// repeated ID-value pairs:
// uint64: size (excluding this field)
// uint32: ID
// (size - 4) bytes: value
// uint64: size (same as the one above)
// uint128: magic
int resultSize =
8 // size
+ 8 + 4 + apkSignatureSchemeV2Block.length // v2Block as ID-value pair
+ 8 // size
+ 16 // magic
;
ByteBuffer result = ByteBuffer.allocate(resultSize);
result.order(ByteOrder.LITTLE_ENDIAN);
long blockSizeFieldValue = resultSize - 8;
result.putLong(blockSizeFieldValue);
long pairSizeFieldValue = 4 + apkSignatureSchemeV2Block.length;
result.putLong(pairSizeFieldValue);
result.putInt(APK_SIGNATURE_SCHEME_V2_BLOCK_ID);
result.put(apkSignatureSchemeV2Block);
result.putLong(blockSizeFieldValue);
result.put(APK_SIGNING_BLOCK_MAGIC);
return result.array();
}
示例6: getByteArray
import java.nio.ByteBuffer; //导入方法依赖的package包/类
public static byte[] getByteArray( long l ){
ByteBuffer buffer = ByteBuffer.allocate(8);
buffer.order(ByteOrder.LITTLE_ENDIAN);
buffer.clear();
buffer.putLong( l );
return buffer.array();
}
示例7: putMyBytes
import java.nio.ByteBuffer; //导入方法依赖的package包/类
@Override
void putMyBytes(ByteBuffer buffer) {
buffer.putLong(purchaseId);
buffer.putInt(goodsIsText ? goods.getData().length | Integer.MIN_VALUE : goods.getData().length);
buffer.put(goods.getData());
buffer.put(goods.getNonce());
buffer.putLong(discountNQT);
}
示例8: doEncodeLength
import java.nio.ByteBuffer; //导入方法依赖的package包/类
private static void doEncodeLength(ByteBuffer buf, int length) {
if (length < 126) {
return;
} else if (length < 65535) {
// FIXME? unsigned short
buf.putShort((short) length);
} else {
// Unsigned long (should never have a message that large! really!)
buf.putLong((long) length);
}
}
示例9: writeElementAtOffset
import java.nio.ByteBuffer; //导入方法依赖的package包/类
private void writeElementAtOffset(ByteBuffer ctx, int offset, CounterId id, long clock, long count)
{
ctx = ctx.duplicate();
ctx.position(offset);
ctx.put(id.bytes().duplicate());
ctx.putLong(clock);
ctx.putLong(count);
}
示例10: gen0x11Message
import java.nio.ByteBuffer; //导入方法依赖的package包/类
private void gen0x11Message(ClientMessage cm, ArrayList<ServerMessage> smList) throws Exception{
if(message0x11 == 0){
return;
}
byte[] data = new byte[Constant.SERVER_MESSAGE_MIN_LENGTH+8];//13 bytes
ByteBuffer bb = ByteBuffer.wrap(data);
bb.put((byte)1);//version
bb.put(cm.getData()[1]);//app id
bb.put((byte)ClientStatMachine.CMD_0x11);//cmd
bb.putShort((short)8);//length 8
bb.putLong(message0x11);
bb.flip();
ServerMessage sm = new ServerMessage(cm.getSocketAddress(), data);
smList.add(sm);
}
示例11: createMessageId
import java.nio.ByteBuffer; //导入方法依赖的package包/类
public static String createMessageId(final ByteBuffer input, final ByteBuffer addr, final long offset) {
input.flip();
input.limit(MessageDecoder.MSG_ID_LENGTH);
input.put(addr);
input.putLong(offset);
return UtilAll.bytes2string(input.array());
}
示例12: fromLane
import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
* Converts a lane value into a byte array.
*
* @param data lane value to convert
* @return converted byte array
*/
private byte[] fromLane(long data) {
ByteBuffer buffer = ByteBuffer.allocate(8);
buffer.putLong(data);
buffer.clear();
byte[] output = new byte[buffer.remaining()];
buffer.get(output, 0, output.length);
Collections.reverse(Bytes.asList(output));
return output;
}
示例13: toInetAddress
import java.nio.ByteBuffer; //导入方法依赖的package包/类
protected static final InetAddress toInetAddress(long number) {
ByteBuffer b8 = ByteBuffer.allocate(8);
b8.putLong(number);
try {
byte[] ipv4 = new byte[4];
System.arraycopy(b8.array(), 0, ipv4, 0, 4);
return InetAddress.getByAddress(ipv4);
} catch (UnknownHostException e) {
throw new IllegalArgumentException("Unable to convert \"" + number + "\" to InetAddress!");
}
}
示例14: writeHeader
import java.nio.ByteBuffer; //导入方法依赖的package包/类
static void writeHeader(ByteBuffer buffer,
long baseOffset,
int lastOffsetDelta,
int sizeInBytes,
byte magic,
CompressionType compressionType,
TimestampType timestampType,
long baseTimestamp,
long maxTimestamp,
long producerId,
short epoch,
int sequence,
boolean isTransactional,
boolean isControlBatch,
int partitionLeaderEpoch,
int numRecords) {
if (magic < RecordBatch.CURRENT_MAGIC_VALUE)
throw new IllegalArgumentException("Invalid magic value " + magic);
if (baseTimestamp < 0 && baseTimestamp != NO_TIMESTAMP)
throw new IllegalArgumentException("Invalid message timestamp " + baseTimestamp);
short attributes = computeAttributes(compressionType, timestampType, isTransactional, isControlBatch);
int position = buffer.position();
buffer.putLong(position + BASE_OFFSET_OFFSET, baseOffset);
buffer.putInt(position + LENGTH_OFFSET, sizeInBytes - LOG_OVERHEAD);
buffer.putInt(position + PARTITION_LEADER_EPOCH_OFFSET, partitionLeaderEpoch);
buffer.put(position + MAGIC_OFFSET, magic);
buffer.putShort(position + ATTRIBUTES_OFFSET, attributes);
buffer.putLong(position + BASE_TIMESTAMP_OFFSET, baseTimestamp);
buffer.putLong(position + MAX_TIMESTAMP_OFFSET, maxTimestamp);
buffer.putInt(position + LAST_OFFSET_DELTA_OFFSET, lastOffsetDelta);
buffer.putLong(position + PRODUCER_ID_OFFSET, producerId);
buffer.putShort(position + PRODUCER_EPOCH_OFFSET, epoch);
buffer.putInt(position + BASE_SEQUENCE_OFFSET, sequence);
buffer.putInt(position + RECORDS_COUNT_OFFSET, numRecords);
long crc = Crc32C.compute(buffer, ATTRIBUTES_OFFSET, sizeInBytes - ATTRIBUTES_OFFSET);
buffer.putInt(position + CRC_OFFSET, (int) crc);
buffer.position(position + RECORD_BATCH_OVERHEAD);
}
示例15: getTransactionBytes
import java.nio.ByteBuffer; //导入方法依赖的package包/类
public byte[] getTransactionBytes( )
{
ByteBuffer b = ByteBuffer.allocate( (creator.length + 8 ) * transactions.size() );
b.order( ByteOrder.LITTLE_ENDIAN );
for (AT_Transaction tx : transactions.values() )
{
b.put( tx.getRecipientId() );
b.putLong( tx.getAmount() );
}
return b.array();
}