Example usage for org.apache.commons.io.filefilter TrueFileFilter INSTANCE

List of usage examples for org.apache.commons.io.filefilter TrueFileFilter INSTANCE

Introduction

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

Prototype

IOFileFilter INSTANCE

To view the source code for org.apache.commons.io.filefilter TrueFileFilter INSTANCE.

Click Source Link

Document

Singleton instance of true filter.

Usage

From source file:cross.io.InputDataFactory.java

/**
 * Create a collection of files from the given string resource paths.
 *
 * @param input the string resource paths
 * @return a collection of files/*w  w  w . j a va2 s.  co  m*/
 */
@Override
public Collection<File> getInputFiles(String[] input) {
    LinkedHashSet<File> files = new LinkedHashSet<>();
    for (String inputString : input) {
        log.debug("Processing input string {}", inputString);
        //separate wildcards from plain files
        String name = FilenameUtils.getName(inputString);
        boolean isWildcard = name.contains("?") || name.contains("*");
        String fullPath = FilenameUtils.getFullPath(inputString);
        File path = new File(fullPath);
        File baseDirFile = new File(this.basedir);
        if (!baseDirFile.exists()) {
            throw new ExitVmException("Input base directory '" + baseDirFile + "' does not exist!");
        }
        if (!baseDirFile.isDirectory()) {
            throw new ExitVmException("Input base directory '" + baseDirFile + "' is not a directory!");
        }
        log.debug("Path is absolute: {}", path.isAbsolute());
        //identify absolute and relative files
        if (!path.isAbsolute()) {
            log.info("Resolving relative file against basedir: {}", this.basedir);
            path = new File(this.basedir, fullPath);
        }
        //normalize filenames
        fullPath = FilenameUtils.normalize(path.getAbsolutePath());
        log.debug("After normalization: {}", fullPath);
        IOFileFilter dirFilter = this.recurse ? TrueFileFilter.INSTANCE : null;
        if (isWildcard) {
            log.debug("Using wildcard matcher for {}", name);
            files.addAll(FileUtils.listFiles(new File(fullPath),
                    new WildcardFileFilter(name, IOCase.INSENSITIVE), dirFilter));
        } else {
            log.debug("Using name for {}", name);
            File f = new File(fullPath, name);
            if (!f.exists()) {
                throw new ExitVmException("Input file '" + f + "' does not exist!");
            }
            files.add(f);
        }
    }
    return files;
}

From source file:com.btoddb.fastpersitentqueue.InMemorySegmentMgr.java

private void loadPagedSegments() throws IOException {
    // read files and sort by their UUID name so they are in proper chronological order
    Collection<File> files = FileUtils.listFiles(pagingDirectory, TrueFileFilter.INSTANCE,
            TrueFileFilter.INSTANCE);/* w w w.  j  a v  a  2  s. c  om*/
    TreeSet<File> sortedFiles = new TreeSet<File>(new Comparator<File>() {
        @Override
        public int compare(File o1, File o2) {
            return new UUID(o1.getName()).compareTo(new UUID(o2.getName()));
        }
    });
    sortedFiles.addAll(files);

    // cleanup memory
    files.clear();

    assert 0 == numberOfActiveSegments.get();
    assert segments.isEmpty();

    segments.clear();

    for (File f : sortedFiles) {
        MemorySegment segment;
        // only load the segment's data if room in memory, otherwise just load its header
        if (numberOfActiveSegments.get() < maxNumberOfActiveSegments - 1) {
            segment = segmentSerializer.loadFromDisk(f.getName());
            segment.setStatus(MemorySegment.Status.READY);
            segment.setPushingFinished(true);

            assert segment.getNumberOfOnlineEntries() > 0;
            assert !segment.getQueue().isEmpty();

            numberOfActiveSegments.incrementAndGet();
        } else {
            segment = segmentSerializer.loadHeaderOnly(f.getName());
            segment.setStatus(MemorySegment.Status.OFFLINE);
            segment.setPushingFinished(true);

        }

        assert segment.isPushingFinished();
        assert segment.getNumberOfEntries() > 0;
        assert segment.getEntryListOffsetOnDisk() > 0;

        segments.add(segment);
        numberOfEntries.addAndGet(segment.getNumberOfEntries());
    }

    //        for (MemorySegment seg : segments) {
    //            if (seg.getStatus() == MemorySegment.Status.READY) {
    //                segmentSerializer.removePagingFile(seg);
    //            }
    //        }
}

