Example usage for java.io FilenameFilter FilenameFilter

List of usage examples for java.io FilenameFilter FilenameFilter

Introduction

In this page you can find the example usage for java.io FilenameFilter FilenameFilter.

Prototype

FilenameFilter

Source Link

Usage

From source file:pt.lsts.neptus.util.bathymetry.TidCachedData.java

public static void convertTideTxtIntoTid() {
    String path = ConfigFetch.getConfFolder() + "/tides";
    File tidesFolder = new File(path);
    File[] txtFiles = tidesFolder.listFiles(new FilenameFilter() {
        @Override//from   w  ww .  java  2 s  .  c  o  m
        public boolean accept(File dir, String name) {
            return FileUtil.checkFileForExtensions(name, "txt") != null;
        }
    });

    for (File txtFx : txtFiles) {
        CachedData txtData = new CachedData(txtFx);

        String tidFP = FileUtil.replaceFileExtension(txtFx.getAbsolutePath(), "tid");
        File tidFx = new File(tidFP);
        TidCachedData tidData = new TidCachedData(tidFx);
        tidData.update(txtData.getTidePeaks());
        try {
            tidData.saveFile(txtData.getName(), tidFx);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:com.l.notel.notel.org.redpin.android.util.ExceptionReporter.java

/**
 * Search for stack trace files.//w ww  . j a  v  a 2 s . c om
 * 
 * @return
 */
private static String[] searchForStackTraces() {
    if (stackTraceFileList != null) {
        return stackTraceFileList;
    }
    File dir = new File(E.FILES_PATH + "/");
    // Try to create the files folder if it doesn't exist
    dir.mkdir();
    // Filter for ".stacktrace" files
    FilenameFilter filter = new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.endsWith(".stacktrace");
        }
    };
    return (stackTraceFileList = dir.list(filter));
}

From source file:com.chaordicsystems.sstableconverter.SSTableConverter.java

public static Collection<SSTableReader> readSSTables(final IPartitioner srcPartitioner, File srcDir,
        final CFMetaData metadata, final OutputHandler outputHandler) {
    final List<SSTableReader> sstables = new ArrayList<SSTableReader>();
    srcDir.list(new FilenameFilter() {
        public boolean accept(File dir, String name) {
            if (new File(dir, name).isDirectory())
                return false;
            Pair<Descriptor, Component> p = SSTable.tryComponentFromFilename(dir, name);
            Descriptor desc = p == null ? null : p.left;
            if (p == null || !p.right.equals(Component.DATA) || desc.temporary)
                return false;

            if (!new File(desc.filenameFor(Component.PRIMARY_INDEX)).exists()) {
                outputHandler.output(String.format("Skipping file %s because index is missing", name));
                return false;
            }/*from  w w  w.  j  a  va  2  s  . c  om*/

            Set<Component> components = new HashSet<Component>();
            components.add(Component.DATA);
            components.add(Component.PRIMARY_INDEX);
            if (new File(desc.filenameFor(Component.COMPRESSION_INFO)).exists())
                components.add(Component.COMPRESSION_INFO);
            if (new File(desc.filenameFor(Component.STATS)).exists())
                components.add(Component.STATS);

            try {
                sstables.add(SSTableReader.openForBatch(desc, components, srcPartitioner, metadata));
            } catch (IOException e) {
                outputHandler
                        .output(String.format("Skipping file %s, error opening it: %s", name, e.getMessage()));
            }
            return false;
        }
    });
    return sstables;
}

From source file:eu.sisob.uma.crawler.ResearchersCrawlerTask.java

public void executeTask() {
    if (middledata_dir == null) {
        middledata_dir = new File(System.getProperty("java.io.tmpdir"));
    } else {/* w  w  w  .  j a  v  a2s  . c  o  m*/
        if (!middledata_dir.exists())
            middledata_dir.mkdirs();
    }

    if (this.split) {
        File splitted_xml_dir = new File(middledata_dir, SPLITTED_XML_FILES_FOLDERNAME);

        ResearcherXMLFileSplitter splitter = new ResearcherXMLFileSplitter(this.document, splitted_xml_dir,
                SPLITTED_PREFIX);
        try {
            splitter.iterate();
        } catch (Exception ex) {
            ProjectLogger.LOGGER.error(ex.getMessage(), ex);
        }

        FilenameFilter filter = new FilenameFilter() {
            public boolean accept(File dir, String name) {

                if (name.startsWith(SPLITTED_PREFIX)) {
                    return true;
                } else {
                    return false;
                }
            }
        };

        File[] files = splitted_xml_dir.listFiles(filter);
        for (File file : files) {
            org.dom4j.io.SAXReader reader = new org.dom4j.io.SAXReader();
            org.dom4j.Document new_doc = null;

            try {
                new_doc = reader.read(file);
            } catch (DocumentException ex) {
                ProjectLogger.LOGGER.error(ex.getMessage(), ex);
                new_doc = null;
            }

            if (new_doc != null) {
                AirResearchersWebPagesExtractor o = new AirResearchersWebPagesExtractor(new_doc,
                        keywordsdata_dir, middledata_dir, split);
                try {
                    ProjectLogger.LOGGER.info("Begin Crawl - " + file.getName());
                    o.iterate();
                } catch (Exception ex) {
                    ProjectLogger.LOGGER.error(ex.getMessage(), ex);
                } finally {
                    ProjectLogger.LOGGER.info("End Crawl" + file.getName());
                }

                try {
                    FileUtils.write(file, new_doc.asXML(), "UTF-8");
                    ProjectLogger.LOGGER.info("Updated file '" + file.getPath() + "'");
                } catch (IOException ex) {
                    ProjectLogger.LOGGER.error("Split file cannot be updated '" + file.getPath() + "'", ex);
                }
            } else {
                ProjectLogger.LOGGER.error("Split file cannot be openend '" + file.getPath() + "'");
            }
        }
    } else {
        AirResearchersWebPagesExtractor o = new AirResearchersWebPagesExtractor(document, keywordsdata_dir,
                middledata_dir, split);
        try {
            ProjectLogger.LOGGER.info("Begin Crawl - " + middledata_dir.getName());
            o.iterate();
        } catch (Exception ex) {
            ProjectLogger.LOGGER.error(ex.getMessage(), ex);
        } finally {
            ProjectLogger.LOGGER.info("End Crawl");
        }

        if (middledata_dir == null) {
            ProjectLogger.LOGGER.error("Something was wrong. Temporal directory is not set.");
        } else {
            try {
                File fField = new File(middledata_dir, MIDDLE_XML_DOCUMENT);
                FileUtils.write(fField, this.document.asXML(), "UTF-8");
                ProjectLogger.LOGGER.info(fField.getAbsoluteFile() + " created.");
            } catch (IOException ex) {
                ProjectLogger.LOGGER.error(ex.getMessage(), ex);
            }
        }

    }
}

From source file:eu.openanalytics.rsb.config.BootstrapConfigurationServletContextListener.java

private void copyUiFragments(final ServletContext servletContext) {
    final File fragmentsSourceDirectory = new File(ConfigurationFactory.RSB_CONFIGURATION_DIRECTORY,
            "fragments");
    if (!fragmentsSourceDirectory.isDirectory()) {
        return;//  ww w. ja v  a2 s.c  o  m
    }

    final String fragmentsDestinationPath = servletContext.getRealPath("/fragments");
    if (StringUtils.isBlank(fragmentsDestinationPath)) {
        return;
    }

    final File fragmentsDestinationDirectory = new File(fragmentsDestinationPath);

    final File[] sourceFragments = fragmentsSourceDirectory.listFiles(new FilenameFilter() {
        @Override
        public boolean accept(final File dir, final String name) {
            return StringUtils.endsWith(name, ".html");
        }
    });

    if (sourceFragments == null) {
        return;
    }

    for (final File sourceFragment : sourceFragments) {
        final File destinationFragment = new File(fragmentsDestinationDirectory, sourceFragment.getName());

        try {
            FileCopyUtils.copy(sourceFragment, destinationFragment);
            LOGGER.info("Installed UI fragment: " + sourceFragment.getName());
        } catch (final IOException ioe) {
            LOGGER.error("Failed to copy UI fragment from: " + sourceFragment + " to: " + destinationFragment,
                    ioe);
        }
    }
}

From source file:interactivespaces.launcher.bootstrap.ExtensionsReader.java

/**
 * Add all extension classpath entries that the controller specifies.
 *
 * @param extensionsFolder/*  w ww  . ja  va2  s . c  om*/
 *          the folder which contains the extension files
 */
public void processExtensionFiles(File extensionsFolder) {
    File[] extensionFiles = extensionsFolder.listFiles(new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            return name.endsWith(EXTENSION_FILE_EXTENSION);
        }
    });
    if (extensionFiles == null || extensionFiles.length == 0) {
        return;
    }

    for (File extensionFile : extensionFiles) {
        processExtensionFile(extensionFile);
    }

    log.info(String.format("Extensions have added the following Java packages: %s", packages));
    log.info(String.format("Extensions have added the following classes to be loaded automatically: %s",
            loadClasses));
    log.info(String.format("Extensions have loaded the following native libraries: %s ", loadLibraries));
    log.info(String.format("Extensions have loaded the following container path items: %s ", containerPath));
}

