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


Java ByteBuffer.putInt方法代码示例

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


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

示例1: iteratorRaisesOnTooSmallRecords

import java.nio.ByteBuffer; //导入方法依赖的package包/类
@Test(expected = CorruptRecordException.class)
public void iteratorRaisesOnTooSmallRecords() throws IOException {
    ByteBuffer buffer = ByteBuffer.allocate(1024);
    MemoryRecordsBuilder builder = MemoryRecords.builder(buffer, CompressionType.NONE, TimestampType.CREATE_TIME, 0L);
    builder.append(15L, "a".getBytes(), "1".getBytes());
    builder.append(20L, "b".getBytes(), "2".getBytes());
    builder.close();

    int position = buffer.position();

    builder = MemoryRecords.builder(buffer, CompressionType.NONE, TimestampType.CREATE_TIME, 2L);
    builder.append(30L, "c".getBytes(), "3".getBytes());
    builder.append(40L, "d".getBytes(), "4".getBytes());
    builder.close();

    buffer.flip();
    buffer.putInt(position + DefaultRecordBatch.LENGTH_OFFSET, 9);

    ByteBufferLogInputStream logInputStream = new ByteBufferLogInputStream(buffer, Integer.MAX_VALUE);
    assertNotNull(logInputStream.nextBatch());
    logInputStream.nextBatch();
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:23,代码来源:ByteBufferLogInputStreamTest.java

示例2: headerToBytes

import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
 * Set the header into a single byte array.
 *
 * @return a byte[] representing the header
 */
public byte[] headerToBytes()  {
    final ByteBuffer buffer = ByteBuffer.allocate(Parameters.BLOCK_HEADER_SIZE);
    // insert magic number (4 bytes)
    buffer.putInt(Parameters.MAGIC_NUMBER);
    // insert reference to previous block (32 bytes)
    buffer.put(previousBlock);
    // insert Merkle root
    buffer.put(merkleRoot); // buffer.put(getTransactionHash());
    // insert difficulty (4 bytes)
    buffer.putInt(difficulty);
    // No need to store the number of transactions in byte representation
    // insert nonce (4 bytes)
    buffer.putInt(nonce);
    return buffer.array();
}
 
开发者ID:StanIsAdmin,项目名称:CrashCoin,代码行数:21,代码来源:Block.java

示例3: writeEntries

import java.nio.ByteBuffer; //导入方法依赖的package包/类
private int writeEntries(DataOutput payload, ByteBuffer offsets, boolean shrink)
    throws IOException {
  int entryOffset = 0;
  for (int i = 0; i < entryCount; ++i) {
    Entry entry = entries.get(i);
    if (entry == null) {
      offsets.putInt(Entry.NO_ENTRY);
    } else {
      byte[] encodedEntry = entry.toByteArray(shrink);
      payload.write(encodedEntry);
      offsets.putInt(entryOffset);
      entryOffset += encodedEntry.length;
    }
  }
  entryOffset = writePad(payload, entryOffset);
  return entryOffset;
}
 
开发者ID:xyxyLiu,项目名称:AndResM,代码行数:18,代码来源:TypeChunk.java

示例4: buildSubMessageHeader

import java.nio.ByteBuffer; //导入方法依赖的package包/类
private boolean buildSubMessageHeader(MPIBuffer buffer, int length) {
    ByteBuffer byteBuffer = buffer.getByteBuffer();
    if (byteBuffer.remaining() < 4) {
      return false;
    }
//    LOG.info(String.format("%d adding sub-header pos: %d", executor, byteBuffer.position()));
    byteBuffer.putInt(length);
    return true;
  }
 
开发者ID:DSC-SPIDAL,项目名称:twister2,代码行数:10,代码来源:MPIMultiMessageSerializer.java

示例5: calculateChunkedSums

import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
 * Calculate checksums for the given data.
 * 
 * The 'mark' of the ByteBuffer parameters may be modified by this function,
 * but the position is maintained.
 * 
 * @param data the DirectByteBuffer pointing to the data to checksum.
 * @param checksums the DirectByteBuffer into which checksums will be
 *                  stored. Enough space must be available in this
 *                  buffer to put the checksums.
 */
public void calculateChunkedSums(ByteBuffer data, ByteBuffer checksums) {
  if (type.size == 0) return;
  
  if (data.hasArray() && checksums.hasArray()) {
    calculateChunkedSums(data.array(), data.arrayOffset() + data.position(), data.remaining(),
        checksums.array(), checksums.arrayOffset() + checksums.position());
    return;
  }

  if (NativeCrc32.isAvailable()) {
    NativeCrc32.calculateChunkedSums(bytesPerChecksum, type.id,
        checksums, data);
    return;
  }
  
  data.mark();
  checksums.mark();
  try {
    byte[] buf = new byte[bytesPerChecksum];
    while (data.remaining() > 0) {
      int n = Math.min(data.remaining(), bytesPerChecksum);
      data.get(buf, 0, n);
      summer.reset();
      summer.update(buf, 0, n);
      checksums.putInt((int)summer.getValue());
    }
  } finally {
    data.reset();
    checksums.reset();
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:43,代码来源:DataChecksum.java

示例6: fillPreBlank

import java.nio.ByteBuffer; //导入方法依赖的package包/类
private void fillPreBlank(final MappedFile mappedFile, final long untilWhere) {
    ByteBuffer byteBuffer = ByteBuffer.allocate(CQ_STORE_UNIT_SIZE);
    byteBuffer.putLong(0L);
    byteBuffer.putInt(Integer.MAX_VALUE);
    byteBuffer.putLong(0L);

    int until = (int) (untilWhere % this.mappedFileQueue.getMappedFileSize());
    for (int i = 0; i < until; i += CQ_STORE_UNIT_SIZE) {
        mappedFile.appendMessage(byteBuffer.array());
    }
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:12,代码来源:ConsumeQueue.java

示例7: runTest1

import java.nio.ByteBuffer; //导入方法依赖的package包/类
private void runTest1(Table hTable) throws IOException {
  // [0, 2, ?, ?, ?, ?, 0, 0, 0, 1]

  byte[] mask = new byte[] { 0, 0, 1, 1, 1, 1, 0, 0, 0, 0 };

  List<Pair<byte[], byte[]>> list = new ArrayList<Pair<byte[], byte[]>>();
  for (int i = 0; i < totalFuzzyKeys; i++) {
    byte[] fuzzyKey = new byte[10];
    ByteBuffer buf = ByteBuffer.wrap(fuzzyKey);
    buf.clear();
    buf.putShort((short) 2);
    for (int j = 0; j < 4; j++) {
      buf.put(fuzzyValue);
    }
    buf.putInt(i);

    Pair<byte[], byte[]> pair = new Pair<byte[], byte[]>(fuzzyKey, mask);
    list.add(pair);
  }

  int expectedSize = secondPartCardinality * totalFuzzyKeys * colQualifiersTotal;
  FuzzyRowFilter fuzzyRowFilter0 = new FuzzyRowFilter(list);
  // Filters are not stateless - we can't reuse them
  FuzzyRowFilter fuzzyRowFilter1 = new FuzzyRowFilter(list);

  // regular test
  runScanner(hTable, expectedSize, fuzzyRowFilter0);
  // optimized from block cache
  runScanner(hTable, expectedSize, fuzzyRowFilter1);

}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:32,代码来源:TestFuzzyRowFilterEndToEnd.java

示例8: createUniqIDBuffer

import java.nio.ByteBuffer; //导入方法依赖的package包/类
private static byte[] createUniqIDBuffer() {
    ByteBuffer buffer = ByteBuffer.allocate(4 + 2);
    long current = System.currentTimeMillis();
    if (current >= nextStartTime) {
        setStartTime(current);
    }
    buffer.position(0);
    buffer.putInt((int) (System.currentTimeMillis() - startTime));
    buffer.putShort((short) COUNTER.getAndIncrement());
    return buffer.array();
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:12,代码来源:MessageClientIDSetter.java

示例9: testPacketSizeTooBig

import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
 * Tests that packets that are too big during Kafka SASL handshake request flow
 * or the actual SASL authentication flow result in authentication failure
 * and do not cause any failures in the server.
 */
@Test
public void testPacketSizeTooBig() throws Exception {
    SecurityProtocol securityProtocol = SecurityProtocol.SASL_PLAINTEXT;
    configureMechanisms("PLAIN", Arrays.asList("PLAIN"));
    server = createEchoServer(securityProtocol);

    // Send SASL packet with large size after valid handshake request
    String node1 = "invalid1";
    createClientConnection(SecurityProtocol.PLAINTEXT, node1);
    sendHandshakeRequestReceiveResponse(node1);
    ByteBuffer buffer = ByteBuffer.allocate(1024);
    buffer.putInt(Integer.MAX_VALUE);
    buffer.put(new byte[buffer.capacity() - 4]);
    buffer.rewind();
    selector.send(new NetworkSend(node1, buffer));
    NetworkTestUtils.waitForChannelClose(selector, node1, ChannelState.READY);
    selector.close();

    // Test good connection still works
    createAndCheckClientConnection(securityProtocol, "good1");

    // Send packet with large size before handshake request
    String node2 = "invalid2";
    createClientConnection(SecurityProtocol.PLAINTEXT, node2);
    buffer.clear();
    buffer.putInt(Integer.MAX_VALUE);
    buffer.put(new byte[buffer.capacity() - 4]);
    buffer.rewind();
    selector.send(new NetworkSend(node2, buffer));
    NetworkTestUtils.waitForChannelClose(selector, node2, ChannelState.READY);
    selector.close();

    // Test good connection still works
    createAndCheckClientConnection(securityProtocol, "good2");
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:41,代码来源:SaslAuthenticatorTest.java

示例10: recordsWithInvalidRecordCount

import java.nio.ByteBuffer; //导入方法依赖的package包/类
private static DefaultRecordBatch recordsWithInvalidRecordCount(Byte magicValue, long timestamp,
                                          CompressionType codec, int invalidCount) {
    ByteBuffer buf = ByteBuffer.allocate(512);
    MemoryRecordsBuilder builder = MemoryRecords.builder(buf, magicValue, codec, TimestampType.CREATE_TIME, 0L);
    builder.appendWithOffset(0, timestamp, null, "hello".getBytes());
    builder.appendWithOffset(1, timestamp, null, "there".getBytes());
    builder.appendWithOffset(2, timestamp, null, "beautiful".getBytes());
    MemoryRecords records = builder.build();
    ByteBuffer buffer = records.buffer();
    buffer.position(0);
    buffer.putInt(RECORDS_COUNT_OFFSET, invalidCount);
    buffer.position(0);
    return new DefaultRecordBatch(buffer);
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:15,代码来源:DefaultRecordBatchTest.java

示例11: p_serializeToBuffer

import java.nio.ByteBuffer; //导入方法依赖的package包/类
@Override
protected void p_serializeToBuffer(ByteBuffer b) throws IOException {
    super.p_serializeToBuffer(b);
    b.putInt(type.getValue());
    FastSerializer.writeString(tableName, b);
    b.putInt(buffer.capacity());
    buffer.rewind();
    b.put(buffer);
}
 
开发者ID:s-store,项目名称:s-store,代码行数:10,代码来源:ConstraintFailureException.java

示例12: 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();
}
 
开发者ID:F8LEFT,项目名称:FApkSigner,代码行数:32,代码来源:V2SchemeSigner.java

示例13: encode

import java.nio.ByteBuffer; //导入方法依赖的package包/类
public static byte[] encode(Message messageExt, boolean needCompress) {
   
	int sysFlag = messageExt.getSysFlag();
    byte[] body = messageExt.getBody();
    if (needCompress && (sysFlag & COMPRESSED_FLAG) == COMPRESSED_FLAG) {
    	body = Util.compress(body, 5);
    }
    int bodyLength = body.length;
    int storeSize = messageExt.getStoreSize();
    
    ByteBuffer byteBuffer;
    if (storeSize > 0) {
        byteBuffer = ByteBuffer.allocate(storeSize);
    } else {
        storeSize = 4 // 1 TOTALSIZE
            + 4 // 2 MAGICCODE
            + 4 // 3 BODYCRC
            + 8 // 4 QUEUEID
            + 8 // 5 PHYSICALOFFSET
            + 4 // 6 SYSFLAG
            + 8 // 7 BORNTIMESTAMP
            + 8 // 8 STORETIMESTAMP
            + 4 + bodyLength // 9 BODY
            + 0;
        byteBuffer = ByteBuffer.allocate(storeSize);
    }
    
    byteBuffer.putInt(storeSize);					   		    // 1 TOTALSIZE
    byteBuffer.putInt(MESSAGE_MAGIC_CODE);		        		// 2 MAGICCODE
    byteBuffer.putInt( messageExt.getBodyCRC() );				// 3 BODYCRC
    byteBuffer.putLong( messageExt.getQueueId() );	 			// 4 QUEUEID
    byteBuffer.putLong( messageExt.getCommitLogOffset() );		// 5 PHYSICALOFFSET
    byteBuffer.putInt(sysFlag);									// 6 SYSFLAG
    byteBuffer.putLong( messageExt.getBornTimestamp() );		// 7 BORNTIMESTAMP
    byteBuffer.putLong( messageExt.getStoreTimestamp() );	    // 8 STORETIMESTAMP
    byteBuffer.putInt(bodyLength);								// 9 BODY
    byteBuffer.put( body );
    return byteBuffer.array();
}
 
开发者ID:variflight,项目名称:feeyo-redisproxy,代码行数:40,代码来源:MessageDecoder.java

示例14: writeHeader

import java.nio.ByteBuffer; //导入方法依赖的package包/类
@Override
protected void writeHeader(ByteBuffer output) {
  int entriesStart = getHeaderSize() + getOffsetSize();
  output.putInt(id);  // Write an unsigned byte with 3 bytes padding
  output.putInt(entryCount);
  output.putInt(entriesStart);
  output.put(configuration.toByteArray(false));
}
 
开发者ID:madisp,项目名称:android-chunk-utils,代码行数:9,代码来源:TypeChunk.java

示例15: sendOKHandshakeReply

import java.nio.ByteBuffer; //导入方法依赖的package包/类
private void sendOKHandshakeReply() throws IOException, ConnectionException {
  byte[] my_okHandshakeBytes = null;
  ByteBuffer my_okHandshakeBuf = null;
  if (this.isReceiver) {
    DistributionConfig cfg = owner.getConduit().config;
    ByteBuffer bb;
    if (useNIO() && TCPConduit.useDirectBuffers) {
      bb = ByteBuffer.allocateDirect(128);
    } else {
      bb = ByteBuffer.allocate(128);
    }
    bb.putInt(0); // reserve first 4 bytes for packet length
    bb.put((byte) NORMAL_MSG_TYPE);
    bb.putShort(MsgIdGenerator.NO_MSG_ID);
    bb.put(REPLY_CODE_OK_WITH_ASYNC_INFO);
    bb.putInt(cfg.getAsyncDistributionTimeout());
    bb.putInt(cfg.getAsyncQueueTimeout());
    bb.putInt(cfg.getAsyncMaxQueueSize());
    // write own product version
    Version.writeOrdinal(bb, Version.CURRENT.ordinal(), true);
    // now set the msg length into position 0
    bb.putInt(0, calcHdrSize(bb.position() - MSG_HEADER_BYTES));
    if (useNIO()) {
      my_okHandshakeBuf = bb;
      bb.flip();
    } else {
      my_okHandshakeBytes = new byte[bb.position()];
      bb.flip();
      bb.get(my_okHandshakeBytes);
    }
  } else {
    my_okHandshakeBuf = okHandshakeBuf;
    my_okHandshakeBytes = okHandshakeBytes;
  }
  if (useNIO()) {
    synchronized (my_okHandshakeBuf) {
      my_okHandshakeBuf.position(0);
      nioWriteFully(getSocket().getChannel(), my_okHandshakeBuf, false, null);
    }
  } else {
    synchronized (outLock) {
      try {
        // this.writerThread = Thread.currentThread();
        this.output.write(my_okHandshakeBytes, 0, my_okHandshakeBytes.length);
        this.output.flush();
      } finally {
        // this.writerThread = null;
      }
    }
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:52,代码来源:Connection.java


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