code: public long countClearBits() throws IOException {
          byte[] temp;
          long size = mFile.size();
          if (size > 1024) {
              temp = new byte[1024];
          }
          else {
              temp = new byte[(int)size];
          }
  
          long pos = 0;
          long count = 0;
          try {
              lock().acquireReadLock();
              while (true) {
                  int amt = mFile.read(pos, temp, 0, temp.length);
                  if (amt <= 0) {
                      break;
                  }
                  for (int i=0; i<amt; i++) {
                      byte val = temp[i];
                      switch (val & 15) {
                      case 0: count += 4; break;
                      case 1: case 2: case 4: case 8: count += 3; break;
                      case 3: case 5: case 6: case 9: case 10: case 12:
                          count += 2; break;
                      case 7: case 11: case 13: case 14: count++; break;
                      default: break;
                      }
                      switch ((val >> 4) & 15) {
                      case 0: count += 4; break;
                      case 1: case 2: case 4: case 8: count += 3; break;
                      case 3: case 5: case 6: case 9: case 10: case 12:
                          count += 2; break;
                      case 7: case 11: case 13: case 14: count++; break;
                      default: break;
                      }
                  }
                  pos += amt;
              }
          }
          catch (InterruptedException e) {
              throw new InterruptedIOException();
          }
          finally {
              lock().releaseLock();
          }
          return count;
      }
docs: Counts all the clear bits.