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


Java Files.createLink方法代碼示例

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


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

示例1: testEqual_links

import java.nio.file.Files; //導入方法依賴的package包/類
public void testEqual_links() throws IOException {
  try (FileSystem fs = Jimfs.newFileSystem(Configuration.unix())) {
    Path fooPath = fs.getPath("foo");
    MoreFiles.asCharSink(fooPath, UTF_8).write("foo");

    Path fooSymlink = fs.getPath("symlink");
    Files.createSymbolicLink(fooSymlink, fooPath);

    Path fooHardlink = fs.getPath("hardlink");
    Files.createLink(fooHardlink, fooPath);

    assertThat(MoreFiles.equal(fooPath, fooSymlink)).isTrue();
    assertThat(MoreFiles.equal(fooPath, fooHardlink)).isTrue();
    assertThat(MoreFiles.equal(fooSymlink, fooHardlink)).isTrue();
  }
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:17,代碼來源:MoreFilesTest.java

示例2: swizzle

import java.nio.file.Files; //導入方法依賴的package包/類
/**
 * ******** Transaction support **********
 */

@Override
public void swizzle(long oid) {

    Path shadow_location = transactionsPath(oid);
    if (!shadow_location.toFile().exists()) {
        ErrorHandling.error("******* Transaction error:Shadow file does not exist *******");
    }
    Path primary_location = filePath(oid);
    if (!primary_location.toFile().exists()) {
        ErrorHandling.error("******* Transaction error: Primary file does not exist *******");
    }
    if (!primary_location.toFile().delete()) {
        ErrorHandling.error("******* Transaction error: Primary file cannot be deleted *******");
    }
    try {
        Files.createLink(primary_location, shadow_location);
    } catch (IOException e) {
        ErrorHandling.error("******* Transaction error: Primary file cannot be linked from shadow *******");
    }
    if (!shadow_location.toFile().delete()) {
        ErrorHandling.error("******* Transaction error: Shadow file cannot be deleted *******");
    }
}
 
開發者ID:stacs-srg,項目名稱:storr,代碼行數:28,代碼來源:DirectoryBackedBucket.java

示例3: doPreUpgrade

import java.nio.file.Files; //導入方法依賴的package包/類
/**
 * Perform any steps that must succeed across all storage dirs/JournalManagers
 * involved in an upgrade before proceeding onto the actual upgrade stage. If
 * a call to any JM's or local storage dir's doPreUpgrade method fails, then
 * doUpgrade will not be called for any JM. The existing current dir is
 * renamed to previous.tmp, and then a new, empty current dir is created.
 *
 * @param conf configuration for creating {@link EditLogFileOutputStream}
 * @param sd the storage directory to perform the pre-upgrade procedure.
 * @throws IOException in the event of error
 */
static void doPreUpgrade(Configuration conf, StorageDirectory sd)
    throws IOException {
  LOG.info("Starting upgrade of storage directory " + sd.getRoot());

  // rename current to tmp
  renameCurToTmp(sd);

  final File curDir = sd.getCurrentDir();
  final File tmpDir = sd.getPreviousTmp();
  List<String> fileNameList = IOUtils.listDirectory(tmpDir, new FilenameFilter() {
    @Override
    public boolean accept(File dir, String name) {
      return dir.equals(tmpDir)
          && name.startsWith(NNStorage.NameNodeFile.EDITS.getName());
    }
  });

  for (String s : fileNameList) {
    File prevFile = new File(tmpDir, s);
    File newFile = new File(curDir, prevFile.getName());
    Files.createLink(newFile.toPath(), prevFile.toPath());
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:35,代碼來源:NNUpgradeUtil.java

示例4: linkInputs

import java.nio.file.Files; //導入方法依賴的package包/類
private void linkInputs(
    Path execDir,
    Digest inputRoot,
    Map<Digest, Directory> directoriesIndex,
    List<String> inputFiles)
    throws IOException, InterruptedException {
  Directory directory = directoriesIndex.get(inputRoot);

  for (FileNode fileNode : directory.getFilesList()) {
    Path execPath = execDir.resolve(fileNode.getName());
    String fileCacheKey = worker.fileCache.put(fileNode.getDigest(), fileNode.getIsExecutable());
    if (fileCacheKey == null) {
      throw new IOException("InputFetchStage: Failed to create cache entry for " + execPath);
    }
    inputFiles.add(fileCacheKey);
    Files.createLink(execPath, worker.fileCache.getPath(fileCacheKey));
  }

  for (DirectoryNode directoryNode : directory.getDirectoriesList()) {
    Digest digest = directoryNode.getDigest();
    String name = directoryNode.getName();
    Path dirPath = execDir.resolve(name);
    Files.createDirectories(dirPath);
    linkInputs(dirPath, digest, directoriesIndex, inputFiles);
  }
}
 
開發者ID:bazelbuild,項目名稱:bazel-buildfarm,代碼行數:27,代碼來源:InputFetchStage.java

示例5: move

import java.nio.file.Files; //導入方法依賴的package包/類
public static boolean move(File src, String dest) {
File destFile = new File(dest + src.getPath().substring(src.getPath().indexOf("\\") + 1));
boolean pass = true;
if (destFile.isFile()) {
    pass = pass && destFile.delete();
}
if (pass) {
    if (AV.save.getBool(Settings.MOVE_PACKAGE_FILES)) {
	pass = pass && Ln.moveFile(src, destFile, false);
    } else {
	try {
	    Ln.makeDirs(destFile);
	    Files.createLink(destFile.toPath(), src.toPath());
	    pass = pass && destFile.exists();
	} catch (IOException | UnsupportedOperationException ex) {
	    SPGlobal.logException(ex);
	    try {
		Files.copy(destFile.toPath(), src.toPath());
	    } catch (IOException ex1) {
		SPGlobal.logException(ex1);
		pass = false;
	    }
	}
    }
}
return pass;
   }
 
開發者ID:tstavrianos,項目名稱:automatic-variants,代碼行數:28,代碼來源:AVFileVars.java

示例6: StreamingOutputForDavFile

import java.nio.file.Files; //導入方法依賴的package包/類
/**
 * Constructor.
 * @param fileFullPath Full path of the file to be read
 * @param cellId Cell ID
 * @param encryptionType encryption type
 * @throws BinaryDataNotFoundException Error when file does not exist.
 */
public StreamingOutputForDavFile(String fileFullPath, String cellId, String encryptionType)
        throws BinaryDataNotFoundException {
    if (!Files.exists(Paths.get(fileFullPath))) {
        throw new BinaryDataNotFoundException(fileFullPath);
    }

    // 読み込み専用のハードリンクを作成するため、ユニーク名を生成。
    String hardLinkName = UniqueNameComposer.compose(fileFullPath);

    for (int i = 0; i < maxRetryCount; i++) {
        try {
            synchronized (fileFullPath) {
                // ハードリンクを作成.
                hardLinkPath = Files.createLink(Paths.get(hardLinkName), Paths.get(fileFullPath));
            }
            // ハードリンクからの入力ストリームを取得
            InputStream inputStream;
            // Perform decryption.
            DataCryptor cryptor = new DataCryptor(cellId);
            inputStream = cryptor.decode(new FileInputStream(hardLinkPath.toFile()), encryptionType);
            hardLinkInput = new BufferedInputStream(inputStream);
            // 成功したら終了
            return;
        } catch (IOException e) {
            // 指定回數まではリトライする。
            logger.debug(String.format("Creating hard link %s failed. Will try again.", hardLinkName));
            try {
                Thread.sleep(retryInterval);
            } catch (InterruptedException e1) {
                logger.debug("Thread interrupted.");
            }
        }
    }

    throw new BinaryDataNotFoundException("Unable to create hard link for DAV file: " + hardLinkName);
}
 
開發者ID:personium,項目名稱:personium-core,代碼行數:44,代碼來源:StreamingOutputForDavFile.java

示例7: createLink

import java.nio.file.Files; //導入方法依賴的package包/類
@Override
public void createLink(Path link, Path existing) throws IOException {
    triggerEx(existing, "createLink");
    Files.createLink(unwrap(link), unwrap(existing));
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:6,代碼來源:FaultyFileSystem.java

示例8: writeSymEntry

import java.nio.file.Files; //導入方法依賴的package包/類
private void writeSymEntry(Path dstFile, Path target) throws IOException {
    Objects.requireNonNull(dstFile);
    Objects.requireNonNull(target);
    Files.createDirectories(Objects.requireNonNull(dstFile.getParent()));
    Files.createLink(dstFile, target);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:7,代碼來源:DefaultImageBuilder.java


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