From source file:com.btoddb.fastpersitentqueue.InMemorySegmentMgrTest.java

@Test
public void testPop() throws Exception {
    mgr.init();/*from  w  w  w.  j  a v a 2  s.  c om*/

    for (int i = 0; i < numEntries; i++) {
        mgr.push(new FpqEntry(idGen.incrementAndGet(), String.format(
                "%02d-3456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789",
                i).getBytes()));
    }

    long end = System.currentTimeMillis() + 1000;
    while (System.currentTimeMillis() < end && mgr.getNumberOfActiveSegments() > 4) {
        Thread.sleep(100);
    }

    for (int i = 0; i < numEntries; i++) {
        FpqEntry entry;
        while (null == (entry = mgr.pop())) {
            Thread.sleep(100);
        }
        System.out.println(new String(entry.getData()));
    }

    // this triggers the last segment to be removed and gives it a chance to happen
    mgr.pop(1);
    Thread.sleep(500);

    assertThat(mgr.getNumberOfEntries(), is(0L));
    assertThat(mgr.getSegments(), hasSize(1));

    MemorySegment seg = mgr.getSegments().iterator().next();
    assertThat(seg.getStatus(), is(MemorySegment.Status.READY));
    assertThat(seg.getNumberOfOnlineEntries(), is(0L));
    assertThat(seg.getNumberOfEntries(), is(0L));
    assertThat(seg.getQueue().keySet(), is(empty()));

    assertThat(FileUtils.listFiles(theDir, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE), is(empty()));
}

From source file:ar.com.fluxit.jqa.JQAMavenPlugin.java

private void doExecute(File buildDirectory, File outputDirectory, File testOutputDirectory,
        MavenProject project, File sourceDir, String sourceJavaVersion)
        throws IntrospectionException, TypeFormatException, FileNotFoundException, IOException,
        RulesContextFactoryException, ExporterException {
    // Add project dependencies to classpath
    getLog().debug("Adding project dependencies to classpath");
    final Collection<File> classPath = new ArrayList<File>();
    @SuppressWarnings("unchecked")
    final Set<Artifact> artifacts = project.getArtifacts();
    for (final Artifact artifact : artifacts) {
        classPath.add(artifact.getFile());
    }/*from w ww .  j  a va2s  . c  o  m*/
    // Add project classes to classpath
    if (outputDirectory != null) {
        classPath.add(outputDirectory);
    }
    if (testOutputDirectory != null) {
        classPath.add(testOutputDirectory);
    }
    getLog().debug("Adding project classes to classpath");
    final Collection<File> classFiles = FileUtils.listFiles(buildDirectory,
            new SuffixFileFilter(RulesContextChecker.CLASS_SUFFIX), TrueFileFilter.INSTANCE);
    // Reads the config file
    getLog().debug("Reading rules context");
    final RulesContext rulesContext = RulesContextFactoryLocator.getRulesContextFactory()
            .getRulesContext(getRulesContextFile().getPath());
    getLog().debug("Checking rules for " + classFiles.size() + " files");
    final CheckingResult checkingResult = RulesContextChecker.INSTANCE.check(project.getArtifactId(),
            classFiles, classPath, rulesContext, new File[] { sourceDir }, sourceJavaVersion, getLogger());
    CheckingResultExporter.INSTANCE.export(checkingResult, project.getArtifactId(), getResultsDirectory(),
            this.xslt, getLogger());
}

From source file:io.github.jeremgamer.editor.panels.Buttons.java

