Example usage for java.io FileFilter FileFilter

List of usage examples for java.io FileFilter FileFilter

Introduction

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

Prototype

FileFilter

Source Link

Usage

From source file:de.uni_koblenz.ist.utilities.license_header.LicenseHeader.java

private void processDirectory(final File toProcess, int level) throws IOException {

    File[] directories = toProcess.listFiles(new FileFilter() {

        @Override/*from ww  w  .j  a  v a2 s . co  m*/
        public boolean accept(File pathname) {
            return pathname.isDirectory() && !pathname.getName().equals(".svn");
        }
    });

    File[] javaFilesToProcess = toProcess.listFiles(new FilenameFilter() {

        @Override
        public boolean accept(File dir, String name) {
            return dir.getAbsolutePath().equals(toProcess.getAbsolutePath())
                    && name.toLowerCase().endsWith(".java");
        }
    });

    File[] xmlFilesToProcess = toProcess.listFiles(new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            String lowerCaseName = name.toLowerCase();
            return dir.getAbsolutePath().equals(toProcess.getAbsolutePath())
                    && (lowerCaseName.endsWith(".xml") || lowerCaseName.endsWith(".xmi"));
        }
    });

    File[] tgFilesToProcess = toProcess.listFiles(new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            return dir.getAbsolutePath().equals(toProcess.getAbsolutePath())
                    && name.toLowerCase().endsWith(".tg");
        }
    });

    if (fullyRecursive) {
        for (File currentSubdirectory : directories) {
            if (verbose) {
                printIndent(level);
                System.out.println("Entering directory " + currentSubdirectory.getName());
            }
            processDirectory(currentSubdirectory, level + 1);
            if (verbose) {
                printIndent(level);
                System.out.println("Leaving directory " + currentSubdirectory.getName());
            }
        }
    }

    for (File currentJavaFile : javaFilesToProcess) {
        processJavaFile(currentJavaFile, level, JAVA_FIRST_LINE, JAVA_PREFIX, JAVA_LAST_LINE);
    }

    for (File currentXMLFile : xmlFilesToProcess) {
        processXMLFile(currentXMLFile, level, 72);
    }

    for (File currentTGFile : tgFilesToProcess) {
        processTGFile(currentTGFile, level);
    }
}

From source file:com.iped.ipcam.bitmapfun.ImageGrid.java

