Java Code Examples for java.nio.ByteBuffer.putLong()

The following are Jave code examples for showing how to use putLong() of the java.nio.ByteBuffer class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: IO   File: VolumeSection.java   View Source Code Vote up 6 votes
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;
}
 
Example 2
Project: burstcoin   File: GetMiningInfo.java   View Source Code Vote up 6 votes
@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;
}
 
Example 3
Project: openjdk-jdk10   File: DirectByteBufferTest.java   View Source Code Vote up 6 votes
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;
}
 
Example 4
Project: Sound.je   File: UUIDConverter.java   View Source Code Vote up 5 votes
/**
 * 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());
}
 
Example 5
Project: walle   File: V2SchemeSigner.java   View Source Code Vote up 5 votes
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();
}
 
Example 6
Project: burstcoin   File: AT_API_Helper.java   View Source Code Vote up 5 votes
public static byte[] getByteArray( long l ){
	ByteBuffer buffer = ByteBuffer.allocate(8);
	buffer.order(ByteOrder.LITTLE_ENDIAN);
	buffer.clear();
	buffer.putLong( l );
	return buffer.array();
}
 
Example 7
Project: burstcoin   File: Attachment.java   View Source Code Vote up 5 votes
@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);
}
 
Example 8
Project: xlight_android_native   File: WsFrameEncodingSupport.java   View Source Code Vote up 5 votes
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);
    }
}
 
Example 9
Project: sstable-adaptor   File: CounterContext.java   View Source Code Vote up 5 votes
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);
}
 
Example 10
Project: ddpush   File: ClientStatMachine.java   View Source Code Vote up 5 votes
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);
}
 
Example 11
Project: reading-and-annotate-rocketmq-3.4.6   File: MessageDecoder.java   View Source Code Vote up 5 votes
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());
}
 
Example 12
Project: creacoinj   File: Keccak.java   View Source Code Vote up 5 votes
/**
 * 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;
}
 
Example 13
Project: datatree   File: AbstractConverterSet.java   View Source Code Vote up 5 votes
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!");
	}
}
 
Example 14
Project: kafka-0.11.0.0-src-with-comment   File: DefaultRecordBatch.java   View Source Code Vote up 5 votes
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);
}
 
Example 15
Project: burstcoin   File: AT_Machine_State.java   View Source Code Vote up 5 votes
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();

}
 
Example 16
Project: WebPLP   File: LongUtils.java   View Source Code Vote up 4 votes
public static byte[] toByteArray(long longvalue)
{
	ByteBuffer buffer = ByteBuffer.allocate(Integer.BYTES).order(BIG_ENDIAN);
	buffer.putLong(longvalue);
	return buffer.array();
}
 
Example 17
Project: EasyDiameter   File: Integer64AVP.java   View Source Code Vote up 4 votes
@Override
public void encodeData(ByteBuffer buffer) {
	buffer.putLong(data);
}
 
Example 18
Project: ditb   File: HFileBlock.java   View Source Code Vote up 4 votes
public void serializeExtraInfo(ByteBuffer destination) {
  destination.put(this.fileContext.isUseHBaseChecksum() ? (byte) 1 : (byte) 0);
  destination.putLong(this.offset);
  destination.putInt(this.nextBlockOnDiskSizeWithHeader);
  destination.rewind();
}
 
Example 19
Project: pumpkindb-java   File: Uuid.java   View Source Code Vote up 4 votes
@Override public void encode(ByteBuf buffer) {
    ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
    bb.putLong(uuid.getMostSignificantBits());
    bb.putLong(uuid.getLeastSignificantBits());
    new Data(bb.array()).encode(buffer);
}
 
Example 20
Project: s-store   File: ClientResponseImpl.java   View Source Code Vote up 2 votes
/**
 * Set the client handle without deserializing it first
 * @param b
 * @param handle
 */
public static void setClientHandle(ByteBuffer b, long handle) {
    b.putLong(10, handle); // 1 + 1 + 8 = 10 
}