public Buttons(final JFrame frame, final ButtonPanel be, final PanelSave ps) {
    this.setBorder(BorderFactory.createTitledBorder(""));

    this.frame = frame;

    JButton add = null;/*from   www.j  av  a 2  s .c o  m*/
    try {
        add = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("add.png"))));
    } catch (IOException e) {
        e.printStackTrace();
    }
    add.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            try {
                JOptionPane jop = new JOptionPane();
                @SuppressWarnings("static-access")
                String name = jop.showInputDialog(null, "Nommez le bouton :", "Crer un bouton",
                        JOptionPane.QUESTION_MESSAGE);

                if (name != null) {
                    for (int i = 0; i < data.getSize(); i++) {
                        if (data.get(i).equals(name)) {
                            name += "1";
                        }
                    }
                    data.addElement(name);
                    new ButtonSave(name);
                    ActionPanel.updateLists();
                    OtherPanel.updateLists();
                    PanelsPanel.updateLists();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }

        }

    });

    JButton remove = null;
    try {
        remove = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png"))));
    } catch (IOException e) {
        e.printStackTrace();
    }
    remove.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            try {
                if (buttonList.getSelectedValue() != null) {
                    File file = new File("projects/" + Editor.getProjectName() + "/buttons/"
                            + buttonList.getSelectedValue() + "/" + buttonList.getSelectedValue() + ".rbd");
                    JOptionPane jop = new JOptionPane();
                    @SuppressWarnings("static-access")
                    int option = jop.showConfirmDialog(null, "tes-vous sr de vouloir supprimer ce bouton?",
                            "Avertissement", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);

                    if (option == JOptionPane.OK_OPTION) {
                        File dir = new File("projects/" + Editor.getProjectName() + "/panels");
                        for (File f : FileUtils.listFilesAndDirs(dir, TrueFileFilter.INSTANCE,
                                TrueFileFilter.INSTANCE)) {
                            if (!f.isDirectory()) {
                                try {
                                    ps.load(f);
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                                for (String section : ps
                                        .getSectionsContaining(buttonList.getSelectedValue() + " (Bouton)")) {
                                    ps.removeSection(section);
                                    try {
                                        ps.save(f);
                                    } catch (IOException e) {
                                        e.printStackTrace();
                                    }
                                }
                            }
                        }
                        if (buttonList.getSelectedValue().equals(be.getFileName())) {
                            be.setFileName("");
                        }
                        be.hide();
                        file.delete();
                        File parent = new File(file.getParent());
                        for (File img : FileUtils.listFiles(parent, TrueFileFilter.INSTANCE,
                                TrueFileFilter.INSTANCE)) {
                            img.delete();
                        }
                        parent.delete();
                        data.remove(buttonList.getSelectedIndex());
                        ActionPanel.updateLists();
                        OtherPanel.updateLists();
                        PanelsPanel.updateLists();
                    }
                }
            } catch (NullPointerException npe) {
                npe.printStackTrace();
            }

        }

    });

    JPanel buttons = new JPanel();
    buttons.setLayout(new BoxLayout(buttons, BoxLayout.LINE_AXIS));
    buttons.add(add);
    buttons.add(remove);

    updateList();
    buttonList.addMouseListener(new MouseAdapter() {
        @SuppressWarnings("unchecked")
        public void mouseClicked(MouseEvent evt) {
            JList<String> list = (JList<String>) evt.getSource();
            if (evt.getClickCount() == 2) {
                int index = list.locationToIndex(evt.getPoint());
                if (isOpen == false) {
                    be.load(new File("projects/" + Editor.getProjectName() + "/buttons/"
                            + list.getModel().getElementAt(index) + "/" + list.getModel().getElementAt(index)
                            + ".rbd"));
                    be.show();
                    previousSelection = list.getSelectedValue();
                    isOpen = true;
                } else {
                    try {
                        if (previousSelection.equals(list.getModel().getElementAt(index))) {
                            be.hide();
                            previousSelection = list.getSelectedValue();
                            list.clearSelection();
                            isOpen = false;
                        } else {
                            be.hideThenShow();
                            previousSelection = list.getSelectedValue();
                            be.load(new File("projects/" + Editor.getProjectName() + "/buttons/"
                                    + list.getModel().getElementAt(index) + "/"
                                    + list.getModel().getElementAt(index) + ".rbd"));
                        }
                    } catch (NullPointerException npe) {
                        be.hide();
                        list.clearSelection();
                    }
                }
            } else if (evt.getClickCount() == 3) {
                int index = list.locationToIndex(evt.getPoint());
                if (isOpen == false) {
                    be.load(new File("projects/" + Editor.getProjectName() + "/buttons/"
                            + list.getModel().getElementAt(index) + "/" + list.getModel().getElementAt(index)
                            + ".rbd"));
                    be.show();
                    previousSelection = list.getSelectedValue();
                    isOpen = true;
                } else {
                    try {
                        if (previousSelection.equals(list.getModel().getElementAt(index))) {
                            be.hide();
                            previousSelection = list.getSelectedValue();
                            list.clearSelection();
                            isOpen = false;
                        } else {
                            be.hideThenShow();
                            previousSelection = list.getSelectedValue();
                            be.load(new File("projects/" + Editor.getProjectName() + "/buttons/"
                                    + list.getModel().getElementAt(index) + "/"
                                    + list.getModel().getElementAt(index) + ".rbd"));
                        }
                    } catch (NullPointerException npe) {
                        be.hide();
                        list.clearSelection();
                    }
                }
            }
        }
    });
    JScrollPane listPane = new JScrollPane(buttonList);
    listPane.getVerticalScrollBar().setUnitIncrement(Editor.SCROLL_SPEED);
    this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
    this.add(buttons);
    this.add(listPane);

}

