Example usage for org.apache.commons.io.filefilter SuffixFileFilter SuffixFileFilter

List of usage examples for org.apache.commons.io.filefilter SuffixFileFilter SuffixFileFilter

Introduction

In this page you can find the example usage for org.apache.commons.io.filefilter SuffixFileFilter SuffixFileFilter.

Prototype

public SuffixFileFilter(List suffixes) 

Source Link

Document

Constructs a new Suffix file filter for a list of suffixes.

Usage

From source file:com.hurence.logisland.processor.DetectOutliersTest.java

@Test
@Ignore("too long")
public void testDetection() throws IOException {
    final TestRunner testRunner = TestRunners.newTestRunner(new DetectOutliers());
    testRunner.setProperty(DetectOutliers.ROTATION_POLICY_TYPE, "by_amount");
    testRunner.setProperty(DetectOutliers.ROTATION_POLICY_AMOUNT, "100");
    testRunner.setProperty(DetectOutliers.ROTATION_POLICY_UNIT, "points");
    testRunner.setProperty(DetectOutliers.CHUNKING_POLICY_TYPE, "by_amount");
    testRunner.setProperty(DetectOutliers.CHUNKING_POLICY_AMOUNT, "10");
    testRunner.setProperty(DetectOutliers.CHUNKING_POLICY_UNIT, "points");
    testRunner.setProperty(DetectOutliers.GLOBAL_STATISTICS_MIN, "-100000");
    testRunner.setProperty(DetectOutliers.MIN_AMOUNT_TO_PREDICT, "100");
    testRunner.setProperty(DetectOutliers.ZSCORE_CUTOFFS_NORMAL, "3.5");
    testRunner.setProperty(DetectOutliers.ZSCORE_CUTOFFS_MODERATE, "5");

    testRunner.setProperty(DetectOutliers.RECORD_VALUE_FIELD, "value");
    testRunner.setProperty(DetectOutliers.RECORD_TIME_FIELD, "timestamp");
    testRunner.assertValid();/* w w w .  j a v a 2s.c  o  m*/

    File f = new File(RESOURCES_DIRECTORY);

    Pair<Integer, Integer>[] results = new Pair[] { new Pair(4032, 124), new Pair(4032, 8), new Pair(4032, 315),
            new Pair(4032, 0), new Pair(4032, 29), new Pair(4032, 2442), new Pair(4032, 314),
            new Pair(4032, 296)

    };

    int count = 0;
    for (File file : FileUtils.listFiles(f, new SuffixFileFilter(".csv"), TrueFileFilter.INSTANCE)) {

        if (count >= results.length)
            break;

        BufferedReader reader = Files.newBufferedReader(file.toPath(), ENCODING);
        List<Record> records = TimeSeriesCsvLoader.load(reader, true, inputDateFormat);
        Assert.assertTrue(!records.isEmpty());

        testRunner.clearQueues();
        testRunner.enqueue(records.toArray(new Record[records.size()]));
        testRunner.run();
        testRunner.assertAllInputRecordsProcessed();

        System.out.println("records.size() = " + records.size());
        System.out.println("testRunner.getOutputRecords().size() = " + testRunner.getOutputRecords().size());
        testRunner.assertOutputRecordsCount(results[count].getSecond());
        count++;

    }

}

From source file:com.simpligility.maven.provisioner.MavenRepositoryHelper.java

