当前位置: 首页>>代码示例>>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;未经允许,请勿转载。