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


Java Ints.BYTES属性代码示例

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


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

示例1: prepareFakePacket

private byte[] prepareFakePacket(byte[] data, byte[] sums) throws IOException {
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  DataOutputStream dos = new DataOutputStream(baos);
  
  int packetLen = data.length + sums.length + Ints.BYTES;
  PacketHeader header = new PacketHeader(
      packetLen, OFFSET_IN_BLOCK, SEQNO, false, data.length, false);
  header.write(dos);
  
  dos.write(sums);
  dos.write(data);
  dos.flush();
  return baos.toByteArray();
}
 
开发者ID:naver,项目名称:hadoop,代码行数:14,代码来源:TestPacketReceiver.java

示例2: getSerializedByteSize

public int getSerializedByteSize() {
  return Ints.BYTES  // Size of index.
      + Byte.BYTES +  // Size of shift
      Long.BYTES * getLastDataIndex();  // Size of long valid data
}
 
开发者ID:pinterest,项目名称:yuvi,代码行数:5,代码来源:BitStream.java

示例3: doRead

private void doRead(ReadableByteChannel ch, InputStream in)
    throws IOException {
  // Each packet looks like:
  //   PLEN    HLEN      HEADER     CHECKSUMS  DATA
  //   32-bit  16-bit   <protobuf>  <variable length>
  //
  // PLEN:      Payload length
  //            = length(PLEN) + length(CHECKSUMS) + length(DATA)
  //            This length includes its own encoded length in
  //            the sum for historical reasons.
  //
  // HLEN:      Header length
  //            = length(HEADER)
  //
  // HEADER:    the actual packet header fields, encoded in protobuf
  // CHECKSUMS: the crcs for the data chunk. May be missing if
  //            checksums were not requested
  // DATA       the actual block data
  Preconditions.checkState(curHeader == null || !curHeader.isLastPacketInBlock());

  curPacketBuf.clear();
  curPacketBuf.limit(PacketHeader.PKT_LENGTHS_LEN);
  doReadFully(ch, in, curPacketBuf);
  curPacketBuf.flip();
  int payloadLen = curPacketBuf.getInt();
  
  if (payloadLen < Ints.BYTES) {
    // The "payload length" includes its own length. Therefore it
    // should never be less than 4 bytes
    throw new IOException("Invalid payload length " +
        payloadLen);
  }
  int dataPlusChecksumLen = payloadLen - Ints.BYTES;
  int headerLen = curPacketBuf.getShort();
  if (headerLen < 0) {
    throw new IOException("Invalid header length " + headerLen);
  }
  
  if (LOG.isTraceEnabled()) {
    LOG.trace("readNextPacket: dataPlusChecksumLen = " + dataPlusChecksumLen +
        " headerLen = " + headerLen);
  }
  
  // Sanity check the buffer size so we don't allocate too much memory
  // and OOME.
  int totalLen = payloadLen + headerLen;
  if (totalLen < 0 || totalLen > MAX_PACKET_SIZE) {
    throw new IOException("Incorrect value for packet payload size: " +
                          payloadLen);
  }

  // Make sure we have space for the whole packet, and
  // read it.
  reallocPacketBuf(PacketHeader.PKT_LENGTHS_LEN +
      dataPlusChecksumLen + headerLen);
  curPacketBuf.clear();
  curPacketBuf.position(PacketHeader.PKT_LENGTHS_LEN);
  curPacketBuf.limit(PacketHeader.PKT_LENGTHS_LEN +
      dataPlusChecksumLen + headerLen);
  doReadFully(ch, in, curPacketBuf);
  curPacketBuf.flip();
  curPacketBuf.position(PacketHeader.PKT_LENGTHS_LEN);

  // Extract the header from the front of the buffer (after the length prefixes)
  byte[] headerBuf = new byte[headerLen];
  curPacketBuf.get(headerBuf);
  if (curHeader == null) {
    curHeader = new PacketHeader();
  }
  curHeader.setFieldsFromData(payloadLen, headerBuf);
  
  // Compute the sub-slices of the packet
  int checksumLen = dataPlusChecksumLen - curHeader.getDataLen();
  if (checksumLen < 0) {
    throw new IOException("Invalid packet: data length in packet header " + 
        "exceeds data length received. dataPlusChecksumLen=" +
        dataPlusChecksumLen + " header: " + curHeader); 
  }
  
  reslicePacket(headerLen, checksumLen, curHeader.getDataLen());
}
 
开发者ID:naver,项目名称:hadoop,代码行数:81,代码来源:PacketReceiver.java


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