public void deployToRemote(String targetUrl, String username, String password) {
    // Using commons-io, if performance or so is a problem it might be worth looking at the Java 8 streams API
    // e.g. http://blog.jooq.org/2014/01/24/java-8-friday-goodies-the-new-new-io-apis/
    // not yet though..
    Collection<File> subDirectories = FileUtils.listFilesAndDirs(repositoryPath,
            (IOFileFilter) DirectoryFileFilter.DIRECTORY, TrueFileFilter.INSTANCE);
    Collection<File> leafDirectories = new ArrayList<File>();
    for (File subDirectory : subDirectories) {
        if (isLeafVersionDirectory(subDirectory)) {

            leafDirectories.add(subDirectory);
        }// www. jav a 2  s.  c  o  m
    }
    for (File leafDirectory : leafDirectories) {
        String leafAbsolutePath = leafDirectory.getAbsoluteFile().toString();
        int repoAbsolutePathLength = repositoryPath.getAbsoluteFile().toString().length();
        String leafRepoPath = leafAbsolutePath.substring(repoAbsolutePathLength + 1, leafAbsolutePath.length());

        Gav gav = GavUtil.getGavFromRepositoryPath(leafRepoPath);

        // only interested in files using the artifactId-version* pattern
        // don't bother with .sha1 files
        IOFileFilter fileFilter = new AndFileFilter(
                new WildcardFileFilter(gav.getArtifactId() + "-" + gav.getVersion() + "*"),
                new NotFileFilter(new SuffixFileFilter("sha1")));
        Collection<File> artifacts = FileUtils.listFiles(leafDirectory, fileFilter, null);

        Authentication auth = new AuthenticationBuilder().addUsername(username).addPassword(password).build();

        RemoteRepository distRepo = new RemoteRepository.Builder("repositoryIdentifier", "default", targetUrl)
                .setAuthentication(auth).build();

        DeployRequest deployRequest = new DeployRequest();
        deployRequest.setRepository(distRepo);
        for (File file : artifacts) {
            String extension;
            if (file.getName().endsWith("tar.gz")) {
                extension = "tar.gz";
            } else {
                extension = FilenameUtils.getExtension(file.getName());
            }

            String baseFileName = gav.getFilenameStart() + "." + extension;
            String fileName = file.getName();
            String g = gav.getGroupdId();
            String a = gav.getArtifactId();
            String v = gav.getVersion();

            Artifact artifact = null;
            if (gav.getPomFilename().equals(fileName)) {
                artifact = new DefaultArtifact(g, a, "pom", v);
            } else if (gav.getJarFilename().equals(fileName)) {
                artifact = new DefaultArtifact(g, a, "jar", v);
            } else if (gav.getSourceFilename().equals(fileName)) {
                artifact = new DefaultArtifact(g, a, "sources", "jar", v);
            } else if (gav.getJavadocFilename().equals(fileName)) {
                artifact = new DefaultArtifact(g, a, "javadoc", "jar", v);
            } else if (baseFileName.equals(fileName)) {
                artifact = new DefaultArtifact(g, a, extension, v);
            } else {
                String classifier = file.getName().substring(gav.getFilenameStart().length() + 1,
                        file.getName().length() - ("." + extension).length());
                artifact = new DefaultArtifact(g, a, classifier, extension, v);
            }

            if (artifact != null) {
                artifact = artifact.setFile(file);
                deployRequest.addArtifact(artifact);
            }

        }

        try {
            system.deploy(session, deployRequest);
        } catch (Exception e) {
            logger.info("Deployment failed with " + e.getMessage() + ", artifact might be deployed already.");
        }
    }
}

From source file:bear.main.JavaCompiler2.java

public List<File> compileScripts(File sourcesDir) {
    FileFilter filter = new SuffixFileFilter(extensions);

    final File[] files = sourcesDir.listFiles(filter);

    final ArrayList<String> params = newArrayListWithExpectedSize(files.length);

    if (!buildDir.exists()) {
        buildDir.mkdir();/*from ww w  . j  a  v  a 2 s  .  co  m*/
    }

    Collections.addAll(params, "-d", buildDir.getAbsolutePath());
    List<File> javaFilesList = newArrayList(files);

    List<File> filesListToCompile = ImmutableList.copyOf(Iterables.filter(javaFilesList, new Predicate<File>() {
        @Override
        public boolean apply(File javaFile) {
            File classFile = new File(buildDir, FilenameUtils.getBaseName(javaFile.getName()) + ".class");

            boolean upToDate = classFile.exists() && classFile.lastModified() > javaFile.lastModified();

            if (upToDate) {
                logger.info("{} is up-to-date", javaFile);
            }

            return !upToDate;
        }
    }));

    if (filesListToCompile.isEmpty()) {
        logger.info("all files are up-to-date");
        return javaFilesList;
    }

    final List<String> filePaths = Lists.transform(filesListToCompile, new Function<File, String>() {
        public String apply(File input) {
            return input.getAbsolutePath();
        }
    });

    params.addAll(filePaths);

    logger.info("compiling {}", params);

    final JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();

    final int r = compiler.run(null, null, null, params.toArray(new String[params.size()]));

    if (r == 0) {
        logger.info("compilation OK.");
    } else {
        logger.info("compilation failed.");
    }

    return javaFilesList;
}

From source file:algorithm.F5Steganography.java

@Override
SuffixFileFilter configureCarrierFileFilter() {
    List<String> supportedFileFormats = new ArrayList<String>();
    supportedFileFormats.add("jpg");
    supportedFileFormats.add("tif");
    supportedFileFormats.add("gif");
    supportedFileFormats.add("bmp");
    return new SuffixFileFilter(supportedFileFormats);
}

From source file:com.norconex.jefmon.settings.panels.JobLocationsPanel.java