private void loadImageFiles() {
    if (Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) {
        String sdDir = Environment.getExternalStorageDirectory().getAbsolutePath();// 
        File file = new File(sdDir + FileUtil.parentPath + FileUtil.picForder);
        if (!file.exists()) {
            file.mkdirs();//from  ww  w. java2 s .  com
            File noMedia = new File(sdDir + FileUtil.parentPath + FileUtil.picForder + ".nomedia");
            try {
                noMedia.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        String fileThumbnail = sdDir + FileUtil.parentPath + FileUtil.picThumbnail;
        File thumbnailFile = new File(fileThumbnail);
        if (!thumbnailFile.exists()) {
            thumbnailFile.mkdirs();
            File noMedia = new File(sdDir + FileUtil.parentPath + FileUtil.picThumbnail + ".nomedia");
            try {
                noMedia.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        File[] files = file.listFiles(new FileFilter() {

            @Override
            public boolean accept(File pathname) {
                if (pathname.isDirectory()) {
                    return true;
                }
                String name = pathname.getName().toLowerCase();
                return name.endsWith(".jpeg") || name.endsWith(".jpg") || name.endsWith(".png")
                        || name.endsWith(".gif");
            }
        });
        for (int i = 0; i < files.length; i++) {
            if (files[i].isFile()) {
                //paths[i] = files[i].getPath();
                ImageInfo imageInfo = new ImageInfo();
                imageInfo.path = files[i].getPath();
                imageInfo.title = files[i].getName();
                imageInfo.thumbnail = fileThumbnail + imageInfo.title;
                System.out.println(imageInfo.thumbnail + "  " + imageInfo.title);
                File thumbnail = new File(imageInfo.thumbnail);
                if (!thumbnail.exists()) {
                    BitmapFactory.Options options = new BitmapFactory.Options();
                    options.inJustDecodeBounds = true;
                    Bitmap bitmap = BitmapFactory.decodeFile(imageInfo.path, options); //bm
                    options.inJustDecodeBounds = false;
                    int be = (int) (options.outWidth / (float) columnWidth);
                    if (be <= 0)
                        be = 1;
                    options.inSampleSize = be;
                    bitmap = BitmapFactory.decodeFile(imageInfo.path, options);
                    FileOutputStream out = null;
                    try {
                        out = new FileOutputStream(thumbnail);
                        if (bitmap != null && bitmap.compress(Bitmap.CompressFormat.JPEG, 50, out)) {
                            out.flush();
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    } finally {
                        if (out != null) {
                            try {
                                out.close();
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        }
                    }

                }
                Uri uri = Uri.parse("file://" + files[i].getPath());
                imageInfo.setActivity(uri,
                        Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
                imageList.add(imageInfo);
                handler.sendEmptyMessage(1);
            }
        }
    }
}

From source file:org.apache.carbondata.sdk.file.CSVNonTransactionalCarbonWriterTest.java

@Test
public void test2Block() throws IOException {
    String path = "./testWriteFiles";
    FileUtils.deleteDirectory(new File(path));

    Field[] fields = new Field[2];
    fields[0] = new Field("name", DataTypes.STRING);
    fields[1] = new Field("age", DataTypes.INT);

    writeFilesAndVerify(1000 * 1000, new Schema(fields), path, null, false, 2, 2);

    File segmentFolder = new File(path);
    File[] dataFiles = segmentFolder.listFiles(new FileFilter() {
        @Override//from  w  ww  .j a  v  a 2s  . c om
        public boolean accept(File pathname) {
            return pathname.getName().endsWith(CarbonCommonConstants.FACT_FILE_EXT);
        }
    });
    Assert.assertNotNull(dataFiles);
    Assert.assertEquals(2, dataFiles.length);

    FileUtils.deleteDirectory(new File(path));
}

From source file:net.grinder.engine.agent.LocalScriptTestDriveService.java

@SuppressWarnings("ResultOfMethodCallIgnored")
private void deleteLogs(File base) {
    base.listFiles(new FileFilter() {
        @Override/*  w  w  w . j  a v  a  2s.  c  om*/
        public boolean accept(File pathName) {
            String extension = FilenameUtils.getExtension(pathName.getName());
            if (extension.startsWith("log")) {
                pathName.delete();
            }
            return true;
        }
    });
}

From source file:de.tarent.maven.plugins.pkg.AbstractMvnPkgPluginTestCase.java

public File[] returnFilesBasedOnFilename(String filename) {

    final Pattern p = Pattern.compile(".*" + filename);
    return TARGETDIR.listFiles(new FileFilter() {
        @Override/*ww  w  .j a va2 s  . c om*/
        public boolean accept(File file) {
            return p.matcher(file.getName()).matches();
        }
    });
}

From source file:com.wintindustries.pfserver.PFDefaultLibrary.FileServices.PFFileServiceLocal.PFFileServiceLocal.java

/**
 * Returns an unlinked PFFolder that mimics the filestructure. This method is relativly quick to execute
 * @param file/*from   w ww. j  a v  a 2s.co  m*/
 * @return 
 */
private synchronized PFFolder recursiveConvertDirectoryToPFFolder(File directory) {
    PFFolder folder = new PFFolder(directory.getName());

    for (File file : directory.listFiles(new FileFilter() {

        @Override
        public boolean accept(File pathname) {
            return pathname.isFile();
        }
    })) {

        PFGenericDocument document = new PFGenericDocument();
        document.setName(file.getName());
        folder.addDocument(document);

    }

    // get all the directories 
    for (File subdirectory : directory.listFiles(new FileFilter() {
        @Override
        public boolean accept(File pathname) {
            return pathname.isDirectory();
        }
    })) {

        PFFolder subfolder = recursiveConvertDirectoryToPFFolder(subdirectory);
        folder.addSubfolder(subfolder);

    }

    return folder;
}

From source file:au.org.ala.spatial.analysis.layers.LayerDistanceIndex.java

/**
 * @param threadcount    number of threads to run analysis.
 * @param onlyThesePairs array of distances to run as fieldId1 + " " +
 *                       fieldId2 where fieldId1.compareTo(fieldId2) &lt 0 or null for all missing
 *                       distances./* ww w.jav a2 s.  c  om*/
 * @throws InterruptedException
 */
public void occurrencesUpdate(int threadcount, String[] onlyThesePairs) throws InterruptedException {

    //create distances file if it does not exist.
    File layerDistancesFile = new File(IntersectConfig.getAlaspatialOutputPath() + LAYER_DISTANCE_FILE);
    if (!layerDistancesFile.exists()) {
        FileWriter fw = null;
        try {
            fw = new FileWriter(layerDistancesFile);
            fw.flush();
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        } finally {
            if (fw != null) {
                try {
                    fw.close();
                } catch (Exception e) {
                    logger.error(e.getMessage(), e);
                }
            }
        }
    }

    Map<String, Double> map = loadDistances();

    LinkedBlockingQueue<String> todo = new LinkedBlockingQueue();

    if (onlyThesePairs != null && onlyThesePairs.length > 0) {
        for (String s : onlyThesePairs) {
            todo.add(s);
        }
    } else {
        //find all environmental layer analysis files
        File root = new File(IntersectConfig.getAlaspatialOutputPath());
        File[] dirs = root.listFiles(new FileFilter() {

            @Override
            public boolean accept(File pathname) {
                return pathname != null && pathname.isDirectory();
            }
        });

        HashMap<String, String> domains = new HashMap<String, String>();
        for (File dir : dirs) {
            //iterate through files so we get everything
            File[] files = new File(dir.getPath()).listFiles(new FileFilter() {

                @Override
                public boolean accept(File pathname) {
                    return pathname.getName().endsWith(".grd") && pathname.getName().startsWith("el");
                }
            });

            for (int i = 0; i < files.length; i++) {
                for (int j = i + 1; j < files.length; j++) {
                    String file1 = files[i].getName().replace(".grd", "");
                    String file2 = files[j].getName().replace(".grd", "");

                    //only operate on file names that are valid fields
                    if (Client.getFieldDao().getFieldById(file1) != null
                            && Client.getFieldDao().getFieldById(file2) != null) {

                        String domain1 = domains.get(file1);
                        if (domain1 == null) {
                            String pid1 = Client.getFieldDao().getFieldById(file1).getSpid();
                            domain1 = Client.getLayerDao().getLayerById(Integer.parseInt(pid1)).getdomain();
                            domains.put(file1, domain1);
                        }
                        String domain2 = domains.get(file2);
                        if (domain2 == null) {
                            String pid2 = Client.getFieldDao().getFieldById(file2).getSpid();
                            domain2 = Client.getLayerDao().getLayerById(Integer.parseInt(pid2)).getdomain();
                            domains.put(file2, domain2);
                        }

                        String key = (file1.compareTo(file2) < 0) ? file1 + " " + file2 : file2 + " " + file1;

                        //domain test
                        if (isSameDomain(parseDomain(domain1), parseDomain(domain2))) {
                            if (!map.containsKey(key) && !todo.contains(key)) {
                                todo.put(key);
                            }
                        }
                    }
                }
            }
        }
    }

    LinkedBlockingQueue<String> toDisk = new LinkedBlockingQueue<String>();
    CountDownLatch cdl = new CountDownLatch(todo.size());
    CalcThread[] threads = new CalcThread[threadcount];
    for (int i = 0; i < threadcount; i++) {
        threads[i] = new CalcThread(cdl, todo, toDisk);
        threads[i].start();
    }

    ToDiskThread toDiskThread = new ToDiskThread(
            IntersectConfig.getAlaspatialOutputPath() + LAYER_DISTANCE_FILE, toDisk);
    toDiskThread.start();

    cdl.await();

    for (int i = 0; i < threadcount; i++) {
        threads[i].interrupt();
    }

    toDiskThread.interrupt();
}

From source file:com.adito.notification.Notifier.java

public void clearAllMessages() {
    synchronized (messages) {
        try {/*from  w  ww .j  av  a2 s  .co  m*/
            messages.clear();
            File[] f = queueDirectory.listFiles(new FileFilter() {
                public boolean accept(File f) {
                    return f.getName().endsWith(".msg");
                }
            });
            if (f != null) {
                for (int i = 0; i < f.length; i++) {
                    f[i].delete();
                }
            }
            CoreServlet.getServlet().fireCoreEvent(new CoreEvent(this, CoreEventConstants.MESSAGE_QUEUE_CLEARED,
                    null, null, CoreEvent.STATE_SUCCESSFUL));
        } catch (Exception e) {
            log.error("Failed to clear messages from queue", e);
            CoreServlet.getServlet().fireCoreEvent(new CoreEvent(this, CoreEventConstants.MESSAGE_QUEUE_CLEARED,
                    null, null, CoreEvent.STATE_UNSUCCESSFUL));
        }
    }
}

From source file:jdao.JDAO.java

public static void processDatasourceDirectory(String scanDir, final String suffix,
        Map<String, DataSource> reg) {
    try {/*  ww w .j ava  2  s.c  o m*/
        File workDir = new File(scanDir);

        if (workDir.isDirectory()) {
            File[] files = workDir.listFiles(new FileFilter() {
                @Override
                public boolean accept(File pathname) {
                    return pathname.isFile() && pathname.getName().endsWith(suffix);
                }
            });

            for (File file : files) {
                String dsName = file.getName();
                dsName = dsName.substring(0, dsName.length() - suffix.length());
                DataSource ds = createDatasourceFromFile(file);
                reg.put(dsName, ds);
            }
        }
    } catch (Exception xe) {
        log("Error processing directory: " + scanDir, xe);
    }
}