本文整理匯總了Java中java.nio.file.Files.readSymbolicLink方法的典型用法代碼示例。如果您正苦於以下問題:Java Files.readSymbolicLink方法的具體用法?Java Files.readSymbolicLink怎麽用?Java Files.readSymbolicLink使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.nio.file.Files
的用法示例。
在下文中一共展示了Files.readSymbolicLink方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: syncSymbolicLink
import java.nio.file.Files; //導入方法依賴的package包/類
private static void syncSymbolicLink(
final Path source, final Path target, final Path sourceFile, final Path targetFile)
throws IOException {
final Path sourceLink = Files.readSymbolicLink(sourceFile);
final Path expectedTargetLink = equivalentSubpath(source, target, sourceLink);
if (Files.exists(targetFile)) {
final Path actualTargetLink = Files.readSymbolicLink(targetFile);
if (expectedTargetLink.toRealPath().equals(actualTargetLink.toRealPath())) {
return;
}
}
Files.deleteIfExists(targetFile);
Files.createSymbolicLink(targetFile, expectedTargetLink);
}
示例2: toFileName
import java.nio.file.Files; //導入方法依賴的package包/類
public static String toFileName(String path) throws IOException {
File f = new File(path);
String fileName = f.getName();
if(Files.isSymbolicLink(f.toPath())) {
Path p = Files.readSymbolicLink(f.toPath());
fileName = p.getFileName().toFile().getName();
}
return fileName;
}
示例3: readLink
import java.nio.file.Files; //導入方法依賴的package包/類
private static Path readLink(final Path path) {
try {
return Files.readSymbolicLink(path);
} catch (IOException e) {
throw new UncheckedIOException("Could not read link " + path, e);
}
}
示例4: verifySymLinks
import java.nio.file.Files; //導入方法依賴的package包/類
private void verifySymLinks(String bindir) throws IOException {
File binDir = new File(bindir);
System.err.println("verifying links in: " + bindir);
File isaDir = new File(binDir, getArch()).getAbsoluteFile();
if (!isaDir.exists()) {
throw new RuntimeException("dir: " + isaDir + " does not exist");
}
try (DirectoryStream<Path> ds = Files.newDirectoryStream(binDir.toPath())) {
for (Path p : ds) {
if (symlinkExcludes.matcher(p.toString()).matches() ||
Files.isDirectory(p, NOFOLLOW_LINKS)) {
continue;
}
Path link = new File(isaDir, p.getFileName().toString()).toPath();
if (Files.isSymbolicLink(link)) {
Path target = Files.readSymbolicLink(link);
if (target.startsWith("..") && p.endsWith(target.getFileName())) {
// System.out.println(target + " OK");
continue;
}
System.err.println("target:" + target);
System.err.println("file:" + p);
}
throw new RuntimeException("could not find link to " + p);
}
}
}
示例5: getPackagePath
import java.nio.file.Files; //導入方法依賴的package包/類
synchronized Path getPackagePath(String pkgName) throws IOException {
// check the cache first
if (pkgDirs.containsKey(pkgName)) {
return pkgDirs.get(pkgName);
}
Path pkgLink = fs.getPath("/packages/" + pkgName.replace('/', '.'));
// check if /packages/$PACKAGE directory exists
if (Files.isDirectory(pkgLink)) {
try (DirectoryStream<Path> stream = Files.newDirectoryStream(pkgLink)) {
for (Path p : stream) {
// find first symbolic link to module directory
if (Files.isSymbolicLink(p)) {
Path modDir = Files.readSymbolicLink(p);
if (Files.isDirectory(modDir)) {
// get package subdirectory under /modules/$MODULE/
Path pkgDir = fs.getPath(modDir.toString() + "/" + pkgName);
if (Files.isDirectory(pkgDir)) {
// it is a package directory only if contains
// at least one .class file
try (DirectoryStream<Path> pstream =
Files.newDirectoryStream(pkgDir)) {
for (Path f : pstream) {
if (Files.isRegularFile(f)
&& f.toString().endsWith(".class")) {
pkgDirs.put(pkgName, pkgDir);
return pkgDir;
}
}
}
}
}
}
}
}
}
return null;
}
示例6: testPackagesLinks
import java.nio.file.Files; //導入方法依賴的package包/類
@Test(dataProvider = "packagesLinks")
public void testPackagesLinks(String link) throws Exception {
FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
Path path = fs.getPath(link);
assertTrue(Files.exists(path), link + " missing");
assertTrue(Files.isSymbolicLink(path), path + " is not a link");
path = Files.readSymbolicLink(path);
assertEquals(path.toString(), "/modules" + link.substring(link.lastIndexOf("/")));
}
示例7: getSymbolicLinkTargetFile
import java.nio.file.Files; //導入方法依賴的package包/類
public static Path getSymbolicLinkTargetFile(Path path) {
if (!Files.isSymbolicLink(path)) {
return path;
}
try {
Path targetPath = Files.readSymbolicLink(path);
return getSymbolicLinkTargetFile(targetPath);
} catch (IOException e) {
throw new RuntimeException("Failed to read symbolic link: " + path, e);
}
}
示例8: getLinkPath
import java.nio.file.Files; //導入方法依賴的package包/類
public static Path getLinkPath (final Path p) throws IOException {
return Files.readSymbolicLink(p);
}
示例9: readSymbolicLink
import java.nio.file.Files; //導入方法依賴的package包/類
@Override
public Path readSymbolicLink(Path link) throws IOException {
Path target = Files.readSymbolicLink(unwrap(link));
triggerEx(target, "readSymbolicLink");
return new PassThroughFileSystem.PassThroughPath(delegate, target);
}
示例10: getEntry
import java.nio.file.Files; //導入方法依賴的package包/類
synchronized Entry getEntry(RelativeDirectory rd) throws IOException {
SoftReference<Entry> ref = entries.get(rd);
Entry e = (ref == null) ? null : ref.get();
if (e == null) {
Map<String, Path> files = new LinkedHashMap<>();
Set<RelativeDirectory> subdirs = new LinkedHashSet<>();
Path dir;
if (rd.path.isEmpty()) {
dir = jrtfs.getPath("/modules");
} else {
Path pkgs = jrtfs.getPath("/packages");
dir = pkgs.resolve(rd.getPath().replaceAll("/$", "").replace("/", "."));
}
if (Files.exists(dir)) {
try (DirectoryStream<Path> modules = Files.newDirectoryStream(dir)) {
for (Path module: modules) {
if (Files.isSymbolicLink(module))
module = Files.readSymbolicLink(module);
Path p = rd.resolveAgainst(module);
if (!Files.exists(p))
continue;
try (DirectoryStream<Path> stream = Files.newDirectoryStream(p)) {
for (Path entry: stream) {
String name = entry.getFileName().toString();
if (Files.isRegularFile(entry)) {
// TODO: consider issue of files with same name in different modules
files.put(name, entry);
} else if (Files.isDirectory(entry)) {
subdirs.add(new RelativeDirectory(rd, name));
}
}
}
}
}
}
e = new Entry(Collections.unmodifiableMap(files),
Collections.unmodifiableSet(subdirs),
getCtInfo(rd));
entries.put(rd, new SoftReference<>(e));
}
return e;
}