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:gov.redhawk.core.filemanager.filesystem.JavaFileSystem.java

@Override
public FileInformationType[] list(final String fullPattern) throws FileException, InvalidFileName {
    final int index = fullPattern.lastIndexOf('/');
    final File container;
    if (index > 0) {
        container = new File(this.root, fullPattern.substring(0, index));
    } else {/*from  ww  w. j  av  a 2 s . c o m*/
        container = this.root;
    }

    final String pattern = fullPattern.substring(index + 1, fullPattern.length());

    final String[] fileNames;

    if (pattern.length() == 0) {
        fileNames = new String[] { "" };
    } else {
        fileNames = container.list(new FilenameFilter() {

            @Override
            public boolean accept(final File dir, final String name) {
                if (!dir.equals(container)) {
                    return false;
                }
                return FilenameUtils.wildcardMatch(name, pattern);
            }
        });
    }

    if (fileNames == null) {
        return new FileInformationType[0];
    }

    final FileInformationType[] retVal = new FileInformationType[fileNames.length];
    for (int i = 0; i < fileNames.length; i++) {
        final FileInformationType fileInfo = new FileInformationType();
        final File file = new File(container, fileNames[i]);
        fileInfo.name = file.getName();
        fileInfo.size = file.length();
        if (file.isFile()) {
            fileInfo.kind = FileType.PLAIN;
        } else {
            fileInfo.kind = FileType.DIRECTORY;
        }
        final Any any = this.orb.create_any();
        any.insert_ulonglong(file.lastModified() / JavaFileSystem.MILLIS_PER_SEC);
        final DataType modifiedTime = new DataType("MODIFIED_TIME", any);

        fileInfo.fileProperties = new DataType[] { modifiedTime };

        retVal[i] = fileInfo;
    }
    return retVal;
}

From source file:org.motechproject.mobile.imp.serivce.oxd.FormDefinitionServiceImpl.java

public List<File> getFileList(String directorySource) throws IOException {

    File directory = new ClassPathResource(directorySource).getFile();
    if (directory == null)
        throw new RuntimeException(new FileNotFoundException(" resource not found" + directorySource));

    if (!directory.exists())
        return Collections.emptyList();

    List<File> fileList = Arrays.asList(directory.listFiles(new FilenameFilter() {
        public boolean accept(File dir, String name) {
            if (name.endsWith(".xml"))
                return true;
            return false;
        }/* w w w.  j a  v  a 2 s . c  o m*/
    }));
    Collections.sort(fileList, new Comparator<File>() {
        public int compare(File o1, File o2) {
            return o1.getName().compareToIgnoreCase(o2.getName());
        }
    });
    return fileList;
}

From source file:com.btoddb.chronicle.FileTestUtils.java

public Matcher<File> hasEventsInDir(final Event[] targetEvents) {
    return new TypeSafeMatcher<File>() {
        String errorDesc;/*from  www.j a  v a2s  . c  om*/
        String expected;
        String got;

        @Override
        protected boolean matchesSafely(final File dir) {
            BufferedReader reader;
            try {
                // find files
                File[] files = dir.listFiles(new FilenameFilter() {
                    @Override
                    public boolean accept(File dir, String name) {
                        return name.endsWith(".avro");
                    }
                });

                Arrays.sort(files);

                int index = 0;
                for (File f : files) {
                    reader = new BufferedReader(new FileReader(f));
                    try {
                        String line;
                        while (null != (line = reader.readLine())) {
                            Event event = config.getEventSerializer().deserialize(line);
                            if (index < targetEvents.length && !targetEvents[index].equals(event)) {
                                errorDesc = "event: ";
                                expected = new String(
                                        config.getEventSerializer().serialize(targetEvents[index]));
                                got = line;
                                return false;
                            }
                            index++;
                        }
                    } finally {
                        reader.close();
                    }
                }

                if (targetEvents.length == index) {
                    return true;
                } else {
                    errorDesc = "number of events: ";
                    expected = String.valueOf(targetEvents.length);
                    got = String.valueOf(index);
                    return false;
                }
            } catch (FileNotFoundException e) {
                e.printStackTrace();
                return false;
            } catch (IOException e) {
                e.printStackTrace();
                return false;
            }
        }

        @Override
        public void describeTo(final Description description) {
            description.appendText(errorDesc).appendValue(expected);
        }

        @Override
        protected void describeMismatchSafely(final File item, final Description mismatchDescription) {
            mismatchDescription.appendText("  was: ").appendValue(got);
        }
    };
}

