Example usage for org.apache.commons.io FileUtils listFiles

List of usage examples for org.apache.commons.io FileUtils listFiles

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils listFiles.

Prototype

public static Collection listFiles(File directory, String[] extensions, boolean recursive) 

Source Link

Document

Finds files within a given directory (and optionally its subdirectories) which match an array of extensions.

Usage

From source file:com.freedomotic.plugins.TrackingReadFile.java

@Override
public void onStart() throws PluginStartupException {
    try {/* www  . ja  va2s  .com*/
        workers = new ArrayList<WorkerThread>();

        File dir = new File(Info.PATHS.PATH_DEVICES_FOLDER + "/simulation/data/motes");
        String[] extensions = new String[] { "mote" };
        LOG.info("Getting all .mote files in {}", dir.getCanonicalPath());
        List<File> motes = (List<File>) FileUtils.listFiles(dir, extensions, true);
        if (!motes.isEmpty()) {
            for (File file : motes) {
                switch (DATA_TYPE) {
                case "coordinates":
                    readMoteFileCoordinates(file);
                    break;
                case "rooms":
                    readMoteFileRooms(file);
                    break;
                default:
                    throw new PluginStartupException("<data-type> property wrong in manifest file");
                }
            }
            for (WorkerThread workerThread : workers) {
                workerThread.start();
            }
        } else {
            throw new PluginStartupException("No .mote files found.");
        }
    } catch (IOException ex) {
        throw new PluginStartupException("Error during file .motes loading." + ex.getMessage(), ex);
    }
}

From source file:com.aionemu.gameserver.dataholders.DataLoader.java

/**
 * This method is supposed to be called from subclass to initialize data
 * loading process.<br>//  w  ww  .ja  v a  2  s. c  om
 * <br>
 * This method is using file given in the constructor to load the data and
 * there are two possibilities:
 * <ul>
 * <li>Given file is file is in deed the <b>file</b> then it's forwarded to
 * {@link #loadFile(File)} method</li>
 * <li>Given file is a <b>directory</b>, then this method is obtaining list
 * of all visible .txt files in this directory and subdirectiores ( except
 * hidden ones and those named "new" ) and call {@link #loadFile(File)} for
 * each of these files.
 * </ul>
 */
@SuppressWarnings("deprecation")
protected void loadData() {
    if (dataFile.isDirectory()) {
        Collection<?> files = FileUtils
                .listFiles(dataFile,
                        FileFilterUtils
                                .andFileFilter(
                                        FileFilterUtils.andFileFilter(
                                                FileFilterUtils
                                                        .notFileFilter(FileFilterUtils.nameFileFilter("new")),
                                                FileFilterUtils.suffixFileFilter(".txt")),
                                        HiddenFileFilter.VISIBLE),
                        HiddenFileFilter.VISIBLE);

        for (Object file1 : files) {
            File f = (File) file1;
            loadFile(f);
        }
    } else {
        loadFile(dataFile);
    }
}

From source file:it.geosolutions.geobatch.nrl.csvingest.CSVIngestActionTest.java

@Test
public void laodAll() throws Exception {

    createCropDescriptors();/*from w  ww.  java2 s . co  m*/

    Queue<EventObject> events = new LinkedList<EventObject>();
    File dir = loadFile("all");
    assertNotNull(dir);
    assertTrue(dir.isDirectory());

    CSVIngestAction action = new CSVIngestAction(new CSVIngestConfiguration(null, null, null));
    action.setCropDataDao(cropDataDAO);
    action.setCropDescriptorDao(cropDescriptorDAO);
    action.setAgrometDao(agrometDAO);
    action.afterPropertiesSet();

    for (File file : FileUtils.listFiles(dir, new String[] { "csv" }, true)) {
        FileSystemEvent event = new FileSystemEvent(file, FileSystemEventType.FILE_ADDED);
        events.add(event);
        Queue result = action.execute(events);
    }

}

From source file:com.denimgroup.threadfix.framework.impl.dotNetWebForm.WebFormsEndpointGenerator.java

private List<AspxParser> getAspxParsers(File rootDirectory, Map<String, AscxFile> map,
        Map<String, AspxParser> masterFileMap) {
    Collection aspxFiles = FileUtils.listFiles(rootDirectory, new FileExtensionFileFilter("aspx"),
            TrueFileFilter.INSTANCE);//  www. j  av a2  s  .  c o  m

    List<AspxParser> aspxParsers = list();

    for (Object aspxFile : aspxFiles) {
        if (aspxFile instanceof File) {
            File file = (File) aspxFile;

            AspxParser aspxParser = AspxParser.parse(file);
            AspxUniqueIdParser uniqueIdParser = AspxUniqueIdParser.parse(file, map);

            if (masterFileMap.containsKey(uniqueIdParser.masterPage)) {
                aspxParser.parameters.addAll(masterFileMap.get(uniqueIdParser.masterPage).parameters);
            }

            aspxParser.parameters.addAll(uniqueIdParser.parameters);
            aspxParsers.add(aspxParser);
        }
    }
    return aspxParsers;
}

From source file:com.ibm.soatf.tool.Utils.java

