本文整理了Java中java.nio.file.Files.readSymbolicLink()
方法的一些代码示例,展示了Files.readSymbolicLink()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Files.readSymbolicLink()
方法的具体详情如下:
包路径:java.nio.file.Files
类名称:Files
方法名:readSymbolicLink
暂无
代码示例来源:origin: org.codehaus.plexus/plexus-utils
/**
* Reads the target of the symbolic link
*
* @param symlink A file that is a symlink
* @return A file that is the target of the symlink
* @throws java.io.IOException
*/
public static File readSymbolicLink( File symlink )
throws IOException
{
Path path = Files.readSymbolicLink( symlink.toPath() );
return path.toFile();
}
代码示例来源:origin: syncany/syncany
public static String readSymlinkTarget(File file) {
try {
return Files.readSymbolicLink(Paths.get(file.getAbsolutePath())).toString();
}
catch (IOException e) {
return null;
}
}
代码示例来源:origin: eclipse-vertx/vert.x
public String perform() {
try {
Path source = vertx.resolveFile(link).toPath();
return Files.readSymbolicLink(source).toString();
} catch (IOException e) {
throw new FileSystemException(e);
}
}
};
代码示例来源:origin: apache/ignite
/** {@inheritDoc} */
@Override public Path getLinkTarget(Path f) throws IOException {
File file = Files.readSymbolicLink(convert(f).toPath()).toFile();
return new Path(file.toURI());
}
代码示例来源:origin: apache/ignite
/**
* @param file File to resolve.
* @return Resolved file if it is a symbolic link or original file.
* @throws IOException If failed to resolve symlink.
*/
public static File resolveSymbolicLink(File file) throws IOException {
Path path = file.toPath();
return Files.isSymbolicLink(path) ? Files.readSymbolicLink(path).toFile() : file;
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Resolves symlink, if the given file is a symlink. Otherwise return null.
* <p>
* If the resolution fails, report an error.
*
* @return
* null if the given file is not a symlink.
* If the symlink is absolute, the returned string is an absolute path.
* If the symlink is relative, the returned string is that relative representation.
* The relative path is meant to be resolved from the location of the symlink.
*/
@CheckForNull
public static String resolveSymlink(@Nonnull File link) throws IOException {
try {
Path path = fileToPath(link);
return Files.readSymbolicLink(path).toString();
} catch (UnsupportedOperationException | FileSystemException x) {
// no symlinks on this platform (windows?),
// or not a link (// Thrown ("Incorrect function.") on JDK 7u21 in Windows 2012 when called on a non-symlink,
// rather than NotLinkException, contrary to documentation. Maybe only when not on NTFS?) ?
return null;
} catch (IOException x) {
throw x;
} catch (Exception x) {
throw new IOException(x);
}
}
代码示例来源:origin: apache/ignite
/**
* @return File status.
*/
private FileStatus fileStatus(File file) throws IOException {
boolean dir = file.isDirectory();
java.nio.file.Path path = dir ? null : file.toPath();
return new FileStatus(dir ? 0 : file.length(), dir, 1, 4 * 1024, file.lastModified(), file.lastModified(),
/*permission*/null, /*owner*/null, /*group*/null, dir ? null : Files.isSymbolicLink(path) ?
new Path(Files.readSymbolicLink(path).toUri()) : null, new Path(file.toURI()));
}
代码示例来源:origin: apache/ignite
/**
* Checks if link is correct.
*
* @param link Symbolic link.
* @param correctTarget Correct link target.
* @return {@code true} If link target is correct.
*/
private static boolean isJarLinkCorrect(File link, File correctTarget) {
if (!Files.isSymbolicLink(link.toPath()))
return false; // It is a real file or it does not exist.
Path target = null;
try {
target = Files.readSymbolicLink(link.toPath());
}
catch (IOException e) {
exit("Failed to read symbolic link: " + link.getAbsolutePath(), e);
}
return Files.exists(target) && target.toFile().equals(correctTarget);
}
代码示例来源:origin: apache/storm
Path versionFile = Files.readSymbolicLink(current);
Matcher m = VERSION_FILE_PATTERN.matcher(versionFile.getFileName().toString());
if (m.matches()) {
代码示例来源:origin: bytedeco/javacpp
Path linkPath = linkFile.toPath();
Path targetPath = Paths.get(name);
if ((!linkFile.exists() || !Files.isSymbolicLink(linkPath) || !Files.readSymbolicLink(linkPath).equals(targetPath))
&& !targetPath.isAbsolute() && !targetPath.equals(linkPath.getFileName())) {
if (logger.isDebugEnabled()) {
Path linkPath2 = linkFile2.toPath();
Path relativeTarget = Paths.get(parent2).relativize(Paths.get(parent)).resolve(name);
if ((!linkFile2.exists() || !Files.isSymbolicLink(linkPath2) || !Files.readSymbolicLink(linkPath2).equals(relativeTarget))
&& !relativeTarget.isAbsolute() && !relativeTarget.equals(linkPath2.getFileName())) {
if (logger.isDebugEnabled()) {
代码示例来源:origin: oracle/opengrok
String linkedTo = Files.readSymbolicLink(given).toRealPath().toString();
if (linkedTo.regionMatches(0, wsRoot, 0, wsRoot.length())) {
relRoot = linkedTo.substring(wsRoot.length());
代码示例来源:origin: bytedeco/javacpp
try {
Path path = file.toPath(), targetPath = Paths.get(target);
if ((!file.exists() || !Files.isSymbolicLink(path) || !Files.readSymbolicLink(path).equals(targetPath))
&& targetPath.isAbsolute() && !targetPath.equals(path)) {
if (logger.isDebugEnabled()) {
if ((!file.exists() || !Files.isSymbolicLink(path) || !Files.readSymbolicLink(path).equals(targetPath))
&& targetPath.isAbsolute() && !targetPath.equals(path)) {
if (logger.isDebugEnabled()) {
try {
Path path = file.toPath(), urlPath = urlFile.toPath();
if ((!file.exists() || !Files.isSymbolicLink(path) || !Files.readSymbolicLink(path).equals(urlPath))
&& urlPath.isAbsolute() && !urlPath.equals(path)) {
if (logger.isDebugEnabled()) {
if ((!file.exists() || !Files.isSymbolicLink(path) || !Files.readSymbolicLink(path).equals(urlPath))
&& urlPath.isAbsolute() && !urlPath.equals(path)) {
if (logger.isDebugEnabled()) {
代码示例来源:origin: bytedeco/javacpp
Path linkPath = linkFile.toPath();
Path targetPath = file2.toPath();
if ((!linkFile.exists() || !Files.isSymbolicLink(linkPath) || !Files.readSymbolicLink(linkPath).equals(targetPath))
&& targetPath.isAbsolute() && !targetPath.equals(linkPath)) {
if (logger.isDebugEnabled()) {
代码示例来源:origin: io.vertx/vertx-core
public String perform() {
try {
Path source = vertx.resolveFile(link).toPath();
return Files.readSymbolicLink(source).toString();
} catch (IOException e) {
throw new FileSystemException(e);
}
}
};
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit
/**
* Get file length
*
* @param file
* a {@link java.io.File}.
* @return length of the given file
* @throws java.io.IOException
* @since 4.1
*/
public static long getLength(File file) throws IOException {
Path nioPath = toPath(file);
if (Files.isSymbolicLink(nioPath))
return Files.readSymbolicLink(nioPath).toString()
.getBytes(UTF_8).length;
return Files.size(nioPath);
}
代码示例来源:origin: org.nuxeo.ecm.core/nuxeo-core-api
path = Files.readSymbolicLink(path);
if (!Files.exists(path)) {
throw new FileNotFoundException(filePath);
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit
/**
* Read target path of the symlink.
*
* @param path
* a {@link java.io.File} object.
* @return target path of the symlink, or null if it is not a symbolic link
* @throws java.io.IOException
* @since 3.0
*/
public static String readSymLink(File path) throws IOException {
Path nioPath = toPath(path);
Path target = Files.readSymbolicLink(nioPath);
String targetString = target.toString();
if (SystemReader.getInstance().isWindows()) {
targetString = targetString.replace('\\', '/');
} else if (SystemReader.getInstance().isMacOS()) {
targetString = Normalizer.normalize(targetString, Form.NFC);
}
return targetString;
}
代码示例来源:origin: org.eclipse.jetty/jetty-util
return path.getParent().resolve(Files.readSymbolicLink(path));
if (Files.exists(path))
代码示例来源:origin: addthis/hydra
private Path resolveLink(Path path) throws IOException {
int depth;
for (depth = 0; depth < SYMLINK_MAX_DEPTH && Files.isSymbolicLink(path); depth++) {
path = Files.readSymbolicLink(path);
}
if (depth == SYMLINK_MAX_DEPTH) {
return null;
} else {
return path;
}
}
代码示例来源:origin: biz.aQute.bnd/biz.aQute.bndlib
public static Path mkdirs(Path dir) throws IOException {
if (Files.isSymbolicLink(dir)) {
return mkdirs(Files.readSymbolicLink(dir));
}
return Files.createDirectories(dir);
}
内容来源于网络,如有侵权,请联系作者删除!