From source file:io.cloudslang.dependency.impl.services.DependencyServiceImpl.java

private URL[] getUrls(File libDir) throws MalformedURLException {
    File[] mavenJars = libDir.listFiles(new FilenameFilter() {
        @Override/*from w ww . j  a  v  a  2 s. c  om*/
        public boolean accept(File dir, String name) {
            return name.toLowerCase().endsWith("jar");
        }
    });

    URL[] mavenJarUrls = new URL[mavenJars.length];
    for (int i = 0; i < mavenJarUrls.length; i++) {
        mavenJarUrls[i] = mavenJars[i].toURI().toURL();
    }
    return mavenJarUrls;
}

From source file:de.mprengemann.intellij.plugin.androidicons.util.RefactorHelper.java

public static void move(Project project, final String description, final List<File> sources,
        final List<File> targets) throws IOException {
    copy(project, description, sources, targets);
    RunnableHelper.runWriteCommand(project, new Runnable() {
        @Override/*from  w w  w .  j  a v a  2  s . co m*/
        public void run() {
            try {
                File dir = null;
                for (File source : sources) {
                    if (dir == null) {
                        dir = source.getParentFile();
                    }
                    FileUtils.forceDelete(source);
                }

                if (dir != null) {
                    if (dir.isDirectory()) {
                        File[] images = dir.listFiles(new FilenameFilter() {
                            @Override
                            public boolean accept(File file, String s) {
                                String mimetype = new MimetypesFileTypeMap().getContentType(file);
                                String type = mimetype.split("/")[0];
                                return type.equals("image");
                            }
                        });
                        if (images == null || images.length == 0) {
                            FileUtils.forceDelete(dir);
                        }
                    }
                }
            } catch (IOException ignored) {
            }
        }
    }, description);
}

From source file:br.edimarmanica.trinity.extract.Extract.java

public void execute() throws IOException, REException {
    File dir = new File(Paths.PATH_BASE + site.getPath());
    int nrPages = dir.listFiles(new FilenameFilter() {
        @Override//from  ww w.  j a va 2s . c  o m
        public boolean accept(File dir, String name) {
            return name.endsWith(".html") || name.endsWith(".htm");
        }
    }).length;

    for (int i = 0; (((WINDOW_SIZE - NR_SHARED_PAGES) * (i)) + NR_SHARED_PAGES) <= nrPages; i++) {
        append = false;
        train(i);
        execute(i);
    }
}

From source file:de.mprengemann.intellij.plugin.androidicons.forms.AndroidIconsImporter.java

