Java Code Examples for com.google.common.primitives.UnsignedInts#toLong()

The following examples show how to use com.google.common.primitives.UnsignedInts#toLong() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JoH.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
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();
}
 
Example 2
Source File: JoH.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
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();
}
 
Example 3
Source File: JoH.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
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();
}
 
Example 4
Source File: JoH.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
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();
}
 
Example 5
Source File: Zip.java    From turbine with Apache License 2.0 5 votes vote down vote up
/** 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));
  }
}
 
Example 6
Source File: Zip.java    From turbine with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example 7
Source File: HashCode.java    From codebuff with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public long padToLong() {
  return UnsignedInts.toLong(hash);
}
 
Example 8
Source File: HashCode.java    From codebuff with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public long padToLong() {
  return UnsignedInts.toLong(hash);
}
 
Example 9
Source File: HashCode.java    From codebuff with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public long padToLong() {
  return UnsignedInts.toLong(hash);
}
 
Example 10
Source File: HashCode.java    From codebuff with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public long padToLong() {
  return UnsignedInts.toLong(hash);
}
 
Example 11
Source File: HashCode.java    From codebuff with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public long padToLong() {
  return UnsignedInts.toLong(hash);
}
 
Example 12
Source File: Stat.java    From riiablo with Apache License 2.0 4 votes vote down vote up
public long toLong() {
  return UnsignedInts.toLong(val);
}
 
Example 13
Source File: HprofParser.java    From haha with Apache License 2.0 4 votes vote down vote up
private long readUnsignedInt() throws IOException {
    return UnsignedInts.toLong(mInput.readInt());
}
 
Example 14
Source File: StrictBGPPeerRegistry.java    From bgpcep with Eclipse Public License 1.0 4 votes vote down vote up
private static long toLong(final Ipv4Address from) {
    final int i = InetAddresses.coerceToInteger(InetAddresses.forString(from.getValue()));
    return UnsignedInts.toLong(i);
}
 
Example 15
Source File: IntOption.java    From dhcp4j with Apache License 2.0 4 votes vote down vote up
@Nonnegative
public long getIntValue() {
    return UnsignedInts.toLong(Ints.fromByteArray(getData()));
}
 
Example 16
Source File: IntOption.java    From dhcp4j with Apache License 2.0 4 votes vote down vote up
@Nonnegative
public long getIntValue() {
    return UnsignedInts.toLong(Ints.fromByteArray(getData()));
}