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


Java UnsignedInts.toLong方法代码示例

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


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

示例1: handleValidStoreMsg

import com.google.common.primitives.UnsignedInts; //导入方法依赖的package包/类
@Override
protected void handleValidStoreMsg(PB.DHTTopLevelMsg.Builder topLevelResponseMsg, PB.DHTStoreValueMsg storeValueMsg) throws Exception {
  if(storeValueMsg.hasSignature()==false){
    throw new Exception("The store message "+storeValueMsg+" does not have a signature");
  }
  if(storeValueMsg.hasKey()==false){
    throw new Exception("The store message "+storeValueMsg+" does not have a key");
  }
  if(storeValueMsg.hasValue()==false){
    throw new Exception("The store message "+storeValueMsg+" does not have a value");
  }
  final byte[] key=storeValueMsg.getKey().toByteArray();
  final byte[] value=storeValueMsg.getValue().toByteArray();
  if(key.length!=32){
    throw new Exception("The store message "+storeValueMsg+" does not have a key of proper length");
  }
  if(storeValueMsg.hasNonce()==false){
    throw new Exception("Nonce is missing "+storeValueMsg);
  }
  final long nonceInMessage=UnsignedInts.toLong(storeValueMsg.getNonce());

  if(isTransactionValid(storeValueMsg)){
    storeKeyValue(key, value, nonceInMessage);
  }
  //TODO Add status message?
}
 
开发者ID:pmarches,项目名称:peercentrum-core,代码行数:27,代码来源:SelfRegistrationDHT.java

示例2: parseRecord

import com.google.common.primitives.UnsignedInts; //导入方法依赖的package包/类
protected UserEventRecord parseRecord(byte[] recordBytes, DatabasePageHeader header,
                                      long recordNumber) throws IOException {
  DataInput input = this.dataInputFactory.create(new ByteArrayInputStream(recordBytes));
  LOGGER.debug(format("Parsing user event record from bytes [%s]...", toHexString(recordBytes)));

  long systemSeconds = UnsignedInts.toLong(input.readInt());
  long displaySeconds = UnsignedInts.toLong(input.readInt());
  UserEventRecord.UserEventType eventType = UserEventRecord.UserEventType.fromId(input.readByte());
  byte eventSubType = input.readByte();
  long eventLocalTimeInSeconds = UnsignedInts.toLong(input.readInt());
  long eventValue = UnsignedInts.toLong(input.readInt());
  int actualReceiverCrc = input.readUnsignedShort();

  validateCrc(actualReceiverCrc, recordBytes);

  UserEventRecord userEventRecord = new UserEventRecord(systemSeconds, displaySeconds,
      eventLocalTimeInSeconds, eventType, eventSubType, eventValue);
  LOGGER.debug(format("Parsed UserEventRecord: [%s]", userEventRecord));

  return userEventRecord;
}
 
开发者ID:alexandre-normand,项目名称:blood-shepherd,代码行数:22,代码来源:UserEventsDatabasePagesResponse.java

示例3: getManufacturingParameters

import com.google.common.primitives.UnsignedInts; //导入方法依赖的package包/类
public List<ManufacturingParameters> getManufacturingParameters() {
  List<ManufacturingParameters> manufacturingParameters = newArrayList();
  try {
    for (DatabasePage page : getPages()) {
      ByteArrayInputStream inputStream = new ByteArrayInputStream(page.getPageData());
      DataInput input = this.dataInputFactory.create(inputStream);
      // TODO: something better than ignoring the data?
      long systemSeconds = UnsignedInts.toLong(input.readInt());
      long displaySeconds = UnsignedInts.toLong(input.readInt());

      byte[] xmlBytes = new byte[inputStream.available() - 2];
      input.readFully(xmlBytes);

      validateCrc(input.readUnsignedShort(), page.getPageData());

      XmlMapper xmlMapper = new XmlMapper();
      ManufacturingParameters parameterPage = xmlMapper.readValue(new String(xmlBytes, "UTF-8"),
              ManufacturingParameters.class);
      manufacturingParameters.add(parameterPage);
    }
    return manufacturingParameters;
  } catch (IOException e) {
    throw Throwables.propagate(e);
  }
}
 
