//  Search for old log file, then apply all committed operation,
      // finally cleans it.
      File logFilePN = new File(dir, "log");
      if ((logFilePN.exists()) && (logFilePN.length() > 0)) {
        logFile = new RandomAccessFile(logFilePN, "r");
        try {
          int optype = logFile.read();
          while (optype == Operation.COMMIT) {
            String dirName;
            String name;
            optype = logFile.read();
 
            while ((optype == Operation.CREATE) ||
                   (optype == Operation.SAVE) ||
                   (optype == Operation.DELETE)) {
              //  Gets all operations of one committed transaction then
              // adds them to specified log.
              dirName = logFile.readUTF();
              if (dirName.length() == 0) dirName = null;
              name = logFile.readUTF();
              Object key = OperationKey.newKey(dirName, name);
              if (Debug.debug && logmon.isLoggable(BasicLevel.DEBUG))
                logmon.log(BasicLevel.DEBUG,
                           "NTransaction.init(), OPERATION=" + optype + ", " + name);
              Operation op = null;
              if ((optype == Operation.SAVE) || (optype == Operation.CREATE)) {
                byte buf[] = new byte[logFile.readInt()];
                logFile.readFully(buf);
                op = Operation.alloc(optype, dirName, name, buf);
                Operation old = (Operation) log.put(key, op);
                if (old != null) old.free();
              } else {
                // Operation.DELETE
                op = Operation.alloc(optype, dirName, name);
                Operation old = (Operation) log.put(key, op);
                if (old != null) {
                  if (old.type == Operation.CREATE) op.type = Operation.NOOP;
                  old.free();
                }
              }
              
              optype = logFile.read();
            }
            if (Debug.debug && logmon.isLoggable(BasicLevel.DEBUG))
              logmon.log(BasicLevel.DEBUG,
                         "NTransaction.init(), COMMIT=" + optype);
          }
          if (Debug.debug && logmon.isLoggable(BasicLevel.DEBUG))
            logmon.log(BasicLevel.DEBUG,
                       "NTransaction.init(), END=" + optype + ", " +
                       logFile.getFilePointer());
          if (optype != Operation.END)
            throw new IOException("Corrupted transaction log");
        } catch (IOException exc) {
          throw exc;
        } finally {
          logFile.close();
        }
        logFile = new RandomAccessFile(logFilePN, mode);
        garbage();
      } else {
        logFile = new RandomAccessFile(logFilePN, mode);
        logFile.setLength(MaxLogFileSize);
        current = 1;
        // Cleans log file
        logFile.seek(0);