Tries to load the edit log file: first from 'edits.new', and if it
doesen't exist, from 'edits'.

@throws IOException If a fatal error occurred.
961755
private void openEditLog() throws IOException {
    if (editsNewFile.exists()) {
      LOG.info("Trying to load edit log from 'edits.new'");
      try {
        openInputStream(editsNewFile);
        openedFromEditsNew = true;
        return;
      } catch (IOException e) {
        LOG.info("Failed to load from 'edits.new'. Trying from 'edits'", e);
      }
    }
    
    openInputStream(editsFile);
    openedFromEditsNew = false;
    LOG.info("Edit log loaded from 'edits'");
  }
1311009
public void commit() throws IOException {
        // assures we perform the close operation only once.
        if (open.compareAndSet(true, false)) {
            // flush & close
            fout.force(true);
            fout.close();

            // if the current file exists, and append is true, then append samples and remove temp file
            // otherwise write header and move tmp file to target
            boolean exists = Files.exists(target);
            if (logger.isInfoEnabled()) {
                logger.info("Finishing recording ...... append: " + append + " exists: " + exists + " target:" + target);
            }
            if (append && exists) {
                appendSamples(target, temp);
                writeHeader(target);
                Files.delete(temp);
            } else {
                writeHeader(temp);
                Files.move(temp, target, StandardCopyOption.REPLACE_EXISTING);
            }
        }
    }
858636
public void init() throws IOException {
    if (!Files.exists(path)) {
      throw new FileNotFoundException(
          "Could not find a file under path: " + path.toAbsolutePath().toString());
    }
    if (Files.size(path) == 0) {
      throw new IllegalStateException("File size can't be zero for chunked files");
    }
    chunks = chunkFile();
    chunksInUse = new ConcurrentSkipListMap<>();
    chunksPreRead = new ConcurrentSkipListMap<>();
    chunksScheduled = new ConcurrentSkipListMap<>();
    nextChunkNum = new AtomicInteger(-1);
    if (raf != null) {
      raf.close();
    }
    execIo = MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor());
    execFinalize = Executors.newSingleThreadExecutor();
  }
438182
public void openFile() throws IOException {

        // get the import resource
        m_folder = new File(OpenCms.getSystemInfo().getAbsoluteRfsPathRelativeToWebInf(m_params.getPath()));

        // if it is a file it must be a zip-file
        if (m_folder.isFile()) {
            m_zipFile = new ZipFile(m_params.getPath());
            m_folder = null;
        }
    }
668297
private void tryReloadingEditLog() throws IOException {
    LOG.info("Trying to reload the edit log ...");
    // The roll image count is 1 after edits.new was renamed to edits
    if (rollImageCount.get() == 1) {
      try {
        LOG.info("Trying to reload the edit log from " +
            editsFile.getAbsolutePath());
        openInputStream(editsFile);
        LOG.info("Successfully reloaded the edit log from " +
            editsFile.getAbsolutePath() + ". Trying to refresh position.");
        refreshStreamPosition();
        LOG.info("Successfully refreshed stream position");
        return;
      } catch (IOException e) {
        LOG.warn("Failed to reload from " + editsFile.getAbsolutePath(), e);
      }
    }
    
    try {
      LOG.info("Trying to reload the edit log from " +
          editsNewFile.getAbsolutePath());
      openInputStream(editsNewFile);
      LOG.info("Successfully reloaded the edit log from " +
          editsNewFile.getAbsolutePath() + ". Trying to refresh position.");
      refreshStreamPosition();
      LOG.info("Successfully refreshed stream position");
      return;
    } catch (IOException e) {
      LOG.error("Failed to reload from " + editsFile.getAbsolutePath(), e);
      throw e;
    }
  }
944435
public void refresh() throws IOException
    {
        if (Files.exists(file))
        {
            fine("%s exist", file);
            writeLock.lock();
            try
            {
                finer("start update(%s)", file);
                update(file);
                finer("end update(%s)", file);
            }
            finally
            {
                writeLock.unlock();
            }
            FileTime lmt = Files.getLastModifiedTime(file);
            if (thread == null && lmt.toMillis()+expires < System.currentTimeMillis())
            {
                thread = new Thread(this, url.toString());
                thread.setDaemon(true);
                thread.start();
                fine("started thread for %s", url);
            }
        }
        else
        {
            fine("%s doesn't exist", file);
            run();
        }
    }
1095516
private void checkFail(String errorMsg) throws IOException {
    if (fsNamesys.failOnTxIdMismatch()) {
      FSEditLog.LOG.error(errorMsg);
      throw new IOException(errorMsg);
    }
    MetaRecoveryContext.editLogLoaderPrompt(errorMsg);
  }
