Compares the checksum located at buf[offset] with the current checksum.
@return true if the checksum matches and false otherwise.
484021
public boolean compare( byte buf[], int offset ) {
     if ( size == 4 ) {
       int checksum = ( (buf[offset+0] & 0xff) << 24 ) | 
                      ( (buf[offset+1] & 0xff) << 16 ) |
                      ( (buf[offset+2] & 0xff) << 8 )  |
                      ( (buf[offset+3] & 0xff) );
       return checksum == (int) summer.getValue();
     }
     return size == 0;
   }
313675
private void checkSubArray(byte[] test, byte[] data, int offset) {
    Preconditions.checkArgument(data.length >= test.length + offset);
    for (int i = 0; i < test.length; i++) {
      Preconditions.checkArgument(test[i] == data[i + offset]);
    }
  }
798180
private boolean compareChars(byte[] chars, int pos) {
        for (int i = 0; i < len; i++) {
            if (differentChars((char) this.chars[i + this.pos], (char) chars[i + pos])) return false;
        }
        return true;
    }
673177
private boolean checkBuffer(long offset) throws IOException {
    if (offset - bufferOffset < 0 || offset - bufferOffset >= currentBufferSize) {
      // the given offset is not contained in the buffer
      bufferOffset = offset;
      int index = 0;
      input.seek(offset);
      try {
        //input.read(buffer, 0, maxBufferSize);
        for (long pos = offset; pos < offset + maxBufferSize; pos++) {
          int ch = input.read();
          if (ch > -1) {
            buffer[index] = (byte)ch;
            index++;
          }
        }
      } catch (IOException ex) {
        // not possible
        ex.printStackTrace();
      }
      currentBufferSize = index;
      return true;
    }
    return false;
  }
26074
private boolean matchByte(final ByteBuffer bbuf) throws IOException {
		final byte b = bbuf.get(0);
		return b == getContent().charAt(0);
	}
1352207
private void verifyChunks( byte[] dataBuf, int dataOff, int len, 
                             byte[] checksumBuf, int checksumOff,
                             int firstChunkOffset, int packetVersion) 
                             throws IOException {
    int chunkOffset = firstChunkOffset;
    while (len > 0) {
      int chunkLen = Math.min(len, bytesPerChecksum - chunkOffset);
      chunkOffset = 0;
      
      checksum.update(dataBuf, dataOff, chunkLen);
      dataOff += chunkLen;

      boolean checksumCorrect;
      if (packetVersion == DataTransferProtocol.PACKET_VERSION_CHECKSUM_FIRST) {
        checksumCorrect = checksum.compare(checksumBuf, checksumOff);
        checksumOff += checksumSize;
      } else {
        // Expect packetVersion == DataTransferProtocol.PACKET_VERSION_CHECKSUM_INLINE
        checksumCorrect = checksum.compare(dataBuf, dataOff);
        dataOff += checksumSize;
      }

      if (!checksumCorrect) {
        if (srcDataNode != null) {
          try {
            LOG.info("report corrupt block " + block + " from datanode " +
                      srcDataNode + " to namenode");
            LocatedBlock lb = new LocatedBlock(block, 
                                            new DatanodeInfo[] {srcDataNode});
            datanode.reportBadBlocks(namespaceId, new LocatedBlock[] {lb});
          } catch (IOException e) {
            LOG.warn("Failed to report bad block " + block + 
                      " from datanode " + srcDataNode + " to namenode");
          }
        }
        throw new IOException("Unexpected checksum mismatch " + 
                              "while writing " + block + " from " + inAddr);
      }

      checksum.reset();
      len -= chunkLen;
    }
  }
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;
  }
718995
public static final long cheesyBufferCheckSum(ByteBuffer buffer) {
        final int mypos = buffer.position();
        buffer.position(0);
        long checksum = 0;
        if (buffer.hasArray()) {
            final byte bytes[] = buffer.array();
            final int end = buffer.arrayOffset() + mypos;
            for (int ii = buffer.arrayOffset(); ii < end; ii++) {
                checksum += bytes[ii];
            }
        } else {
            for (int ii = 0; ii < mypos; ii++) {
                checksum += buffer.get();
            }
        }
        buffer.position(mypos);
        return checksum;
    }
1064349
public boolean check(ByteBuffer data)
    {
        assert (data != null);
        int size = data.limit();
        //  This function is on critical path. It deliberately doesn't use
        //  recursion to get a bit better performance.
        Trie current = this;
        int start = 0;
        while (true) {
            //  We've found a corresponding subscription!
            if (current.refcnt > 0) {
                return true;
            }

            //  We've checked all the data and haven't found matching subscription.
            if (size == 0) {
                return false;
            }

            //  If there's no corresponding slot for the first character
            //  of the prefix, the message does not match.
            byte c = data.get(start);
            if (c < current.min || c >= current.min + current.count) {
                return false;
            }

            //  Move to the next character.
            if (current.count == 1) {
                current = current.next[0];
            }
            else {
                current = current.next[c - current.min];
                if (current == null) {
                    return false;
                }
            }
            start++;
            size--;
        }
    }