/**
 * Deletes the directory contents recursively, deletes directories if <code>filesOnly</code> is <code>false</code>
 * @param rootDir the directory which contents you want to remove
 * @param filesOnly if true, keeps directories, deletes only files
 * @throws IOException /* ww w .  ja  va  2  s . c om*/
 */
public static void deleteDirContent(File rootDir, boolean filesOnly) throws IOException {
    if (!rootDir.isDirectory()) {
        return;
    }
    if (filesOnly) {
        Collection<File> files = FileUtils.listFiles(rootDir, FileFilterUtils.fileFileFilter(),
                FileFilterUtils.directoryFileFilter());
        for (File file : files) {
            if (file.isDirectory()) {
                deleteDirContent(file, filesOnly);
            } else {
                boolean success = file.delete();
                logger.trace("Deleting file " + file.getName() + ": " + (success ? "Success" : "Failure"));
            }
        }
    } else {
        for (File file : rootDir.listFiles()) {
            if (file.isDirectory()) {
                FileUtils.deleteDirectory(file);
            } else {
                boolean success = file.delete();
                logger.trace("Deleting file " + file.getName() + ": " + (success ? "Success" : "Failure"));
            }
        }
    }
}

From source file:com.offbynull.coroutines.mavenplugin.AbstractInstrumentMojo.java

/**
 * Creates an {@link Instrumenter} instance.
 * @param log maven logger/*from  w  w  w . j  a  va2s .com*/
 * @param classpath classpath for classes being instrumented
 * @return a new {@link Instrumenter}
 * @throws MojoExecutionException if any exception occurs
 */
protected final Instrumenter getInstrumenter(Log log, List<String> classpath) throws MojoExecutionException {
    List<File> classpathFiles;
    try {
        log.debug("Getting compile classpath");
        classpathFiles = classpath.stream().map(x -> new File(x)).collect(Collectors.toList());
        log.debug("Getting bootstrap classpath");
        classpathFiles.addAll(FileUtils.listFiles(new File(jdkLibsDirectory), new String[] { "jar" }, true));

        log.info("Classpath for instrumentation is as follows: " + classpathFiles);
    } catch (Exception ex) {
        throw new MojoExecutionException("Unable to get compile classpath elements", ex);
    }

    log.info("Creating instrumenter...");

    try {
        return new Instrumenter(classpathFiles);
    } catch (Exception ex) {
        throw new MojoExecutionException("Unable to create instrumenter", ex);
    }
}

From source file:com.baasbox.service.dbmanager.DbManagerService.java

public static List<String> getExports() {
    java.io.File dir = new java.io.File(backupDir);
    if (!dir.exists()) {
        dir.mkdirs();//from  ww w.  j  a v  a2 s  . c  o  m
    }
    Collection<java.io.File> files = FileUtils.listFiles(dir, new String[] { "zip" }, false);
    File[] fileArr = files.toArray(new File[files.size()]);

    Arrays.sort(fileArr, LastModifiedFileComparator.LASTMODIFIED_REVERSE);

    List<String> fileNames = new ArrayList<String>();
    for (java.io.File file : fileArr) {
        fileNames.add(file.getName());
    }
    return fileNames;
}

From source file:com.scaniatv.LangFileUpdater.java

/**
 * Method that gets a list of all lang files.
 * /*  w  w  w  .  j  av a  2 s.  c  o m*/
 * @return 
 */
public static String[] getLangFiles() {
    Collection<File> files = FileUtils.listFiles(new File(DEFAULT_LANG_ROOT), TrueFileFilter.INSTANCE,
            TrueFileFilter.INSTANCE);
    ArrayList<String> fileNames = new ArrayList<>();

    String sep = File.separator;

    files.forEach((File file) -> {
        fileNames.add(file.getPath().replace("." + sep + "scripts" + sep + "lang" + sep + "english" + sep, ""));
    });

    return fileNames.toArray(new String[fileNames.size()]);
}

From source file:com.linkedin.pinot.filesystem.LocalPinotFS.java

@Override
public String[] listFiles(URI fileUri) throws IOException {
    File file = new File(fileUri);
    Collection<File> files = FileUtils.listFiles(file, null, true);
    return files.stream().map(File::getPath).toArray(String[]::new);
}

From source file:averroes.JarFile.java

/**
 * Add all the generated class files to the Jar file.
 * //from   w  ww.j a  v a 2 s . co  m
 * @throws IOException
 */
public void addGeneratedLibraryClassFiles() throws IOException {
    Set<String> classFiles = new HashSet<String>();
    File dir = Paths.libraryClassesOutputDirectory();
    File placeholderJar = Paths.placeholderLibraryJarFile();

    // Add the class files to the crafted JAR file.
    FileUtils.listFiles(dir, new String[] { "class" }, true).stream()
            .filter(f -> !relativize(dir, f).equals(Names.AVERROES_LIBRARY_CLASS_BC_SIG + ".class"))
            .forEach(file -> {
                try {
                    String className = relativize(dir, file);
                    add(dir, file);
                    classFiles.add(className);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            });
    close();

    // Now add all those class files in the crafted JAR file to the BCEL
    // repository.
    for (String classFile : classFiles) {
        ClassParser parser = new ClassParser(placeholderJar.getPath(), classFile);
        JavaClass cls = parser.parse();
        bcelClasses.add(cls);
    }
}