java.nio.file.attribute.BasicFileAttributes#isSymbolicLink ( )源码实例Demo

下面列出了java.nio.file.attribute.BasicFileAttributes#isSymbolicLink ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: openjdk-8   文件: FileTreeWalker.java
/**
 * Returns the attributes of the given file, taking into account whether
 * the walk is following sym links is not. The {@code canUseCached}
 * argument determines whether this method can use cached attributes.
 */
private BasicFileAttributes getAttributes(Path file, boolean canUseCached)
    throws IOException
{
    // if attributes are cached then use them if possible
    if (canUseCached &&
        (file instanceof BasicFileAttributesHolder) &&
        (System.getSecurityManager() == null))
    {
        BasicFileAttributes cached = ((BasicFileAttributesHolder)file).get();
        if (cached != null && (!followLinks || !cached.isSymbolicLink())) {
            return cached;
        }
    }

    // attempt to get attributes of file. If fails and we are following
    // links then a link target might not exist so get attributes of link
    BasicFileAttributes attrs;
    try {
        attrs = Files.readAttributes(file, BasicFileAttributes.class, linkOptions);
    } catch (IOException ioe) {
        if (!followLinks)
            throw ioe;

        // attempt to get attrmptes without following links
        attrs = Files.readAttributes(file,
                                     BasicFileAttributes.class,
                                     LinkOption.NOFOLLOW_LINKS);
    }
    return attrs;
}
 
源代码2 项目: jdk8u_jdk   文件: FileTreeWalker.java
/**
 * Returns the attributes of the given file, taking into account whether
 * the walk is following sym links is not. The {@code canUseCached}
 * argument determines whether this method can use cached attributes.
 */
private BasicFileAttributes getAttributes(Path file, boolean canUseCached)
    throws IOException
{
    // if attributes are cached then use them if possible
    if (canUseCached &&
        (file instanceof BasicFileAttributesHolder) &&
        (System.getSecurityManager() == null))
    {
        BasicFileAttributes cached = ((BasicFileAttributesHolder)file).get();
        if (cached != null && (!followLinks || !cached.isSymbolicLink())) {
            return cached;
        }
    }

    // attempt to get attributes of file. If fails and we are following
    // links then a link target might not exist so get attributes of link
    BasicFileAttributes attrs;
    try {
        attrs = Files.readAttributes(file, BasicFileAttributes.class, linkOptions);
    } catch (IOException ioe) {
        if (!followLinks)
            throw ioe;

        // attempt to get attrmptes without following links
        attrs = Files.readAttributes(file,
                                     BasicFileAttributes.class,
                                     LinkOption.NOFOLLOW_LINKS);
    }
    return attrs;
}
 
源代码3 项目: dragonwell8_jdk   文件: FileTreeWalker.java
/**
 * Returns the attributes of the given file, taking into account whether
 * the walk is following sym links is not. The {@code canUseCached}
 * argument determines whether this method can use cached attributes.
 */
private BasicFileAttributes getAttributes(Path file, boolean canUseCached)
    throws IOException
{
    // if attributes are cached then use them if possible
    if (canUseCached &&
        (file instanceof BasicFileAttributesHolder) &&
        (System.getSecurityManager() == null))
    {
        BasicFileAttributes cached = ((BasicFileAttributesHolder)file).get();
        if (cached != null && (!followLinks || !cached.isSymbolicLink())) {
            return cached;
        }
    }

    // attempt to get attributes of file. If fails and we are following
    // links then a link target might not exist so get attributes of link
    BasicFileAttributes attrs;
    try {
        attrs = Files.readAttributes(file, BasicFileAttributes.class, linkOptions);
    } catch (IOException ioe) {
        if (!followLinks)
            throw ioe;

        // attempt to get attrmptes without following links
        attrs = Files.readAttributes(file,
                                     BasicFileAttributes.class,
                                     LinkOption.NOFOLLOW_LINKS);
    }
    return attrs;
}
 