315588
boolean isBetterThanOrEqualTo(State other) {
    int newModeBitCount = this.bitCount + (HighLevelEncoder.LATCH_TABLE[this.mode][other.mode] >> 16);
    if (this.binaryShiftByteCount < other.binaryShiftByteCount) {
      // add additional B/S encoding cost of other, if any
      newModeBitCount += calculateBinaryShiftCost(other) - calculateBinaryShiftCost(this);
    } else if (this.binaryShiftByteCount > other.binaryShiftByteCount && other.binaryShiftByteCount > 0) {
      // maximum possible additional cost (we end up exceeding the 31 byte boundary and other state can stay beneath it)
      newModeBitCount += 10; 
    }
    return newModeBitCount <= other.bitCount;
  }
266337
def check
      sync

      return false unless check_spaces
      return false unless check_entries

      expected_size = address_to_offset(@total_entries + @total_spaces + 1)
      actual_size = @f.size
      if actual_size != expected_size
        PEROBS.log.error "Size mismatch in EquiBlobsFile #{@file_name}. " +
          "Expected #{expected_size} bytes but found #{actual_size} bytes."
        return false
      end

      true
    end
383460
public boolean checkSuExists() {
        Process process = null;
        try {
            process = Runtime.getRuntime().exec(new String[] { "which", BINARY_SU });
            BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
            return in.readLine() != null;
        } catch (Throwable t) {
            return false;
        } finally {
            if (process != null) process.destroy();
        }
    }
97558
function arrayBufferEquals(ab1, ab2) {
    if (ab1.byteLength !== ab2.byteLength) {
        return false;
    }
    var arr1 = new Uint8Array(ab1);
    var arr2 = new Uint8Array(ab2);
    for (var i = 0, len = arr1.length; i < len; i++) {
        if (arr1[i] !== arr2[i]) {
            return false;
        }
    }
    return true;
}
731321
def compute_checksum(&block)
      crc = CRC.new
      # Have to read this first because it might change the seek position.
      file_size = header.file_size
      @io.seek(8, IO::SEEK_SET)
      pos = 8
      length = 4096-8
      buf = nil
      while true
        buf = @io.read(length, buf)
        break if !buf
        crc.update(buf)
        pos += buf.size
        block.call(pos) if block
        length = 4096
      end
      crc.crc
    end
823490
def _validate_checksum(self, buffer):
        
        self._log.debug("Validating the buffer")
        if len(buffer) == 0:
            self._log.debug("Buffer was empty")
            if self._conn.isOpen():
                self._log.debug('Closing connection')
                self._conn.close()
            return False
        p0 = hex2int(buffer[0])
        p1 = hex2int(buffer[1])
        checksum = sum([hex2int(c) for c in buffer[:35]]) & 0xFF
        p35 = hex2int(buffer[35])
        if p0 != 165 or p1 != 150 or p35 != checksum:
            self._log.debug("Buffer checksum was not valid")
            return False
        return True
939758
private void verifyChunkedSums(
      byte[] data, int dataOff, int dataLen,
      byte[] checksums, int checksumsOff, String fileName,
      long basePos) throws ChecksumException {
    
    int remaining = dataLen;
    int dataPos = 0;
    while (remaining > 0) {
      int n = Math.min(remaining, bytesPerChecksum);
      
      summer.reset();
      summer.update(data, dataOff + dataPos, n);
      dataPos += n;
      remaining -= n;
      
      int calculated = (int)summer.getValue();
      int stored = (checksums[checksumsOff] << 24 & 0xff000000) |
        (checksums[checksumsOff + 1] << 16 & 0xff0000) |
        (checksums[checksumsOff + 2] << 8 & 0xff00) |
        checksums[checksumsOff + 3] & 0xff;
      checksumsOff += 4;
      if (calculated != stored) {
        long errPos = basePos + dataPos - n;
        throw new ChecksumException(
            "Checksum error: "+ fileName + " at "+ errPos +
            " exp: " + stored + " got: " + calculated, errPos);
      }
    }
  }
445030
private static boolean isAPortOffset(int offset) {
    return (offset == STANDARD_ASCII_PORT_OFFSET)
                   || (offset == STANDARD_HTTP_PORT_OFFSET)
                   || (offset == STANDARD_SERVLET_PORT_OFFSET)
                   || (offset == STANDARD_CFASL_PORT_OFFSET);
  }