code: public static EditLogValidation validateEditLog(EditLogInputStream in) {
      long lastPos = 0;
      long firstTxId = HdfsConstants.INVALID_TXID;
      long lastTxId = HdfsConstants.INVALID_TXID;
      long numValid = 0;
      try {
        FSEditLogOp op = null;
        while (true) {
          lastPos = in.getPosition();
          try {
            if ((op = in.readOp()) == null) {
              break;
            }
          } catch (Throwable t) {
            FSImage.LOG.warn("Caught exception after reading " + numValid +
                " ops from " + in + " while determining its valid length." +
                "Position was " + lastPos, t);
            in.resync();
            FSImage.LOG.info("After resync, position is " + in.getPosition());
            continue;
          }
          if (firstTxId == HdfsConstants.INVALID_TXID) {
            firstTxId = op.getTransactionId();
          }
          if (lastTxId == HdfsConstants.INVALID_TXID
              || op.txid > lastTxId) {
            lastTxId = op.getTransactionId();
          } else {
            FSImage.LOG.error("Out of order txid found. Found " + op.txid
                              + ", expected " + (lastTxId + 1));
          }
          numValid++;
        }
      } catch (Throwable t) {
        // Catch Throwable and not just IOE, since bad edits may generate
        // NumberFormatExceptions, AssertionErrors, OutOfMemoryErrors, etc.
        FSImage.LOG.debug("Caught exception after reading " + numValid +
            " ops from " + in + " while determining its valid length.", t);
      }
      return new EditLogValidation(lastPos, firstTxId, lastTxId, false);
    }
docs: Return the number of valid transactions in the stream. If the stream is
  truncated during the header, returns a value indicating that there are
  0 valid transactions. This reads through the stream but does not close
  it.
  @throws IOException if the stream cannot be read due to an IO error (eg
  if the log does not exist)