From source file:com.payne.file.FileDelete.java

public boolean deleteFileByFilter(File filePath, final String filter) {
    boolean result = false;
    if (filePath.isDirectory()) {
        File[] listFiles = filePath.listFiles(new FilenameFilter() {

            @Override/*from  w ww . j  a  v  a  2 s  .  co m*/
            public boolean accept(File dir, String name) {
                if (dir != null && name.contains(filter)) {
                    return true; // ??
                } else {
                    return false; //
                }
            }
        });
        if (listFiles.length > 0) {
            for (File file : listFiles) {
                result = delFile(file);
                if (!result) {
                    System.out.println("??" + file.getName());
                    break;
                }
            }
        } else {
            result = true;
        }
    } else if (filePath.isFile()) {
        if (filePath.getName().contains(filter)) {
            result = filePath.delete();
        }
    }
    return result;
}

From source file:com.netflix.ice.basic.MapDb.java

void upload() {
    AmazonS3Client s3Client = AwsUtils.getAmazonS3Client();

    File dir = new File(config.localDir);
    File[] files = dir.listFiles(new FilenameFilter() {
        public boolean accept(File file, String fileName) {
            return fileName.startsWith(dbName);
        }//w w  w  .  ja  v  a2 s  .  c o  m
    });
    for (File file : files)
        s3Client.putObject(config.workS3BucketName, config.workS3BucketPrefix + file.getName(), file);

    for (File file : files)
        s3Client.putObject(config.workS3BucketName, config.workS3BucketPrefix + "copy" + file.getName(), file);
}

