Returns a CRC of the remaining bytes in the stream.
434029
private String crc(InputStream input) {
    if (input == null)
      throw new IllegalArgumentException("input cannot be null.");
    CRC32 crc = new CRC32();
    byte[] buffer = new byte[4096];
    try {
      while (true) {
        int length = input.read(buffer);
        if (length == -1) break;
        crc.update(buffer, 0, length);
      }
    } catch (Exception ex) {
      try {
        input.close();
      } catch (Exception ignored) {
      }
    }
    return Long.toString(crc.getValue());
  }
1104381
public byte getByte(long pos) {
    checkOffsetAndCount(size, pos, 1);
    for (Segment s = head; true; s = s.next) {
      int segmentByteCount = s.limit - s.pos;
      if (pos < segmentByteCount) return s.data[s.pos + (int) pos];
      pos -= segmentByteCount;
    }
  }
791945
public static int crc16(ByteBuffer bytes) {

        int crc = 0x0000;

        while (bytes.hasRemaining()) {
            crc = doCrc(bytes.get(), crc);
        }

        return crc & 0xFFFF;
    }
1198457
def _crc16_checksum(bytes):
    
    crc = 0x0000
    polynomial = 0x1021

    for byte in bytes:
        for i in range(8):
            bit = (byte >> (7 - i) & 1) == 1
            c15 = (crc >> 15 & 1) == 1
            crc <<= 1
            if c15 ^ bit:
                crc ^= polynomial

    return crc & 0xFFFF
259512
def file_crc32(filePath):
    
    crc = 0
    with open(filePath, 'rb') as f:
        for block in _file_iter(f, _BLOCK_SIZE):
            crc = binascii.crc32(block, crc) & 0xFFFFFFFF
    return crc
1071687
static public long checksum2long(byte[] checksum, int offset, int length) {
    long crc = 0L;
    int iter = 0;
    for(int i=offset; i<offset+length; i++, iter++) {
      crc |= (0xffL&(long)checksum[i])<<((length-iter-1)*8);
    }
    return crc;
  }
990554
def file_crc32(filename, chunksize=_CHUNKSIZE):
    

    check = 0
    with open(filename, 'rb') as fd:
        for data in iter(lambda: fd.read(chunksize), ""):
            check = crc32(data, check)
    return check
218318
public static long crc32AsLong(@NotNull byte[] input) {
		CRC32 crc32 = new CRC32();
		crc32.update(input);
		return crc32.getValue();
	}
15700
def crc24(blob):
    """"""
    CRC24_INIT = 0x0B704CE
    CRC24_POLY = 0x1864CFB

    crc = CRC24_INIT
    for octet in bytearray(blob):
        crc ^= (octet << 16)
        for _ in range(8):
            crc <<= 1
            if crc & 0x1000000:
                crc ^= CRC24_POLY
    assert 0 <= crc < 0x1000000
    crc_bytes = struct.pack('>L', crc)
    assert crc_bytes[:1] == b'\x00'
    return crc_bytes[1:]
1180231
public static int crc16(byte[] bytes, int off, int len) {

        int crc = 0x0000;
        int end = off + len;

        for (int i = off; i < end; i++) {
            crc = doCrc(bytes[i], crc);
        }

        return crc & 0xFFFF;
    }
200980
public static long generate(long crc, byte []buffer, int offset, int len)
  {
    final long []crcTable = CRC_TABLE;
    
    for (int i = 0; i < len; i++) {
      final int index = ((int) crc ^ buffer[offset + i]) & 0xff;
      
      crc = (crc >>> 8) ^ crcTable[index];
    }

    return crc;
  }
