本文整理了Java中java.nio.file.Files.createLink()
方法的一些代码示例,展示了Files.createLink()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Files.createLink()
方法的具体详情如下:
包路径:java.nio.file.Files
类名称:Files
方法名:createLink
暂无
代码示例来源:origin: apache/geode
void createLink(Path link, Path existing) throws IOException {
Files.createLink(link, existing);
}
代码示例来源:origin: org.apache.hadoop/hadoop-common
/**
* Creates a hardlink
* @param file - existing source file
* @param linkName - desired target link file
*/
public static void createHardLink(File file, File linkName)
throws IOException {
if (file == null) {
throw new IOException(
"invalid arguments to createHardLink: source file is null");
}
if (linkName == null) {
throw new IOException(
"invalid arguments to createHardLink: link name is null");
}
createLink(linkName.toPath(), file.toPath());
}
代码示例来源:origin: org.apache.hadoop/hadoop-common
createLink(linkDir.toPath().resolve(name),
parentDir.toPath().resolve(name));
代码示例来源:origin: apache/flink
/**
* This recreates the new working directory of the recovered RocksDB instance and links/copies the contents from
* a local state.
*/
private void restoreInstanceDirectoryFromPath(Path source) throws IOException {
FileSystem fileSystem = source.getFileSystem();
final FileStatus[] fileStatuses = fileSystem.listStatus(source);
if (fileStatuses == null) {
throw new IOException("Cannot list file statues. Directory " + source + " does not exist.");
}
for (FileStatus fileStatus : fileStatuses) {
final Path filePath = fileStatus.getPath();
final String fileName = filePath.getName();
File restoreFile = new File(source.getPath(), fileName);
File targetFile = new File(stateBackend.instanceRocksDBPath.getPath(), fileName);
if (fileName.endsWith(SST_FILE_SUFFIX)) {
// hardlink'ing the immutable sst-files.
Files.createLink(targetFile.toPath(), restoreFile.toPath());
} else {
// true copy for all other files.
Files.copy(restoreFile.toPath(), targetFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
}
}
}
代码示例来源:origin: eclipse-vertx/vert.x
public Void perform() {
try {
Path source = vertx.resolveFile(link).toPath();
Path target = vertx.resolveFile(existing).toPath();
if (symbolic) {
Files.createSymbolicLink(source, target);
} else {
Files.createLink(source, target);
}
} catch (IOException e) {
throw new FileSystemException(e);
}
return null;
}
};
代码示例来源:origin: azkaban/azkaban
Files.createLink(linkFile.toPath(), Paths.get(targetFile.getAbsolutePath()));
linkCount++;
代码示例来源:origin: wildfly/wildfly
Files.createLink(path, tempPath);
} catch (FileAlreadyExistsException e) {
try {
代码示例来源:origin: google/guava
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();
}
}
代码示例来源:origin: wildfly/wildfly
Files.createLink(path, tempPath);
} catch (FileAlreadyExistsException e) {
try {
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testUnlink() throws Exception {
String fileName = "some-file.txt";
long fileSize = 1234;
createFileWithJunk(fileName, fileSize);
String linkName = "some-link.txt";
Files.createLink(Paths.get(testDir + pathSep + linkName), Paths.get(testDir + pathSep + fileName));
assertEquals(fileSize, fileLength(linkName));
vertx.fileSystem().unlink(testDir + pathSep + linkName, createHandler(true, v -> assertFalse(fileExists(linkName))));
await();
}
代码示例来源:origin: Netflix/Priam
"snap_v2_" + DateUtil.formatInstant(DateUtil.yyyyMMddHHmm, now));
snapshotDir.toFile().mkdirs();
Files.createLink(Paths.get(snapshotDir.toString(), file2.getFileName().toString()), file2);
Files.createLink(Paths.get(snapshotDir.toString(), file3.getFileName().toString()), file3);
Files.createLink(Paths.get(snapshotDir.toString(), file4.getFileName().toString()), file4);
代码示例来源:origin: org.apache.hadoop/hadoop-hdfs
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
throws IOException {
String name = file.getFileName().toString();
if (Files.isRegularFile(file)
&& name.startsWith(NNStorage.NameNodeFile.EDITS.getName())) {
Path newFile = curDir.resolve(name);
Files.createLink(newFile, file);
}
return super.visitFile(file, attrs);
}
}
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit
Path link = null;
try {
link = Files.createLink(
Paths.get(lock.getAbsolutePath() + ".lnk"), //$NON-NLS-1$
lockPath);
代码示例来源:origin: io.vertx/vertx-core
public Void perform() {
try {
Path source = vertx.resolveFile(link).toPath();
Path target = vertx.resolveFile(existing).toPath();
if (symbolic) {
Files.createSymbolicLink(source, target);
} else {
Files.createLink(source, target);
}
} catch (IOException e) {
throw new FileSystemException(e);
}
return null;
}
};
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit
Path path = file.toPath();
try {
link = Files.createLink(Paths.get(uniqueLinkPath(file)), path);
Integer nlink = (Integer) (Files.getAttribute(path,
"unix:nlink")); //$NON-NLS-1$
代码示例来源:origin: io.vertx/vertx-core
@Test
public void testUnlink() throws Exception {
String fileName = "some-file.txt";
long fileSize = 1234;
createFileWithJunk(fileName, fileSize);
String linkName = "some-link.txt";
Files.createLink(Paths.get(testDir + pathSep + linkName), Paths.get(testDir + pathSep + fileName));
assertEquals(fileSize, fileLength(linkName));
vertx.fileSystem().unlink(testDir + pathSep + linkName, createHandler(true, v -> assertFalse(fileExists(linkName))));
await();
}
代码示例来源:origin: com.indeed/util-core
@Override
public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException {
super.visitFile(file, attrs);
Files.createLink(dest.resolve(src.relativize(file)), file);
return FileVisitResult.CONTINUE;
}
});
代码示例来源:origin: de.pfabulist.lindwurm/niotest
@Test
@Category( { SlowTest.class, HardLink.class, Writable.class } )
public void testHardLinkModifyOneModifiedDateOfOtherChanged() throws IOException, InterruptedException {
Files.createLink( link(), orig() );
FileTime before = Files.getLastModifiedTime( orig() );
waitForAttribute();
Files.write( link(), CONTENT_OTHER );
assertThat( Files.getLastModifiedTime( orig() ) ).isGreaterThan( before );
}
代码示例来源:origin: de.pfabulist.lindwurm/niotest
@Test
@Category( { HardLink.class, Writable.class, WorkingDirectoryInPlaygroundTree.class} )
public void testHardLinkToRelative() throws IOException {
Files.createLink( link(), relativize( orig() ) );
assertThat( Files.isSameFile( link(), orig() ) ).isEqualTo( true );
}
代码示例来源:origin: de.pfabulist.lindwurm/niotest
@Test
@Category( { SymLink.class, HardLink.class, Delete.class, Writable.class } )
public void testHardLinkToSymLinkDeleteSymLeavesHardLinkUntouched() throws IOException {
Files.createSymbolicLink( symLink(), targetFile() );
Files.createLink( hardLink(), symLink() );
Files.delete( symLink() );
//assertThat( hardLink() ).hasBinaryContent( CONTENT );
assertThat( Files.readAllBytes( hardLink() ) ).isEqualTo( CONTENT );
}
内容来源于网络,如有侵权,请联系作者删除!