源代码4 项目: TencentKona-8   文件: FileTreeWalker.java
/**
 * Returns the attributes of the given file, taking into account whether
 * the walk is following sym links is not. The {@code canUseCached}
 * argument determines whether this method can use cached attributes.
 */
private BasicFileAttributes getAttributes(Path file, boolean canUseCached)
    throws IOException
{
    // if attributes are cached then use them if possible
    if (canUseCached &&
        (file instanceof BasicFileAttributesHolder) &&
        (System.getSecurityManager() == null))
    {
        BasicFileAttributes cached = ((BasicFileAttributesHolder)file).get();
        if (cached != null && (!followLinks || !cached.isSymbolicLink())) {
            return cached;
        }
    }

    // attempt to get attributes of file. If fails and we are following
    // links then a link target might not exist so get attributes of link
    BasicFileAttributes attrs;
    try {
        attrs = Files.readAttributes(file, BasicFileAttributes.class, linkOptions);
    } catch (IOException ioe) {
        if (!followLinks)
            throw ioe;

        // attempt to get attrmptes without following links
        attrs = Files.readAttributes(file,
                                     BasicFileAttributes.class,
                                     LinkOption.NOFOLLOW_LINKS);
    }
    return attrs;
}
 
源代码5 项目: jdk8u60   文件: FileTreeWalker.java
/**
 * Returns the attributes of the given file, taking into account whether
 * the walk is following sym links is not. The {@code canUseCached}
 * argument determines whether this method can use cached attributes.
 */
private BasicFileAttributes getAttributes(Path file, boolean canUseCached)
    throws IOException
{
    // if attributes are cached then use them if possible
    if (canUseCached &&
        (file instanceof BasicFileAttributesHolder) &&
        (System.getSecurityManager() == null))
    {
        BasicFileAttributes cached = ((BasicFileAttributesHolder)file).get();
        if (cached != null && (!followLinks || !cached.isSymbolicLink())) {
            return cached;
        }
    }

    // attempt to get attributes of file. If fails and we are following
    // links then a link target might not exist so get attributes of link
    BasicFileAttributes attrs;
    try {
        attrs = Files.readAttributes(file, BasicFileAttributes.class, linkOptions);
    } catch (IOException ioe) {
        if (!followLinks)
            throw ioe;

        // attempt to get attrmptes without following links
        attrs = Files.readAttributes(file,
                                     BasicFileAttributes.class,
                                     LinkOption.NOFOLLOW_LINKS);
    }
    return attrs;
}
 
源代码6 项目: JDKSourceCode1.8   文件: FileTreeWalker.java
/**
 * Returns the attributes of the given file, taking into account whether
 * the walk is following sym links is not. The {@code canUseCached}
 * argument determines whether this method can use cached attributes.
 */
private BasicFileAttributes getAttributes(Path file, boolean canUseCached)
    throws IOException
{
    // if attributes are cached then use them if possible
    if (canUseCached &&
        (file instanceof BasicFileAttributesHolder) &&
        (System.getSecurityManager() == null))
    {
        BasicFileAttributes cached = ((BasicFileAttributesHolder)file).get();
        if (cached != null && (!followLinks || !cached.isSymbolicLink())) {
            return cached;
        }
    }

    // attempt to get attributes of file. If fails and we are following
    // links then a link target might not exist so get attributes of link
    BasicFileAttributes attrs;
    try {
        attrs = Files.readAttributes(file, BasicFileAttributes.class, linkOptions);
    } catch (IOException ioe) {
        if (!followLinks)
            throw ioe;

        // attempt to get attrmptes without following links
        attrs = Files.readAttributes(file,
                                     BasicFileAttributes.class,
                                     LinkOption.NOFOLLOW_LINKS);
    }
    return attrs;
}
 