925483
private void initNewFile() throws IOException {
    mFile = new File(PathUtils.concatPath(CommonUtils.getTmpDir(mTmpDirs), UUID.randomUUID()));
    if (mHash != null) {
      mLocalOutputStream =
          new BufferedOutputStream(new DigestOutputStream(new FileOutputStream(mFile), mHash));
    } else {
      mLocalOutputStream = new BufferedOutputStream(new FileOutputStream(mFile));
    }
    mPartitionOffset = 0;
    LOG.debug("Init new temp file @ {}", mFile.getPath());
  }
929848
public void load() throws FileNotFoundException {

        XMLObjectReader reader = null;
        try {
            this.preparePersistFile();

            File f = new File(persistFile.toString());
            if (f.exists()) {
                // we have V2 config
                loadVer2(persistFile.toString());
            } else {
                String s1 = persistFile.toString().replace("1.xml", ".xml");
                f = new File(s1);

                if (f.exists()) {
                    loadVer1(s1);
                }

                this.store();
                f.delete();
            }
        } catch (XMLStreamException ex) {
            logger.error(String.format("Failed to load the M3UA configuration file. \n%s", ex.getMessage()));
        } catch (FileNotFoundException e) {
            logger.warn(String.format("Failed to load the M3UA configuration file. \n%s", e.getMessage()));
        } catch (IOException e) {
            logger.error(String.format("Failed to load the M3UA configuration file. \n%s", e.getMessage()));
        }
    }
680713
private void fillIn() throws IOException {

		BufferedReader br = null;
		InputStream in = null;
		try {
			in = new FileInputStream( this.definitionFile.getEditedFile());
			br = new BufferedReader( new InputStreamReader( in, StandardCharsets.UTF_8 ));

			String line;
			while(( line = nextLine( br )) != null ) {

				int code = recognizeBlankLine( line, this.definitionFile.getBlocks());
				if( code == P_CODE_YES )
					continue;

				code = recognizeComment( line, this.definitionFile.getBlocks());
				if( code == P_CODE_YES )
					continue;

				code = recognizeImport( line );
				if( code == P_CODE_CANCEL )
					break;
				else if( code == P_CODE_YES )
					continue;

				code = recognizeFacet( line, br );
				if( code == P_CODE_CANCEL )
					break;
				else if( code == P_CODE_YES )
					continue;

				code = recognizeInstanceOf( line, br, null );
				if( code == P_CODE_CANCEL )
					break;
				else if( code == P_CODE_YES )
					continue;

				// "recognizeComponent" is the last attempt to identify the line.
				code = recognizeComponent( line, br );

				// So, eventually, we add the line as an unknown block.
				if( code != P_CODE_YES )
					this.definitionFile.getBlocks().add( new BlockUnknown( this.definitionFile, line ));

				// Deal with the error codes.
				// Cancel: break the loop.
				// No: try to process the next line.
				if( code == P_CODE_CANCEL )
					break;

				if( code == P_CODE_NO )
					addModelError( ErrorCode.P_UNRECOGNIZED_BLOCK );
			}

			if( line == null
					&& this.lastLineEndedWithLineBreak )
				this.definitionFile.getBlocks().add( new BlockBlank( this.definitionFile, "" ));

		} finally {
			Utils.closeQuietly( br );
			Utils.closeQuietly( in );
		}
	}
715659
File findInProgressEditsFile(long startTxId)
  throws IOException {
    File ret = findFile(NameNodeDirType.EDITS,
        getInProgressEditsFileName(startTxId));
    if (ret == null) {
      throw new IOException(
          "No edits file for txid " + startTxId + "-in progress");
    }
    return ret;
  }
980613
public void load(String filename, String separator) throws IOException, PropertiesException {
		load(new File(filename), separator);
	}
535675
private void updateInputStream() throws IOException {
    if (mInputStream != null && (mInputStream.mFile.isIncompleteLog() || !mInputStream.isDone())) {
      return;
    }

    if (mInputStream != null) {
      mInputStream.close();
      mInputStream = null;
    }
    if (mFilesToProcess.isEmpty()) {
      UfsJournalSnapshot snapshot = UfsJournalSnapshot.getSnapshot(mJournal);
      if (snapshot.getCheckpoints().isEmpty() && snapshot.getLogs().isEmpty()) {
        return;
      }

      int index = 0;
      if (!snapshot.getCheckpoints().isEmpty()) {
        UfsJournalFile checkpoint = snapshot.getLatestCheckpoint();
        if (mNextSequenceNumber < checkpoint.getEnd()) {
          String location = checkpoint.getLocation().toString();
          LOG.info("Reading checkpoint {}", location);
          mCheckpointStream = new CheckpointInputStream(
              mUfs.open(location, OpenOptions.defaults().setRecoverFailedOpen(true)));
          mNextSequenceNumber = checkpoint.getEnd();
        }
        for (; index < snapshot.getLogs().size(); index++) {
          UfsJournalFile file = snapshot.getLogs().get(index);
          if (file.getEnd() > checkpoint.getEnd()) {
            break;
          }
        }
        // index now points to the first log with mEnd > checkpoint.mEnd.
      }
      for (; index < snapshot.getLogs().size(); index++) {
        UfsJournalFile file = snapshot.getLogs().get(index);
        if ((!mReadIncompleteLog && file.isIncompleteLog())
            || mNextSequenceNumber >= file.getEnd()) {
          continue;
        }
        mFilesToProcess.add(snapshot.getLogs().get(index));
      }
    }

    if (!mFilesToProcess.isEmpty()) {
      mInputStream = new JournalInputStream(mFilesToProcess.poll());
    }
  }