1169321
def recv(self, stream, crc_mode=1, retry=16, timeout=60, delay=1, quiet=0):
        '''
        
        '''

        # initiate protocol
        error_count = 0
        char = 0
        cancel = 0
        while True:
            # first try CRC mode, if this fails,
            # fall back to checksum mode
            if error_count >= retry:
                self.abort(timeout=timeout)
                return None
            elif crc_mode and error_count < (retry / 2):
                if not self.putc(CRC):
                    time.sleep(delay)
                    error_count += 1
            else:
                crc_mode = 0
                if not self.putc(NAK):
                    time.sleep(delay)
                    error_count += 1

            char = self.getc(1, timeout)
            if not char:
                error_count += 1
                continue
            elif char == SOH:
                #crc_mode = 0
                break
            elif char == STX:
                break
            elif char == CAN:
                if cancel:
                    return None
                else:
                    cancel = 1
            else:
                error_count += 1

        # read data
        error_count = 0
        income_size = 0
        packet_size = 128
        sequence = 1
        cancel = 0
        while True:
            while True:
                if char == SOH:
                    packet_size = 128
                    break
                elif char == STX:
                    packet_size = 1024
                    break
                elif char == EOT:
                    # We received an EOT, so send an ACK and return the received
                    # data length
                    self.putc(ACK)
                    return income_size
                elif char == CAN:
                    # cancel at two consecutive cancels
                    if cancel:
                        return None
                    else:
                        cancel = 1
                else:
                    if not quiet:
                        print >> sys.stderr, \
                            'recv ERROR expected SOH/EOT, got', ord(char)
                    error_count += 1
                    if error_count >= retry:
                        self.abort()
                        return None
            # read sequence
            error_count = 0
            cancel = 0
            seq1 = ord(self.getc(1))
            seq2 = 0xff - ord(self.getc(1))
            if seq1 == sequence and seq2 == sequence:
                # sequence is ok, read packet
                # packet_size + checksum
                data = self.getc(packet_size + 1 + crc_mode, timeout)
                if crc_mode:
                    csum = (ord(data[-2]) << 8) + ord(data[-1])
                    data = data[:-2]
                    log.debug('CRC (%04x <> %04x)' % \
                        (csum, self.calc_crc(data)))
                    valid = csum == self.calc_crc(data)
                else:
                    csum = data[-1]
                    data = data[:-1]
                    log.debug('checksum (checksum(%02x <> %02x)' % \
                        (ord(csum), self.calc_checksum(data)))
                    valid = ord(csum) == self.calc_checksum(data)

                # valid data, append chunk
                if valid:
                    income_size += len(data)
                    stream.write(data)
                    self.putc(ACK)
                    sequence = (sequence + 1) % 0x100
                    char = self.getc(1, timeout)
                    continue
            else:
                # consume data
                self.getc(packet_size + 1 + crc_mode)
                self.debug('expecting sequence %d, got %d/%d' % \
                    (sequence, seq1, seq2))

            # something went wrong, request retransmission
            self.putc(NAK)
418194
private byte getFlagByte()
	{
		byte ret = 0;

		if (unsynchronisation) ret |= 0x80;
		if (extended) ret |= 0x40;
		if (experimental) ret |= 0x20;
		if (footer) ret |= 0x10;

		return ret;
	}
556647
def compute_crc(data):
    """"""
    crc16 = crcmod.predefined.Crc('modbus')
    crc16.update(data)
    return int(crc16.hexdigest(), 16)
916352
int getFileCrc(String src) throws IOException {
    checkOpen();
    return getFileCrc(dataTransferVersion,
        src, namenode, namenodeProtocolProxy, socketFactory, socketTimeout);
  }
178374
def _crc32(self, ch, crc):
        """"""
        return ((crc >> 8) & 0xffffff) ^ self.crctable[(crc ^ ord(ch)) & 0xff]
382682
public static long calculateCRC32(byte[] buffer, int offset, int length)
	{
		if (!init_done)
		{
			initialize();
		}
		for (int i = offset; i < offset + length; i++)
		{
			long tmp1 = (crc >>> 8) & 0x00FFFFFFL;
			long tmp2 = values[(int) ((crc ^ Character.toUpperCase((char) buffer[i])) & 0xff)];
			crc = tmp1 ^ tmp2;
			// System.out.println("CRC:   "+crc);
		}
		return crc;
	}