當前位置: 首頁>>代碼示例>>Java>>正文


Java FileUtil.replaceFile方法代碼示例

本文整理匯總了Java中org.apache.hadoop.fs.FileUtil.replaceFile方法的典型用法代碼示例。如果您正苦於以下問題:Java FileUtil.replaceFile方法的具體用法?Java FileUtil.replaceFile怎麽用?Java FileUtil.replaceFile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.hadoop.fs.FileUtil的用法示例。


在下文中一共展示了FileUtil.replaceFile方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: completeHalfDoneAcceptRecovery

import org.apache.hadoop.fs.FileUtil; //導入方法依賴的package包/類
/**
 * In the case the node crashes in between downloading a log segment
 * and persisting the associated paxos recovery data, the log segment
 * will be left in its temporary location on disk. Given the paxos data,
 * we can check if this was indeed the case, and "roll forward"
 * the atomic operation.
 * 
 * See the inline comments in
 * {@link #acceptRecovery(RequestInfo, SegmentStateProto, URL)} for more
 * details.
 *
 * @throws IOException if the temporary file is unable to be renamed into
 * place
 */
private void completeHalfDoneAcceptRecovery(
    PersistedRecoveryPaxosData paxosData) throws IOException {
  if (paxosData == null) {
    return;
  }

  long segmentId = paxosData.getSegmentState().getStartTxId();
  long epoch = paxosData.getAcceptedInEpoch();
  
  File tmp = storage.getSyncLogTemporaryFile(segmentId, epoch);
  
  if (tmp.exists()) {
    File dst = storage.getInProgressEditLog(segmentId);
    LOG.info("Rolling forward previously half-completed synchronization: " +
        tmp + " -> " + dst);
    FileUtil.replaceFile(tmp, dst);
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:33,代碼來源:Journal.java

示例2: unlinkFile

import org.apache.hadoop.fs.FileUtil; //導入方法依賴的package包/類
/**
 * Copy specified file into a temporary file. Then rename the
 * temporary file to the original name. This will cause any
 * hardlinks to the original file to be removed. The temporary
 * files are created in the same directory. The temporary files will
 * be recovered (especially on Windows) on datanode restart.
 */
private void unlinkFile(File file, Block b) throws IOException {
  File tmpFile = DatanodeUtil.createTmpFile(b, DatanodeUtil.getUnlinkTmpFile(file));
  try {
    FileInputStream in = new FileInputStream(file);
    try {
      FileOutputStream out = new FileOutputStream(tmpFile);
      try {
        IOUtils.copyBytes(in, out, 16*1024);
      } finally {
        out.close();
      }
    } finally {
      in.close();
    }
    if (file.length() != tmpFile.length()) {
      throw new IOException("Copy of file " + file + " size " + file.length()+
                            " into file " + tmpFile +
                            " resulted in a size of " + tmpFile.length());
    }
    FileUtil.replaceFile(tmpFile, file);
  } catch (IOException e) {
    boolean done = tmpFile.delete();
    if (!done) {
      DataNode.LOG.info("detachFile failed to delete temporary file " +
                        tmpFile);
    }
    throw e;
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:37,代碼來源:ReplicaInfo.java


注:本文中的org.apache.hadoop.fs.FileUtil.replaceFile方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。