开发者ID:alexandre-normand,项目名称:blood-shepherd,代码行数:26,代码来源:ManufacturingDataDatabasePagesResponse.java

示例4: parseRecord

import com.google.common.primitives.UnsignedInts; //导入方法依赖的package包/类
protected GlucoseReadRecord parseRecord(byte[] recordBytes, DatabasePageHeader header,
                                      long recordNumber) throws IOException {
  DataInput input = this.dataInputFactory.create(new ByteArrayInputStream(recordBytes));
  LOGGER.debug(format("Parsing glucose record from bytes [%s]", toHexString(recordBytes)));

  long systemSeconds = UnsignedInts.toLong(input.readInt());
  long displaySeconds = UnsignedInts.toLong(input.readInt());
  int glucoseValueWithFlags = input.readUnsignedShort();
  byte trendAndArrowNoise = input.readByte();
  int actualReceiverCrc = input.readUnsignedShort();

  validateCrc(actualReceiverCrc, recordBytes);

  GlucoseReadRecord glucoseReadRecord = new GlucoseReadRecord(systemSeconds, displaySeconds,
          glucoseValueWithFlags, trendAndArrowNoise, recordNumber, header.getPageNumber());
  LOGGER.debug(format("Parsed GlucoseRead: [%s]", glucoseReadRecord));

  return glucoseReadRecord;
}
 
开发者ID:alexandre-normand,项目名称:blood-shepherd,代码行数:20,代码来源:GlucoseReadsDatabasePagesResponse.java

示例5: checkChecksum

import com.google.common.primitives.UnsignedInts; //导入方法依赖的package包/类
public static boolean checkChecksum(byte[] bytes) {
    if ((bytes == null) || (bytes.length < 4)) return false;
    final CRC32 crc = new CRC32();
    crc.update(bytes, 0, bytes.length - 4);
    final long buffer_crc = UnsignedInts.toLong(ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN).getInt(bytes.length - 4));
    return buffer_crc == crc.getValue();
}
 
开发者ID:NightscoutFoundation,项目名称:xDrip,代码行数:8,代码来源:JoH.java

示例6: data

import com.google.common.primitives.UnsignedInts; //导入方法依赖的package包/类
/** The entry data. */
public byte[] data() {
  // Read the offset and variable lengths from the central directory and then try to map in the
  // data section in one shot.
  long offset = UnsignedInts.toLong(cd.getInt(cdindex + CENOFF));
  int nameLength = cd.getChar(cdindex + CENNAM);
  int extLength = cd.getChar(cdindex + CENEXT);
  int compression = cd.getChar(cdindex + CENHOW);
  switch (compression) {
    case 0x8:
      return getBytes(
          offset,
          nameLength,
          extLength,
          UnsignedInts.toLong(cd.getInt(cdindex + CENSIZ)),
          /*deflate=*/ true);
    case 0x0:
      return getBytes(
          offset,
          nameLength,
          extLength,
          UnsignedInts.toLong(cd.getInt(cdindex + CENLEN)),
          /*deflate=*/ false);
    default:
      throw new AssertionError(
          String.format("unsupported compression mode: 0x%x", compression));
  }
}
 
开发者ID:google,项目名称:turbine,代码行数:29,代码来源:Zip.java

示例7: getPartitionOwner

import com.google.common.primitives.UnsignedInts; //导入方法依赖的package包/类
@Override
public PartitionOwner getPartitionOwner(I vertexId) {
  long unsignedHashCode = UnsignedInts.toLong(vertexId.hashCode());
  // The reader can verify that unsignedHashCode of HASH_LIMIT - 1 yields
  // index of size - 1, and unsignedHashCode of 0 yields index of 0.
  int index = (int)
      ((unsignedHashCode * getPartitionOwners().size()) / HASH_LIMIT);
  return partitionOwnerList.get(index);
}
 