源代码7 项目: jdk8u-dev-jdk   文件: FileTreeWalker.java
/**
 * Returns the attributes of the given file, taking into account whether
 * the walk is following sym links is not. The {@code canUseCached}
 * argument determines whether this method can use cached attributes.
 */
private BasicFileAttributes getAttributes(Path file, boolean canUseCached)
    throws IOException
{
    // if attributes are cached then use them if possible
    if (canUseCached &&
        (file instanceof BasicFileAttributesHolder) &&
        (System.getSecurityManager() == null))
    {
        BasicFileAttributes cached = ((BasicFileAttributesHolder)file).get();
        if (cached != null && (!followLinks || !cached.isSymbolicLink())) {
            return cached;
        }
    }

    // attempt to get attributes of file. If fails and we are following
    // links then a link target might not exist so get attributes of link
    BasicFileAttributes attrs;
    try {
        attrs = Files.readAttributes(file, BasicFileAttributes.class, linkOptions);
    } catch (IOException ioe) {
        if (!followLinks)
            throw ioe;

        // attempt to get attrmptes without following links
        attrs = Files.readAttributes(file,
                                     BasicFileAttributes.class,
                                     LinkOption.NOFOLLOW_LINKS);
    }
    return attrs;
}
 
源代码8 项目: Launcher   文件: HashedDir.java
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
    // Verify is not symlink
    if (!allowSymlinks && attrs.isSymbolicLink())
        throw new SecurityException("Symlinks are not allowed");

    // Add file (may be unhashed, if exclusion)
    path.add(IOHelper.getFileName(file));
    boolean doDigest = digest && (matcher == null || matcher.shouldUpdate(path));
    current.map.put(path.removeLast(), new HashedFile(file, attrs.size(), doDigest));
    return super.visitFile(file, attrs);
}
 
源代码9 项目: openjdk-jdk8u   文件: FileTreeWalker.java
/**
 * Returns the attributes of the given file, taking into account whether
 * the walk is following sym links is not. The {@code canUseCached}
 * argument determines whether this method can use cached attributes.
 */
private BasicFileAttributes getAttributes(Path file, boolean canUseCached)
    throws IOException
{
    // if attributes are cached then use them if possible
    if (canUseCached &&
        (file instanceof BasicFileAttributesHolder) &&
        (System.getSecurityManager() == null))
    {
        BasicFileAttributes cached = ((BasicFileAttributesHolder)file).get();
        if (cached != null && (!followLinks || !cached.isSymbolicLink())) {
            return cached;
        }
    }

    // attempt to get attributes of file. If fails and we are following
    // links then a link target might not exist so get attributes of link
    BasicFileAttributes attrs;
    try {
        attrs = Files.readAttributes(file, BasicFileAttributes.class, linkOptions);
    } catch (IOException ioe) {
        if (!followLinks)
            throw ioe;

        // attempt to get attrmptes without following links
        attrs = Files.readAttributes(file,
                                     BasicFileAttributes.class,
                                     LinkOption.NOFOLLOW_LINKS);
    }
    return attrs;
}
 
源代码10 项目: openjdk-jdk8u-backup   文件: FileTreeWalker.java
/**
 * Returns the attributes of the given file, taking into account whether
 * the walk is following sym links is not. The {@code canUseCached}
 * argument determines whether this method can use cached attributes.
 */
private BasicFileAttributes getAttributes(Path file, boolean canUseCached)
    throws IOException
{
    // if attributes are cached then use them if possible
    if (canUseCached &&
        (file instanceof BasicFileAttributesHolder) &&
        (System.getSecurityManager() == null))
    {
        BasicFileAttributes cached = ((BasicFileAttributesHolder)file).get();
        if (cached != null && (!followLinks || !cached.isSymbolicLink())) {
            return cached;
        }
    }

    // attempt to get attributes of file. If fails and we are following
    // links then a link target might not exist so get attributes of link
    BasicFileAttributes attrs;
    try {
        attrs = Files.readAttributes(file, BasicFileAttributes.class, linkOptions);
    } catch (IOException ioe) {
        if (!followLinks)
            throw ioe;

        // attempt to get attrmptes without following links
        attrs = Files.readAttributes(file,
                                     BasicFileAttributes.class,
                                     LinkOption.NOFOLLOW_LINKS);
    }
    return attrs;
}
 
