Example usage for java.nio.file Files newDirectoryStream

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

Introduction

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

Prototype

public static DirectoryStream<Path> newDirectoryStream(Path dir) throws IOException 

Source Link

Document

Opens a directory, returning a DirectoryStream to iterate over all entries in the directory.

Usage

From source file:org.bimserver.test.RemoveEmpty.java

private void start(String loc) {
    Path base = Paths.get(loc);
    try {/*from   w ww .j a va 2  s  . c om*/
        DirectoryStream<Path> newDirectoryStream = Files.newDirectoryStream(base);
        for (Path p : newDirectoryStream) {
            DirectoryStream<Path> a = Files.newDirectoryStream(p);
            int c = 0;
            for (Path b : a) {
                c++;
            }
            if (c == 1) {
                org.apache.commons.io.FileUtils.deleteDirectory(p.toFile());
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.basistech.rosette.api.RosetteAPITest.java

@Parameterized.Parameters
public static Collection<Object[]> data() throws URISyntaxException, IOException {
    File dir = new File("src/test/mock-data/response");
    Collection<Object[]> params = new ArrayList<>();
    try (DirectoryStream<Path> paths = Files.newDirectoryStream(dir.toPath())) {
        for (Path file : paths) {
            if (file.toString().endsWith(".json")) {
                params.add(new Object[] { file.getFileName().toString() });
            }/*  ww w  .ja  va  2s.c om*/
        }
    }
    return params;
}

From source file:org.apache.htrace.impl.TestDroppedSpans.java

@BeforeClass
public static void afterClass() throws IOException {
    if (tempDir != null) {
        try (DirectoryStream<Path> stream = Files.newDirectoryStream(tempDir)) {
            for (final Iterator<Path> it = stream.iterator(); it.hasNext();) {
                Files.delete(it.next());
            }/*from  w  w w  .  j  a v a  2s  . c  o m*/
        }
        Files.delete(tempDir);
        tempDir = null;
    }
}

From source file:com.nwn.NwnFileHandler.java

/**
 * Get names of files in given directory
 * @param dir Path to directory for parsing
 * @return String of file names in directory
 *//*from w ww . j  a v  a  2  s  .  com*/
public static ArrayList<String> getFileNamesInDirectory(Path dir) throws NoSuchFileException, IOException {
    ArrayList<String> fileNamesInDir = new ArrayList<String>();
    DirectoryStream<Path> dirStream = Files.newDirectoryStream(dir);
    for (Path file : dirStream) {
        fileNamesInDir.add(file.getFileName().toString());
    }
    dirStream.close();
    return fileNamesInDir;
}

From source file:com.flipkart.poseidon.api.APIManager.java

public static void scanAndAdd(Path dir, List<String> validConfigs) {
    try (DirectoryStream<Path> files = Files.newDirectoryStream(dir)) {
        for (Path entry : files) {
            File file = entry.toFile();
            if (file.isDirectory()) {
                scanAndAdd(entry, validConfigs);
                continue;
            }//from   w  w w  .jav  a 2  s.co m
            if ("json".equals(FilenameUtils.getExtension(file.getName()))) {
                try {
                    String config = FileUtils.readFileToString(file);
                    if (validateConfig(config)) {
                        validConfigs.add(config);
                    }
                } catch (IOException e) {
                    logger.error(
                            "Unable to read one of the local config. Filename = [[" + file.getName() + "]]");
                }
            }
        }
    } catch (IOException e) {
        logger.error("Local override directory not found.");
    }

}

From source file:org.roda_project.commons_ip.utils.ZIPUtils.java

/**
 * @param source//from   w ww.java2s. c  o  m
 *          IP
 * @param destinationDirectory
 *          this path is only used if unzipping the SIP, otherwise source will
 *          be used
 * @param ipFileExtension
 *          file extension (e.g. .zip)
 */
public static Path extractIPIfInZipFormat(final Path source, Path destinationDirectory) throws ParseException {
    Path ipFolderPath = destinationDirectory;
    if (!Files.isDirectory(source)) {
        try {
            ZIPUtils.unzip(source, destinationDirectory);

            // 20161111 hsilva: see if the IP extracted has a folder which contains
            // the content of the IP (for being compliant with previous way of
            // creating SIP in ZIP format, this test/adjustment is needed)
            if (Files.exists(destinationDirectory)
                    && !Files.exists(destinationDirectory.resolve(IPConstants.METS_FILE))) {
                try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(destinationDirectory)) {
                    for (Path path : directoryStream) {
                        if (Files.isDirectory(path) && Files.exists(path.resolve(IPConstants.METS_FILE))) {
                            ipFolderPath = path;
                            break;
                        }
                    }
                }
            }
        } catch (IOException e) {
            LOGGER.error("Error unzipping file", e);
            throw new ParseException("Error unzipping file", e);
        }
    }

    return ipFolderPath;
}

From source file:org.lavajug.streamcaster.server.web.controllers.LiveStreamController.java

/**
 *
 *//* w ww. j a va 2s . c  o m*/
@GET("/index")
public void index() {

    LinkedList<String> devices = new LinkedList<>();
    Path devicesPath = Paths.get("/dev");

    try {
        for (Path device : Files.newDirectoryStream(devicesPath)) {
            if (device.getFileName().toString().startsWith("video")) {
                devices.addFirst(device.toAbsolutePath().toString());
            }
        }
    } catch (IOException ex) {
    }
    context.addParameter("isWindows", SystemUtils.IS_OS_WINDOWS);
    context.addParameter("devices", devices);
    context.addParameter("section", "LIVE");
    context.addParameter("current", Configuration.getCurrentProfile());
    render();
}

From source file:ch.eitchnet.csvrestendpoint.components.CsvDataHandler.java

public List<String> getCsvNames() {

    File csvDataDir = getCsvDataDir();
    if (!csvDataDir.isDirectory()) {
        logger.error("CSV Data Dir is not a directory at " + csvDataDir.getAbsolutePath());
        return Collections.emptyList();
    }/*from   w  w  w . j av a2s .c  o m*/

    try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(csvDataDir.toPath())) {

        List<String> names = new ArrayList<>();

        for (Iterator<Path> iter = directoryStream.iterator(); iter.hasNext();) {
            Path path = iter.next();
            String name = path.toFile().getName();
            if (name.endsWith(".csv"))
                names.add(name.substring(0, name.length() - 4));
        }

        return names;

    } catch (Exception e) {
        throw new RuntimeException("Failed to read CSV names due to " + e.getMessage());
    }
}

From source file:org.nuxeo.liveconnect.importer.filesystem.FSImporter.java

protected void importFolder(DocumentModel folder, Path inputPath) {
    try (DirectoryStream<Path> stream = Files.newDirectoryStream(inputPath)) {
        for (Path file : stream) {
            if (!Files.isDirectory(file)) {
                importFile(folder, file);
            } else {
                importFolder(folder, file);
            }/*from ww  w  . j ava2s  .com*/
        }
    } catch (IOException | DirectoryIteratorException e) {
        throw new NuxeoException(e);
    }
}

From source file:io.fabric8.profiles.ProfilesHelpers.java

public static void recusivelyCollectFileListing(ArrayList<String> rc, Path base, Path directory)
        throws IOException {
    try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(directory)) {
        for (Path path : directoryStream) {
            if (Files.isDirectory(path)) {
                recusivelyCollectFileListing(rc, base, path);
            } else {
                rc.add(base.relativize(path).toString());
            }//from   w ww. j  a v  a  2s.co m
        }
    }
}