code: public boolean validate(SharedTorrent torrent, Piece piece) throws IOException {
  
      logger.trace("Validating {}...", this);
  
      // TODO: remove cast to int when large ByteBuffer support is
      // implemented in Java.
      byte[] pieceBytes = data.array();
      final byte[] calculatedHash = TorrentUtils.calculateSha1Hash(pieceBytes);
      this.valid = Arrays.equals(calculatedHash, this.hash);
      logger.trace("validating result of piece {} is {}", this.index, this.valid);
  
      return this.isValid();
    }
docs: Validates this piece.
  
  @return Returns true if this piece, as stored in the underlying byte
  storage, is valid, i.e. its SHA1 sum matches the one from the torrent
  meta-info.