public JobLocationsPanel(String id, JEFMonConfig dirtyConfig) {
    super(id, dirtyConfig);
    setOutputMarkupId(true);//from   w ww  . ja  va2s  . c om

    if (dirtyConfig.getMonitoredPaths() != null) {
        locations.addAll(Arrays.asList(dirtyConfig.getMonitoredPaths()));
    }
    formWrapper.setOutputMarkupId(true);
    add(formWrapper);

    // --- Locations Select ---
    locationsSelect = buildLocationsSelect("locations");
    formWrapper.add(locationsSelect);

    // --- Remove ---
    removeButton = new WebMarkupContainer("removeButton");
    removeButton.setOutputMarkupId(true);
    removeButton.add(new OnClickBehavior() {
        private static final long serialVersionUID = 2072304873075922291L;

        @Override
        protected void onClick(AjaxRequestTarget target) {
            Collection<File> files = locationsSelect.getModelObject();
            locations.removeAll(files);
            locationsSelect.setChoices(locations);
            removeButton.setVisible(false);
            target.add(formWrapper);
        }
    });
    removeButton.setVisible(false);
    formWrapper.add(removeButton);

    // --- Add File ---
    IOFileFilter validationFilter = new SuffixFileFilter(".index");
    FilenameFilter browseFilter = new OrFileFilter(DirectoryFileFilter.DIRECTORY, validationFilter);
    BootstrapFileSystemDialog fileDialog = new BootstrapFileSystemDialog("addFileModal",
            new ResourceModel("location.dlg.file"), browseFilter, true) {
        private static final long serialVersionUID = 831482258795791951L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, File[] files) {
            addFileToSelect(target, files);
        }
    };
    fileDialog.setSelectionValidator(validationFilter);
    add(fileDialog);
    WebMarkupContainer addFileButton = new WebMarkupContainer("addFileButton");
    addFileButton.add(new BootstrapModalLauncher(fileDialog));
    formWrapper.add(addFileButton);

    // --- Add Folder ---
    BootstrapFileSystemDialog folderDialog = new BootstrapFileSystemDialog("addFolderModal",
            new ResourceModel("location.dlg.dir"), DirectoryFileFilter.DIRECTORY, true) {
        private static final long serialVersionUID = -6453512318897096749L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, File[] files) {
            addFileToSelect(target, files);
        }
    };
    folderDialog.setSelectionValidator(DirectoryFileFilter.DIRECTORY);
    add(folderDialog);
    WebMarkupContainer addFolderButton = new WebMarkupContainer("addFolderButton");
    addFolderButton.add(new BootstrapModalLauncher(folderDialog));
    formWrapper.add(addFolderButton);

}

From source file:algorithm.BagItPackaging.java

@Override
SuffixFileFilter configureDecapsulationFileFilter() {
    List<String> supportedFileFormats = new ArrayList<String>();
    supportedFileFormats.add("_BAG.zip");
    return new SuffixFileFilter(supportedFileFormats);
}

From source file:algorithm.PNGChunkAdding.java

@Override
SuffixFileFilter configureCarrierFileFilter() {
    ArrayList<String> supportedFormats = new ArrayList<String>();
    supportedFormats.add("PNG");
    supportedFormats.add("png");
    return new SuffixFileFilter(supportedFormats);
}

From source file:algorithm.F5Steganography.java

@Override
SuffixFileFilter configurePayloadFileFilter() {
    List<String> supportedFileFormats = new ArrayList<String>();
    supportedFileFormats.add("txt");
    supportedFileFormats.add("xml");
    return new SuffixFileFilter(supportedFileFormats);
}

From source file:com.orange.mmp.dao.flf.MidletDaoFlfImpl.java

public Midlet[] find(Midlet midlet) throws MMPDaoException {
    if (midlet == null) {
        throw new MMPDaoException("missing or bad data access object");
    }/*from w w w.  j a va  2 s .c om*/

    FilenameFilter jadFilter = new SuffixFileFilter(".jad");
    FilenameFilter jarFilter = new SuffixFileFilter(".jar");
    Midlet[] midlets = null;
    ArrayList<Midlet> midletList = new ArrayList<Midlet>();

    try {
        File midletFolder = new File(this.path);
        for (File typeFolder : midletFolder.listFiles()) {
            if (midlet.getType() == null || midlet.getType().equals(typeFolder.getName())) {
                File[] jadFiles = typeFolder.listFiles(jadFilter);
                File[] jarFiles = typeFolder.listFiles(jarFilter);
                if (jadFiles != null && jadFiles.length > 0 && jarFiles != null && jarFiles.length > 0) {
                    JadFile jadFile = new JadFile();
                    jadFile.load(jadFiles[0]);
                    if (midlet.getVersion() == null
                            || jadFile.getValue(Constants.JAD_PARAMETER_VERSION).equals(midlet.getVersion())) {
                        Midlet newPFM = new Midlet();
                        newPFM.setType(typeFolder.getName());
                        newPFM.setVersion(new Version(jadFile.getValue(Constants.JAD_PARAMETER_VERSION)));
                        newPFM.setJadLocation(jadFiles[0].toURI().toString());
                        newPFM.setJarLocation(jarFiles[0].toURI().toString());
                        midletList.add(newPFM);
                    }
                }
            }
        }
    } catch (IOException ioe) {
        throw new MMPDaoException("failed to find PFM : " + ioe.getMessage());
    }

    midlets = new Midlet[midletList.size()];
    return midletList.toArray(midlets);
}

From source file:algorithm.PNGChunkAdding.java

@Override
SuffixFileFilter configurePayloadFileFilter() {
    ArrayList<String> supportedFormats = new ArrayList<String>();
    supportedFormats.add("txt");
    supportedFormats.add("json");
    supportedFormats.add("xml");
    return new SuffixFileFilter(supportedFormats);
}