开发者ID:renato2099,项目名称:giraph-gora,代码行数:10,代码来源:HashRangeWorkerPartitioner.java

示例8: fromBytes

import com.google.common.primitives.UnsignedInts; //导入方法依赖的package包/类
@Override
public void fromBytes(byte[] responseAsBytes) {
  super.fromBytes(responseAsBytes);
  try {
    DataInput dataInput = dataInputFactory.create(new ByteArrayInputStream(responseAsBytes));
    this.firstPage = UnsignedInts.toLong(dataInput.readInt());
    this.lastPage = UnsignedInts.toLong(dataInput.readInt());

  } catch (IOException e) {
    throw Throwables.propagate(e);
  }
}
 
开发者ID:alexandre-normand,项目名称:blood-shepherd,代码行数:13,代码来源:PageRangeResponse.java

示例9: readPageHeader

import com.google.common.primitives.UnsignedInts; //导入方法依赖的package包/类
private DatabasePageHeader readPageHeader(byte[] headerBytes) {
  try {
    DataInput dataInput = this.dataInputFactory.create(new ByteArrayInputStream(headerBytes));

    long firstRecordIndex = UnsignedInts.toLong(dataInput.readInt());
    long numberOfRecords = UnsignedInts.toLong(dataInput.readInt());
    RecordType recordType = RecordType.fromId(dataInput.readByte());
    byte revision = dataInput.readByte();
    long pageNumber = UnsignedInts.toLong(dataInput.readInt());
    long reserved2 = UnsignedInts.toLong(dataInput.readInt());
    long reserved3 = UnsignedInts.toLong(dataInput.readInt());
    long reserved4 = UnsignedInts.toLong(dataInput.readInt());
    int crc = dataInput.readUnsignedShort();

    int expectedCrc = DecodingUtils.getCrc16(headerBytes, 0, PAGE_HEADER_SIZE - 2);

    if (crc != expectedCrc) {
      throw new IllegalStateException(format("Invalid crc, expected [%s], received [%s]",
              Integer.toHexString(expectedCrc), Integer.toHexString(crc)));
    }

    return new DatabasePageHeader(firstRecordIndex, numberOfRecords, recordType, revision,
            pageNumber, reserved2, reserved3, reserved4, crc);

  } catch (IOException e) {
    throw Throwables.propagate(e);
  }
}
 
开发者ID:alexandre-normand,项目名称:blood-shepherd,代码行数:29,代码来源:DatabasePagesResponse.java

示例10: padToLong