源代码11 项目: openjdk-jdk9   文件: FileTreeWalker.java
/**
 * Returns the attributes of the given file, taking into account whether
 * the walk is following sym links is not. The {@code canUseCached}
 * argument determines whether this method can use cached attributes.
 */
private BasicFileAttributes getAttributes(Path file, boolean canUseCached)
    throws IOException
{
    // if attributes are cached then use them if possible
    if (canUseCached &&
        (file instanceof BasicFileAttributesHolder) &&
        (System.getSecurityManager() == null))
    {
        BasicFileAttributes cached = ((BasicFileAttributesHolder)file).get();
        if (cached != null && (!followLinks || !cached.isSymbolicLink())) {
            return cached;
        }
    }

    // attempt to get attributes of file. If fails and we are following
    // links then a link target might not exist so get attributes of link
    BasicFileAttributes attrs;
    try {
        attrs = Files.readAttributes(file, BasicFileAttributes.class, linkOptions);
    } catch (IOException ioe) {
        if (!followLinks)
            throw ioe;

        // attempt to get attrmptes without following links
        attrs = Files.readAttributes(file,
                                     BasicFileAttributes.class,
                                     LinkOption.NOFOLLOW_LINKS);
    }
    return attrs;
}
 
源代码12 项目: yajsync   文件: BasicFileAttributeManager.java
private int toMode(BasicFileAttributes attrs)
{
    if (attrs.isDirectory()) {
        return FileOps.S_IFDIR | _defaultDirectoryPermissions;
    } else if (attrs.isRegularFile()) {
        return FileOps.S_IFREG | _defaultFilePermissions;
    } else if (attrs.isSymbolicLink()) {
        return FileOps.S_IFLNK | _defaultFilePermissions;
    } else {
        return FileOps.S_IFUNK;
    }
}
 
源代码13 项目: java-tutorial   文件: PrintFiles.java
@Override
public FileVisitResult visitFile(Path file,
                                 BasicFileAttributes attr) {
    if (attr.isSymbolicLink()) {
        System.out.format("Symbolic link: %s ", file);
    } else if (attr.isRegularFile()) {
        System.out.format("Regular file: %s ", file);
    } else {
        System.out.format("Other: %s ", file);
    }
    System.out.println("(" + attr.size() + "bytes)");
    return CONTINUE;
}
 
源代码14 项目: Java8CN   文件: FileTreeWalker.java
/**
 * Returns the attributes of the given file, taking into account whether
 * the walk is following sym links is not. The {@code canUseCached}
 * argument determines whether this method can use cached attributes.
 */
private BasicFileAttributes getAttributes(Path file, boolean canUseCached)
    throws IOException
{
    // if attributes are cached then use them if possible
    if (canUseCached &&
        (file instanceof BasicFileAttributesHolder) &&
        (System.getSecurityManager() == null))
    {
        BasicFileAttributes cached = ((BasicFileAttributesHolder)file).get();
        if (cached != null && (!followLinks || !cached.isSymbolicLink())) {
            return cached;
        }
    }

    // attempt to get attributes of file. If fails and we are following
    // links then a link target might not exist so get attributes of link
    BasicFileAttributes attrs;
    try {
        attrs = Files.readAttributes(file, BasicFileAttributes.class, linkOptions);
    } catch (IOException ioe) {
        if (!followLinks)
            throw ioe;

        // attempt to get attrmptes without following links
        attrs = Files.readAttributes(file,
                                     BasicFileAttributes.class,
                                     LinkOption.NOFOLLOW_LINKS);
    }
    return attrs;
}
 