From source file:com.jeffthefate.stacktrace.ExceptionHandler.java

/**
 * Search for stack trace files.//from  w ww . j a v a2s.  c  om
 * @return
 */
private static String[] searchForStackTraces() {
    if (stackTraceFileList != null)
        return stackTraceFileList;
    File dir = new File(G.FILES_PATH + "/");
    // Try to create the files folder if it doesn't exist
    dir.mkdir();
    // Filter for ".stacktrace" files
    FilenameFilter filter = new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.endsWith(".stacktrace");
        }
    };
    return (stackTraceFileList = dir.list(filter));
}

From source file:ws.doerr.cssinliner.server.InlinerApp.java

private InlinerApp(Path sourceFolder, Path dataFolder) throws Exception {
    TempFolder workingFolder = new TempFolder("cssinline");

    // Start the Http Server
    Server.start(getClass().getPackage().getName());
    Server.registerWebsocket("/connect");

    // Setup Handlebars
    FileTemplateLoader loader = new FileTemplateLoader(workingFolder.getFile());
    loader.setSuffix("");
    handlebars = new Handlebars(loader);

    EmailService.get().getHelpers().forEach((tag, helper) -> {
        handlebars.registerHelper(tag, helper);
    });/*from w w  w  .  ja  v  a  2 s .c  o m*/

    // List all the source files from the folder
    File[] files = sourceFolder.toFile().listFiles(new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            return name.endsWith(".html");
        }
    });

    for (File file : files) {
        try {
            SourceInstance instance = new SourceInstance(file.toPath(), dataFolder, workingFolder.getPath());
            InlinerContext context = inliner.process(instance.getSource(), instance.getInlined());
            instance.update(context);

            processHandlebars(instance);

            getDocumentTitle(instance);

            sources.put(instance.getId(), instance);

            pathToInstance.put(file.toPath().normalize().toString(), instance.getId());

            instance.getDependencies().forEach((dependency) -> {
                pathToInstance.put(dependency.getPath().normalize().toString(), instance.getId());
                folders.add(dependency.getPath().normalize().getParent().toString());
            });

            pathToInstance.put(instance.getData().toString(), instance.getId());
        } catch (Exception ex) {

        }
    }

    // Register the folder for change events
    Monitor.getInstance().register(sourceHandler, sourceFolder);
    Monitor.getInstance().register(dataHandler, dataFolder);

    folders.forEach(folder -> {
        Path f = Paths.get(folder);
        Monitor.getInstance().register(dependencyHandler, f);
    });
}