import com.google.common.primitives.UnsignedInts; //导入方法依赖的package包/类
@Override
public long padToLong() {
  return UnsignedInts.toLong(hash);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:5,代码来源:HashCode.java

示例11: ZipIterable

import com.google.common.primitives.UnsignedInts; //导入方法依赖的package包/类
public ZipIterable(Path path) throws IOException {
  this.path = path;
  this.chan = FileChannel.open(path, StandardOpenOption.READ);
  // Locate the EOCD
  long size = chan.size();
  if (size < ENDHDR) {
    throw new ZipException("invalid zip archive");
  }
  long eocdOffset = size - ENDHDR;
  MappedByteBuffer eocd = chan.map(MapMode.READ_ONLY, eocdOffset, ENDHDR);
  eocd.order(ByteOrder.LITTLE_ENDIAN);
  int index = 0;
  int commentSize = 0;
  if (!isSignature(eocd, 0, 5, 6)) {
    // The archive may contain a zip file comment; keep looking for the EOCD.
    long start = Math.max(0, size - ENDHDR - 0xFFFF);
    eocd = chan.map(MapMode.READ_ONLY, start, (size - start));
    eocd.order(ByteOrder.LITTLE_ENDIAN);
    index = (int) ((size - start) - ENDHDR);
    while (index > 0) {
      index--;
      eocd.position(index);
      if (isSignature(eocd, index, 5, 6)) {
        commentSize = (int) ((size - start) - ENDHDR) - index;
        eocdOffset = start + index;
        break;
      }
    }
  }
  checkSignature(path, eocd, index, 5, 6, "ENDSIG");
  int totalEntries = eocd.getChar(index + ENDTOT);
  long cdsize = UnsignedInts.toLong(eocd.getInt(index + ENDSIZ));
  int actualCommentSize = eocd.getChar(index + ENDCOM);
  if (commentSize != actualCommentSize) {
    throw new ZipException(
        String.format(
            "zip file comment length was %d, expected %d", commentSize, actualCommentSize));
  }
  // If the number of entries is 0xffff, check if the archive has a zip64 EOCD locator.
  if (totalEntries == ZIP64_MAGICCOUNT) {
    // Assume the zip64 EOCD has the usual size; we don't support zip64 extensible data sectors.
    long zip64eocdOffset = size - ENDHDR - ZIP64_LOCHDR - ZIP64_ENDHDR;
    MappedByteBuffer zip64eocd = chan.map(MapMode.READ_ONLY, zip64eocdOffset, ZIP64_ENDHDR);
    zip64eocd.order(ByteOrder.LITTLE_ENDIAN);
    // Note that zip reading is necessarily best-effort, since an archive could contain 0xFFFF
    // entries and the last entry's data could contain a ZIP64_ENDSIG. Some implementations
    // read the full EOCD records and compare them.
    if (zip64eocd.getInt(0) == ZIP64_ENDSIG) {
      cdsize = zip64eocd.getLong(ZIP64_ENDSIZ);
      eocdOffset = zip64eocdOffset;
    }
  }
  this.cd = chan.map(MapMode.READ_ONLY, eocdOffset - cdsize, cdsize);
  cd.order(ByteOrder.LITTLE_ENDIAN);
}
 
开发者ID:google,项目名称:turbine,代码行数:56,代码来源:Zip.java

示例12: readUnsignedInt

import com.google.common.primitives.UnsignedInts; //导入方法依赖的package包/类
private long readUnsignedInt() throws IOException {
    return UnsignedInts.toLong(mInput.readInt());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:4,代码来源:HprofParser.java

示例13: getEntryTime

import com.google.common.primitives.UnsignedInts; //导入方法依赖的package包/类
public long getEntryTime(ClockType clockType, TimeUnit units) {
    long entryTime = clockType == ClockType.THREAD ?
            UnsignedInts.toLong(mEntryThreadTime) : UnsignedInts.toLong(mEntryGlobalTime);
    return units.convert(entryTime, VmTraceData.getDefaultTimeUnits());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:6,代码来源:Call.java

示例14: getExitTime

import com.google.common.primitives.UnsignedInts; //导入方法依赖的package包/类
public long getExitTime(ClockType clockType, TimeUnit units) {
    long exitTime = clockType == ClockType.THREAD ?
            UnsignedInts.toLong(mExitThreadTime) : UnsignedInts.toLong(mExitGlobalTime);
    return units.convert(exitTime, VmTraceData.getDefaultTimeUnits());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:6,代码来源:Call.java

示例15: getInclusiveTime

import com.google.common.primitives.UnsignedInts; //导入方法依赖的package包/类
public long getInclusiveTime(ClockType clockType, TimeUnit units) {
    long inclusiveTime = clockType == ClockType.THREAD ?
            UnsignedInts.toLong(mExitThreadTime - mEntryThreadTime) :
            UnsignedInts.toLong(mExitGlobalTime - mEntryGlobalTime);
    return units.convert(inclusiveTime, VmTraceData.getDefaultTimeUnits());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:7,代码来源:Call.java


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