Example usage for java.nio.file Files isRegularFile

List of usage examples for java.nio.file Files isRegularFile

Introduction

In this page you can find the example usage for java.nio.file Files isRegularFile.

Prototype

public static boolean isRegularFile(Path path, LinkOption... options) 

Source Link

Document

Tests whether a file is a regular file with opaque content.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    Path path = FileSystems.getDefault().getPath("/home/docs/users.txt");
    System.out.println(Files.isRegularFile(path, LinkOption.NOFOLLOW_LINKS));
}

From source file:Main.java

public static void main(String[] args) {

    Path path = FileSystems.getDefault().getPath("C:/tutorial/Java/JavaFX", "Demo.txt");

    //method 1/*from  www  .  ja  v a 2  s.c om*/
    boolean is_regular = Files.isRegularFile(path, LinkOption.NOFOLLOW_LINKS);
}

From source file:Test.java

private static void displayFileAttributes(Path path) throws Exception {
    String format = "Exists: %s %n" + "notExists: %s %n" + "Directory: %s %n" + "Regular: %s %n"
            + "Executable: %s %n" + "Readable: %s %n" + "Writable: %s %n" + "Hidden: %s %n" + "Symbolic: %s %n"
            + "Last Modified Date: %s %n" + "Size: %s %n";

    System.out.printf(format, Files.exists(path, LinkOption.NOFOLLOW_LINKS),
            Files.notExists(path, LinkOption.NOFOLLOW_LINKS),
            Files.isDirectory(path, LinkOption.NOFOLLOW_LINKS),
            Files.isRegularFile(path, LinkOption.NOFOLLOW_LINKS), Files.isExecutable(path),
            Files.isReadable(path), Files.isWritable(path), Files.isHidden(path), Files.isSymbolicLink(path),
            Files.getLastModifiedTime(path, LinkOption.NOFOLLOW_LINKS), Files.size(path));
}

From source file:com.ignorelist.kassandra.steam.scraper.FileCache.java

private boolean exists(String key) {
    return Files.isRegularFile(buildCacheFile(key), LinkOption.NOFOLLOW_LINKS);
}

From source file:com.cyc.corpus.nlmpaper.AIMedOpenAccessPaper.java

private List<Path> listArchiveFiles(Path underHere) {
    List res = new ArrayList<>();

    try {/* www .  j  a va 2s . c o m*/
        Files.newDirectoryStream(underHere).forEach((p) -> {
            if (Files.isRegularFile(p, LinkOption.NOFOLLOW_LINKS)) {
                res.add(p);
            } else if (Files.isDirectory(p, LinkOption.NOFOLLOW_LINKS)) {
                res.addAll(listArchiveFiles(p));
            }
        });
    } catch (IOException ex) {
        LOG.log(Level.SEVERE, null, ex);
    }

    return res;
}

From source file:org.zxg.hotupdate.HotUpdateClassLoader.java

@Override
public void fileModified(Path path) {
    try {/*from  w  w  w  .j  a v  a2  s  .com*/
        if (Files.isRegularFile(path, LinkOption.NOFOLLOW_LINKS)) {
            synchronized (this) {
                loadClassFromFile(relativePathToClassName(classesRootDirPath.relativize(path).toString()));
            }
        }
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }
}

From source file:org.ng200.openolympus.FileAccess.java

public static boolean isFile(Path path, LinkOption... options) {
    return Files.isRegularFile(path, options);
}

From source file:org.zxg.hotupdate.HotUpdateClassLoader.java

@Override
public void fileDeleted(Path path) {
    if (Files.isRegularFile(path, LinkOption.NOFOLLOW_LINKS)) {
        synchronized (this) {
            classNameToClass.remove(relativePathToClassName(classesRootDirPath.relativize(path).toString()));
        }//  www. j  a  v  a2  s  .c o m
    }
}

From source file:org.commonjava.maven.galley.transport.htcli.internal.UploadMetadataGenTransferDecoratorTest.java

private void assertFile(final String filePath, boolean fileExists, final String httpMetaPath,
        boolean metaExists) throws Exception {
    final Path artifactPath = Paths.get(tempFolder.getAbsolutePath(), tempRepo, filePath);
    assertThat(Files.isRegularFile(artifactPath, LinkOption.NOFOLLOW_LINKS), equalTo(fileExists));
    final Path metadataPath = Paths.get(tempFolder.getAbsolutePath(), tempRepo, httpMetaPath);
    assertThat(Files.isRegularFile(metadataPath, LinkOption.NOFOLLOW_LINKS), equalTo(metaExists));
    if (metaExists) {
        String metaContent = FileUtils.readFileToString(metadataPath.toFile());
        assertThat(metaContent.contains(FILE_SIZE.toString()), equalTo(true));
        assertThat(metaContent.contains(MOCK_TIME), equalTo(true));
    }/*from  w w  w .  j a va  2s  .com*/
}

From source file:org.codice.ddf.configuration.migration.ImportMigrationExternalEntryImpl.java

/**
 * Verifies the corresponding existing file or directory to see if it matches the original one
 * based on the exported info./*ww w  .j  av  a 2s. c o m*/
 *
 * @param required <code>true</code> if the file or directory was required to be exported; <code>
 * false</code> if it was optional
 * @return <code>false</code> if an error was detected during verification; <code>true</code>
 *     otherwise
 */
@SuppressWarnings("squid:S3725" /* Files.isRegularFile() is used for consistency and to make sure that softlinks are not followed. not worried about performance here */)
private boolean verifyRealFileOrDirectory(boolean required) {
    return AccessUtils.doPrivileged(() -> {
        final MigrationReport report = getReport();
        final Path apath = getAbsolutePath();
        final File file = getFile();

        if (!file.exists()) {
            if (required) {
                report.record(new MigrationException(Messages.IMPORT_PATH_ERROR, apath, "does not exist"));
                return false;
            }
            return true;
        }
        if (softlink) {
            if (!Files.isSymbolicLink(apath)) {
                report.record(
                        new MigrationWarning(Messages.IMPORT_PATH_WARNING, apath, "is not a symbolic link"));
                return false;
            }
        } else if (isFile() && !Files.isRegularFile(apath, LinkOption.NOFOLLOW_LINKS)) {
            report.record(new MigrationWarning(Messages.IMPORT_PATH_WARNING, apath, "is not a regular file"));
        } else if (isDirectory() && !Files.isDirectory(apath, LinkOption.NOFOLLOW_LINKS)) {
            report.record(
                    new MigrationWarning(Messages.IMPORT_PATH_WARNING, apath, "is not a regular directory"));
        }
        return verifyChecksum();
    });
}