1369745
private void updateStreamPosition() throws IOException {
    try {
      currentEditLogInputStreamPosition = currentEditLogInputStream
          .getPosition();
    } catch (IOException e) {
      LOG.error("Failed to get edit log file position", e);
      throw new IOException("updateStreamPosition failed");
    }
  }
127691
private void init() throws IOException {
        if (initialized.compareAndSet(false, true)) {
            log.debug("Init: {}", mode);
            // if the path is null, the consumer has been uninitialized
            if (path != null) {
                if (log.isDebugEnabled()) {
                    Path parent = path.getParent();
                    log.debug("Parent abs: {} dir: {}", parent.isAbsolute(), Files.isDirectory(parent));
                }
                if (IClientStream.MODE_APPEND.equals(mode)) {
                    if (Files.notExists(path)) {
                        throw new IOException("File to be appended doesnt exist, verify the record mode");
                    }
                    log.debug("Path: {}\nRead: {} write: {} size: {}", path, Files.isReadable(path), Files.isWritable(path), Files.size(path));
                    writer = new FLVWriter(path, true);
                } else if (IClientStream.MODE_RECORD.equals(mode)) {
                    try {
                        // delete existing file
                        if (Files.deleteIfExists(path)) {
                            log.debug("File deleted");
                        }
                        // ensure parent dirs exist
                        Files.createDirectories(path.getParent());
                        // create the file
                        path = Files.createFile(path);
                    } catch (IOException ioe) {
                        log.error("File creation error: {}", ioe);
                    }
                    if (!Files.isWritable(path)) {
                        throw new IOException("File is not writable");
                    }
                    log.debug("Path: {}\nRead: {} write: {}", path, Files.isReadable(path), Files.isWritable(path));
                    writer = new FLVWriter(path, false);
                } else {
                    try {
                        // delete existing file since we're not recording nor appending
                        if (Files.deleteIfExists(path)) {
                            log.debug("File deleted");
                        }
                    } catch (IOException ioe) {
                        log.error("File creation error: {}", ioe);
                    }
                }
            } else {
                log.warn("Consumer is uninitialized");
            }
            log.debug("Init - complete");
        }
    }
1040576
protected void init() throws IOException {
        try {
            long lwmScn = _arrayFile.getLwmScn();
            long hwmScn = _arrayFile.getHwmScn();
            if (hwmScn < lwmScn) {
                throw new IOException(_arrayFile.getAbsolutePath() + " is corrupted: lwmScn=" + lwmScn + " hwmScn=" + hwmScn);
            }

            // Initialize entry manager and process entry files on disk if any.
            _entryManager.init(lwmScn, hwmScn);

            // Load data from the array file on disk.
            loadArrayFileData();
        } catch (IOException e) {
            _entryManager.clear();
            getLogger().error(e.getMessage(), e);
            throw e;
        }
    }
497648
public void load() throws IOException {
        final File nodesDir = getNodesDir();
        final File[] subdirs = nodesDir.listFiles(new FileFilter() {
            public boolean accept(File child) {
                return child.isDirectory();
            }
        });
        final Map<String, Node> newNodes = new TreeMap<>();
        if (subdirs != null) {
            for (File subdir : subdirs) {
                try {
                    XmlFile xmlFile = new XmlFile(Jenkins.XSTREAM, new File(subdir, "config.xml"));
                    if (xmlFile.exists()) {
                        Node node = (Node) xmlFile.read();
                        newNodes.put(node.getNodeName(), node);
                    }
                } catch (IOException e) {
                    Logger.getLogger(Nodes.class.getName()).log(Level.WARNING, "could not load " + subdir, e);
                }
            }
        }
        Queue.withLock(new Runnable() {
            @Override
            public void run() {
                nodes.entrySet().removeIf(stringNodeEntry -> !(stringNodeEntry.getValue() instanceof EphemeralNode));
                nodes.putAll(newNodes);
                jenkins.updateComputerList();
                jenkins.trimLabels();
            }
        });
    }