From source file:com.textocat.textokit.commons.util.CorpusUtils.java

/**
 * convenience overload of/*from w w  w.  ja va  2  s  .c o m*/
 * {@link #partitionCorpusByFileSize(File, IOFileFilter, IOFileFilter, int)}
 * that look up corpus files in all subdirectories.
 *
 * @param corpusDir
 * @param corpusFileFilter
 * @param partitionsNumber
 * @return
 */
public static List<Set<File>> partitionCorpusByFileSize(File corpusDir, IOFileFilter corpusFileFilter,
        int partitionsNumber) {
    return partitionCorpusByFileSize(corpusDir, corpusFileFilter, TrueFileFilter.INSTANCE, partitionsNumber);
}

From source file:com.bluexml.tools.miscellaneous.PrepareSIDEModulesMigration.java

private static void executeInpath(boolean inplace, String frameworkmodulesPath, String classifier_base,
        String version_base, String classifier_target, String version_target, String frameworkmodulesInplace,
        File workspaceFile, final String versionInProjectName, String versionInProjectName2) {
    File frameworkmodulesPathFile = new File(frameworkmodulesPath);
    if (inplace) {
        frameworkmodulesPathFile = new File(frameworkmodulesInplace);
        Collection<?> listFiles = FileUtils.listFiles(frameworkmodulesPathFile, TrueFileFilter.INSTANCE,
                new IOFileFilter() {

                    public boolean accept(File dir, String name) {
                        return !name.equals(".svn");
                    }//from   w ww.  ja v a  2s  . co m

                    public boolean accept(File file) {
                        return !file.getName().equals(".svn");
                    }
                });
        for (Object object : listFiles) {

            File f = (File) object;
            //            System.out.println("PrepareSIDEModulesMigration.main() file :" + f);
            replaceVersionInFile(versionInProjectName, versionInProjectName2, version_base, classifier_base,
                    version_target, classifier_target, f, true);
        }

    } else if (frameworkmodulesPathFile.exists()) {

        // copy resource
        // get project to copy

        File[] listFilesT = frameworkmodulesPathFile.listFiles();
        System.out.println("PrepareSIDEModulesMigration.main() all :" + listFilesT.length);
        File[] listFiles = frameworkmodulesPathFile.listFiles(new FileFilter() {
            public boolean accept(File file) {
                if (file.isDirectory()) {

                    String pat = versionInProjectName;
                    pat = ".*" + Pattern.quote(pat) + ".*";
                    boolean matches = file.getName().matches(pat);
                    System.out.println("accept() file" + file.getName() + " pattern :" + pat + " ?" + matches);
                    return matches;
                }
                System.out
                        .println("PrepareSIDEModulesMigration.main(...).new FileFilter() {...}.accept() FALSE");
                return false;
            }
        });
        System.out.println("PrepareSIDEModulesMigration.main() to copy : " + listFiles.length);
        for (File srcDir : listFiles) {
            System.out.println("PrepareSIDEModulesMigration.main() copy dir :" + srcDir);
            File copyDir = copyDir(workspaceFile, srcDir);

            reNameResources(versionInProjectName, copyDir, versionInProjectName2, version_base, classifier_base,
                    version_target, classifier_target);
        }

    } else {
        System.err.println("frameworkmodulesPathFile do not exists :" + frameworkmodulesPathFile);
    }
}

From source file:bioLockJ.module.parser.r16s.QiimeParser.java

/**
 * Init input files to find the most specific taxa file, this will contain all the info
 * for all taxa levels above it./*from   www .j  a  v  a  2  s.  c  o  m*/
 */
@Override
protected void initInputFiles(final File dir) throws Exception {
    final String searchTerm = getLowestTaxaLevelFileName();
    Log.out.info("Recursively search for most specific taxa file " + searchTerm + " in: " + getDirName(dir));
    final IOFileFilter ff = new NameFileFilter(searchTerm);
    setModuleInput(dir, ff, TrueFileFilter.INSTANCE);
}

From source file:com.przyjaznyplan.utils.CsvConverter.java

private void ifAudioGetIt(String value, ContentValues sqlValues) {
    if (value != null && value.endsWith(MP3_EXT)) {
        Collection files = FileUtils.listFiles(new File(rootFolder), new NameFileFilter(value),
                TrueFileFilter.INSTANCE);
        Iterator<File> iterator = files.iterator();
        if (iterator.hasNext()) {
            File f = iterator.next();
            sqlValues.put(Czynnosc.AUDIO, f.getAbsolutePath());
        }//  ww  w .j a va  2  s. c o m

    }
}

From source file:io.github.jeremgamer.editor.panels.Labels.java

public Labels(final JFrame frame, final LabelPanel lp, final PanelSave ps) {
    this.frame = frame;

    this.setBorder(BorderFactory.createTitledBorder(""));
    JButton add = null;//from  w w  w .j  av a  2s  .c o  m
    try {
        add = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("add.png"))));
    } catch (IOException e) {
        e.printStackTrace();
    }
    add.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            try {
                JOptionPane jop = new JOptionPane();
                @SuppressWarnings("static-access")
                String name = jop.showInputDialog((JFrame) SwingUtilities.windowForComponent(labelList),
                        "Nommez le label :", "Crer un label", JOptionPane.QUESTION_MESSAGE);

                if (name != null) {
                    for (int i = 0; i < data.getSize(); i++) {
                        if (data.get(i).equals(name)) {
                            name += "1";
                        }
                    }
                    data.addElement(name);
                    new LabelSave(name);
                    ActionPanel.updateLists();
                    OtherPanel.updateLists();
                    PanelsPanel.updateLists();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }

        }

    });

    JButton remove = null;
    try {
        remove = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png"))));
    } catch (IOException e) {
        e.printStackTrace();
    }
    remove.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            try {
                if (labelList.getSelectedValue() != null) {
                    File file = new File("projects/" + Editor.getProjectName() + "/labels/"
                            + labelList.getSelectedValue() + ".rbd");
                    JOptionPane jop = new JOptionPane();
                    @SuppressWarnings("static-access")
                    int option = jop.showConfirmDialog((JFrame) SwingUtilities.windowForComponent(labelList),
                            "tes-vous sr de vouloir supprimer ce label?", "Avertissement",
                            JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);

                    if (option == JOptionPane.OK_OPTION) {
                        File dir = new File("projects/" + Editor.getProjectName() + "/panels");
                        for (File f : FileUtils.listFilesAndDirs(dir, TrueFileFilter.INSTANCE,
                                TrueFileFilter.INSTANCE)) {
                            if (!f.isDirectory()) {
                                try {
                                    ps.load(f);
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                                for (String section : ps
                                        .getSectionsContaining(labelList.getSelectedValue() + " (Label)")) {
                                    ps.removeSection(section);
                                    try {
                                        ps.save(f);
                                    } catch (IOException e) {
                                        e.printStackTrace();
                                    }
                                }
                            }
                        }
                        if (labelList.getSelectedValue().equals(lp.getFileName())) {
                            lp.setFileName("");
                        }
                        lp.hide();
                        file.delete();
                        data.remove(labelList.getSelectedIndex());
                        ActionPanel.updateLists();
                        OtherPanel.updateLists();
                        PanelsPanel.updateLists();
                    }
                }
            } catch (NullPointerException npe) {
                npe.printStackTrace();
            }

        }

    });

    JPanel buttons = new JPanel();
    buttons.setLayout(new BoxLayout(buttons, BoxLayout.LINE_AXIS));
    buttons.add(add);
    buttons.add(remove);

    updateList();
    labelList.addMouseListener(new MouseAdapter() {
        @SuppressWarnings("unchecked")
        public void mouseClicked(MouseEvent evt) {
            JList<String> list = (JList<String>) evt.getSource();
            if (evt.getClickCount() == 2) {
                int index = list.locationToIndex(evt.getPoint());
                if (isOpen == false) {
                    lp.show();
                    lp.load(new File("projects/" + Editor.getProjectName() + "/labels/"
                            + list.getModel().getElementAt(index) + ".rbd"));
                    previousSelection = list.getSelectedValue();
                    isOpen = true;
                } else {
                    try {
                        if (previousSelection.equals(list.getModel().getElementAt(index))) {
                            lp.hide();
                            previousSelection = list.getSelectedValue();
                            list.clearSelection();
                            isOpen = false;
                        } else {
                            lp.hideThenShow();
                            previousSelection = list.getSelectedValue();
                            lp.load(new File("projects/" + Editor.getProjectName() + "/labels/"
                                    + list.getModel().getElementAt(index) + ".rbd"));
                        }
                    } catch (NullPointerException npe) {
                        lp.hide();
                        list.clearSelection();
                    }
                }
            } else if (evt.getClickCount() == 3) {
                int index = list.locationToIndex(evt.getPoint());
                if (isOpen == false) {
                    lp.show();
                    lp.load(new File("projects/" + Editor.getProjectName() + "/labels/"
                            + list.getModel().getElementAt(index) + ".rbd"));
                    previousSelection = list.getSelectedValue();
                    isOpen = true;
                } else {
                    try {
                        if (previousSelection.equals(list.getModel().getElementAt(index))) {
                            lp.hide();
                            previousSelection = list.getSelectedValue();
                            list.clearSelection();
                            isOpen = false;
                        } else {
                            lp.hideThenShow();
                            previousSelection = list.getSelectedValue();
                            lp.load(new File("projects/" + Editor.getProjectName() + "/labels/"
                                    + list.getModel().getElementAt(index) + ".rbd"));
                        }
                    } catch (NullPointerException npe) {
                        lp.hide();
                        list.clearSelection();
                    }
                }
            }
        }
    });
    JScrollPane listPane = new JScrollPane(labelList);
    listPane.getVerticalScrollBar().setUnitIncrement(Editor.SCROLL_SPEED);
    this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
    this.add(buttons);
    this.add(listPane);

}