源代码15 项目: hottub   文件: FileTreeWalker.java
/**
 * Returns the attributes of the given file, taking into account whether
 * the walk is following sym links is not. The {@code canUseCached}
 * argument determines whether this method can use cached attributes.
 */
private BasicFileAttributes getAttributes(Path file, boolean canUseCached)
    throws IOException
{
    // if attributes are cached then use them if possible
    if (canUseCached &&
        (file instanceof BasicFileAttributesHolder) &&
        (System.getSecurityManager() == null))
    {
        BasicFileAttributes cached = ((BasicFileAttributesHolder)file).get();
        if (cached != null && (!followLinks || !cached.isSymbolicLink())) {
            return cached;
        }
    }

    // attempt to get attributes of file. If fails and we are following
    // links then a link target might not exist so get attributes of link
    BasicFileAttributes attrs;
    try {
        attrs = Files.readAttributes(file, BasicFileAttributes.class, linkOptions);
    } catch (IOException ioe) {
        if (!followLinks)
            throw ioe;

        // attempt to get attrmptes without following links
        attrs = Files.readAttributes(file,
                                     BasicFileAttributes.class,
                                     LinkOption.NOFOLLOW_LINKS);
    }
    return attrs;
}
 
源代码16 项目: openjdk-8-source   文件: FileTreeWalker.java
/**
 * Returns the attributes of the given file, taking into account whether
 * the walk is following sym links is not. The {@code canUseCached}
 * argument determines whether this method can use cached attributes.
 */
private BasicFileAttributes getAttributes(Path file, boolean canUseCached)
    throws IOException
{
    // if attributes are cached then use them if possible
    if (canUseCached &&
        (file instanceof BasicFileAttributesHolder) &&
        (System.getSecurityManager() == null))
    {
        BasicFileAttributes cached = ((BasicFileAttributesHolder)file).get();
        if (cached != null && (!followLinks || !cached.isSymbolicLink())) {
            return cached;
        }
    }

    // attempt to get attributes of file. If fails and we are following
    // links then a link target might not exist so get attributes of link
    BasicFileAttributes attrs;
    try {
        attrs = Files.readAttributes(file, BasicFileAttributes.class, linkOptions);
    } catch (IOException ioe) {
        if (!followLinks)
            throw ioe;

        // attempt to get attrmptes without following links
        attrs = Files.readAttributes(file,
                                     BasicFileAttributes.class,
                                     LinkOption.NOFOLLOW_LINKS);
    }
    return attrs;
}
 
源代码17 项目: mycore   文件: MCRFileAttributes.java
public static FileType fromAttribute(BasicFileAttributes attrs) {
    if (attrs.isRegularFile()) {
        return file;
    }
    if (attrs.isDirectory()) {
        return directory;
    }
    if (attrs.isSymbolicLink()) {
        return link;
    }
    return other;
}
 
源代码18 项目: DAFramework   文件: SysToolkit.java
public static boolean isSymbolicLink(String path) throws Exception {
	BasicFileAttributes attrs = Files.readAttributes(FileSystems.getDefault().getPath(polishFilePath(path)), BasicFileAttributes.

	class, LinkOption.NOFOLLOW_LINKS);
	return attrs.isSymbolicLink();
}
 
源代码19 项目: wES   文件: SysToolkit.java
public static boolean isSymbolicLink(String path) throws Exception {
	BasicFileAttributes attrs = Files.readAttributes(FileSystems.getDefault().getPath(polishFilePath(path)), BasicFileAttributes.

			class, LinkOption.NOFOLLOW_LINKS);
	return attrs.isSymbolicLink();
}
 
源代码20 项目: levelup-java-examples   文件: IsFileSymbolicLink.java
@Test
public void file_is_symbolic_link_nio() throws IOException {

	BasicFileAttributes attr = Files.readAttributes(source,
			BasicFileAttributes.class);

	boolean isSymbolicLink = attr.isSymbolicLink();

	assertFalse(isSymbolicLink);
}