private void fillComboBoxes() {
    if (this.assetRoot.getCanonicalPath() == null) {
        return;//w  w w.  j a va 2 s.  c om
    }
    File assetRoot = new File(this.assetRoot.getCanonicalPath());
    final FilenameFilter systemFileNameFiler = new FilenameFilter() {
        @Override
        public boolean accept(File file, String s) {
            return !s.startsWith(".");
        }
    };
    File[] colorDirs = assetRoot.listFiles(systemFileNameFiler);
    Comparator<File> alphabeticalComparator = new Comparator<File>() {
        @Override
        public int compare(File file1, File file2) {
            if (file1 != null && file2 != null) {
                return file1.getName().compareTo(file2.getName());
            }
            return 0;
        }
    };
    Arrays.sort(colorDirs, alphabeticalComparator);
    for (File file : colorDirs) {
        if (!file.isDirectory()) {
            continue;
        }
        colorSpinner.addItem(file.getName().replace("_", " "));
    }

    if (colorDirs.length < 1) {
        return;
    }
    File exColorDir = colorDirs[0];
    File[] densities = exColorDir.listFiles(systemFileNameFiler);
    if (densities == null || densities.length < 1) {
        return;
    }
    File exDensity = densities[0];
    File[] assets = exDensity.listFiles(systemFileNameFiler);
    if (assets == null || assets.length < 1) {
        return;
    }
    Arrays.sort(assets, alphabeticalComparator);
    for (File asset : assets) {
        if (asset.isDirectory()) {
            continue;
        }
        String extension = asset.getName().substring(asset.getName().lastIndexOf(".") + 1);
        if (!extension.equalsIgnoreCase("png")) {
            continue;
        }
        assetSpinner
                .addItem(ExportNameUtils.getExportNameFromFilename(asset.getName()).replace("ic_action_", ""));
    }
    assetColor = (String) colorSpinner.getSelectedItem();
    assetName = (String) assetSpinner.getSelectedItem();
}

From source file:jpad.MainEditor.java

public void saveAs_OSX_Nix() {
    String fileToSaveTo = null;/*  w  ww  .  j av  a  2  s . c o  m*/
    FilenameFilter awtFilter = new FilenameFilter() {

        @Override
        public boolean accept(File dir, String name) {
            String lowercaseName = name.toLowerCase();
            if (lowercaseName.endsWith(".txt")) {
                return true;
            } else {
                return false;
            }
        }
    };
    FileDialog fd = new FileDialog(this, "Save Text File", FileDialog.SAVE);
    fd.setDirectory(System.getProperty("java.home"));
    if (curFile == null)
        fd.setFile("Untitled.txt");
    else
        fd.setFile(curFile);
    fd.setFilenameFilter(awtFilter);
    fd.setVisible(true);
    if (fd.getFile() != null)
        fileToSaveTo = fd.getDirectory() + fd.getFile();
    else {
        fileToSaveTo = fd.getFile();
        return;
    }

    curFile = fileToSaveTo;
    JRootPane root = this.getRootPane();
    root.putClientProperty("Window.documentFile", new File(curFile));
    hasChanges = false;
    hasSavedToFile = true;
}

From source file:it.geosolutions.imageio.plugins.nitronitf.ImageIOUtils.java

/**
 * Returns a list of Files contained in the given String array of files or directories. If one of the array contents is a directory, it searches
 * it. Files ending in the extensions provided are returned in the list.
 * //from  ww  w  .  j  a v a  2  s. co m
 * @param filesOrDirs
 * @param extensions
 * @return
 */
public static List<File> getFiles(String[] filesOrDirs, String[] extensions) {
    List<File> files = new ArrayList<File>();
    final String[] exts = extensions;
    for (int i = 0; i < filesOrDirs.length; i++) {
        String arg = filesOrDirs[i];
        File file = new File(arg);
        if (file.isDirectory() && file.exists()) {
            files.addAll(Arrays.asList(file.listFiles(new FilenameFilter() {
                public boolean accept(File dir, String name) {
                    return ArrayUtils.contains(exts, FilenameUtils.getExtension(name.toLowerCase()));
                }
            })));
        } else
            files.add(file);
    }
    return files;
}

From source file:com.basistech.IndexFiles.java

private void iterateOverFiles(File directory) throws IOException {
    File[] textFiles = directory.listFiles(new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.endsWith(".txt");
        }//from ww w. ja  va  2  s .c  o m
    });

    for (File dataFile : textFiles) {
        Reader dataReader = null;
        try {
            dataReader = Files.newReader(dataFile, Charsets.UTF_8);
            TokenStream tokenStream = analyzer.tokenStream("full_text", dataReader);
            tokenStream.reset();
            OffsetAttribute offsets = tokenStream.getAttribute(OffsetAttribute.class);

            while (tokenStream.incrementToken()) {
                offsets.startOffset();
            }
        } finally {
            IOUtils.closeQuietly(dataReader);
        }
    }

}