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:com.codemarvels.ant.aptrepotask.AptRepoTask.java

public void execute() {
    if (repoDir == null) {
        log("repoDir attribute is empty !", LogLevel.ERR.getLevel());
        throw new RuntimeException("Bad attributes for apt-repo task");
    }//from   w w w .  j  a  va2s . co  m
    log("repo dir: " + repoDir);
    File repoFolder = new File(repoDir);
    if (!repoFolder.exists()) {
        repoFolder.mkdirs();
    }
    File[] files = repoFolder.listFiles(new FileFilter() {
        public boolean accept(File pathname) {
            if (pathname.getName().endsWith(FILE_DEB_EXT)) {
                return true;
            }
            return false;
        }
    });
    Packages packages = new Packages();
    for (int i = 0; i < files.length; i++) {
        File file = files[i];
        PackageEntry packageEntry = new PackageEntry();
        packageEntry.setSize(file.length());
        packageEntry.setSha1(Utils.getDigest("SHA-1", file));
        packageEntry.setSha256(Utils.getDigest("SHA-256", file));
        packageEntry.setMd5sum(Utils.getDigest("MD5", file));
        String fileName = file.getName();
        packageEntry.setFilename(fileName);
        log("found deb: " + fileName);
        try {
            ArchiveInputStream control_tgz;
            ArArchiveEntry entry;
            TarArchiveEntry control_entry;
            ArchiveInputStream debStream = new ArchiveStreamFactory().createArchiveInputStream("ar",
                    new FileInputStream(file));
            while ((entry = (ArArchiveEntry) debStream.getNextEntry()) != null) {
                if (entry.getName().equals("control.tar.gz")) {
                    ControlHandler controlHandler = new ControlHandler();
                    GZIPInputStream gzipInputStream = new GZIPInputStream(debStream);
                    control_tgz = new ArchiveStreamFactory().createArchiveInputStream("tar", gzipInputStream);
                    while ((control_entry = (TarArchiveEntry) control_tgz.getNextEntry()) != null) {
                        log("control entry: " + control_entry.getName(), LogLevel.DEBUG.getLevel());
                        if (control_entry.getName().trim().equals(CONTROL_FILE_NAME)) {
                            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
                            IOUtils.copy(control_tgz, outputStream);
                            String content_string = outputStream.toString("UTF-8");
                            outputStream.close();
                            controlHandler.setControlContent(content_string);
                            log("control cont: " + outputStream.toString("utf-8"), LogLevel.DEBUG.getLevel());
                            break;
                        }
                    }
                    control_tgz.close();
                    if (controlHandler.hasControlContent()) {
                        controlHandler.handle(packageEntry);
                    } else {
                        throw new RuntimeException("no control content found for: " + file.getName());
                    }
                    break;
                }
            }
            debStream.close();
            packages.addPackageEntry(packageEntry);
        } catch (Exception e) {
            String msg = FAILED_TO_CREATE_APT_REPO + " " + file.getName();
            log(msg, e, LogLevel.ERR.getLevel());
            throw new RuntimeException(msg, e);
        }
    }
    try {
        File packagesFile = new File(repoDir, PACKAGES_GZ);
        packagesWriter = new BufferedWriter(
                new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(packagesFile))));
        packagesWriter.write(packages.toString());
        DefaultHashes hashes = Utils.getDefaultDigests(packagesFile);
        ReleaseInfo pinfo = new ReleaseInfo(PACKAGES_GZ, packagesFile.length(), hashes);
        Release release = new Release();
        release.addInfo(pinfo);
        final File releaseFile = new File(repoDir, RELEASE);
        FileUtils.fileWrite(releaseFile, release.toString());
    } catch (IOException e) {
        throw new RuntimeException("writing files failed", e);
    } finally {
        if (packagesWriter != null) {
            try {
                packagesWriter.close();
            } catch (IOException e) {
                throw new RuntimeException("writing files failed", e);
            }
        }
    }
}

From source file:org.acdd.ext.cache.CacheManger.java

public boolean vaildCache(String path, String bundleConfigFile) {
    String configHash = ACDDFileUtils.getMD5(bundleConfigFile);
    if (configHash == null) {
        return false;
    }// w  w w .  j  a v  a 2 s  . c o m
    File newConfigFile = new File(cacheFolder, configHash);
    if (newConfigFile.exists() && newConfigFile.isFile()) {
        try {
            String content = org.apache.commons.io.FileUtils.readFileToString(newConfigFile);
            bundleMaps = new JSONObject(content);
            File dir = new File(path);
            File[] rcFiles = dir.listFiles(new FileFilter() {
                @Override
                public boolean accept(File pathname) {
                    if (pathname.getAbsolutePath().endsWith(".so")
                            && pathname.getAbsolutePath().contains("libcom")) {
                        return true;
                    }
                    return false;
                }
            });
            for (File file : rcFiles) {
                String pkg = file.getName().replace("libcom", "com").replace(".so", "").replaceAll("_", ".");
                String pkgHash = ACDDFileUtils.getMD5(file.getAbsolutePath());
                if (pkgHash.equals(bundleMaps.optString(pkg))) {
                    bundleMaps.remove(pkg);
                } else {
                    System.out.println("validCache=====find  unmatched pkg " + pkgHash);
                    System.out.println("=====valid aborted, need produce new config file???");
                    return false;
                }
            }
            if (bundleMaps.length() == 0) {
                return true;
            }

        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }
    return false;
}

From source file:edu.kit.dama.util.release.GenerateSourceRelease.java

public static void copySources(File source, File destination, final ReleaseConfiguration config)
        throws IOException {
    for (String folder : config.getInputDirectories()) {
        File input = new File(source, folder);
        if (!input.exists()) {
            //warn
            continue;
        }//from ww w.j a  v a 2  s  .c o  m
        new File(destination, folder).mkdirs();
        FileUtils.copyDirectory(input, new File(destination, folder), new FileFilter() {

            @Override
            public boolean accept(File pathname) {
                //check folders to ignore
                for (String folder : config.getDirectoriesToIgnore()) {
                    if (pathname.isDirectory() && folder.equals(pathname.getName())) {
                        return false;
                    }
                }

                //check files to ignore
                for (String file : config.getFilesToIgnore()) {
                    if (pathname.isFile() && new WildcardFileFilter(file).accept(pathname)) {
                        return false;
                    }
                }

                return true;
            }
        });
    }

    for (String file : config.getFilesToRemove()) {
        FileUtils.deleteQuietly(new File(destination, file));
    }

    for (String file : config.getInputFiles()) {
        File input = new File(source, file);
        if (input.exists()) {
            FileUtils.copyFile(new File(source, file), new File(destination, file));
        } else {
            //warn
        }
    }
}

From source file:com.googlecode.t7mp.TomcatConfigFilesSetupTest.java

@Test
public void testConfiguratorDefaultConfigFiles() throws MojoExecutionException {
    TomcatDirectorySetup directorySetup = new TomcatDirectorySetup(catalinaBaseDir, log);
    directorySetup.createTomcatDirectories();
    TomcatConfigFilesSetup fileSetup = new TomcatConfigFilesSetup(catalinaBaseDir, log, setupUtil);
    fileSetup.copyDefaultConfig();/*from   www .j a  va  2s . c o  m*/
    File confDir = new File(catalinaBaseDir, "/conf/");
    File[] createdDirectories = confDir.listFiles(new FileFilter() {
        @Override
        public boolean accept(File file) {
            return file.isFile();
        }
    });
    List<String> fileNames = new ArrayList<String>();
    for (File file : createdDirectories) {
        fileNames.add(file.getName());
    }
    Collections.sort(expectedFileNames);
    Collections.sort(fileNames);
    Assert.assertEquals(expectedFileNames, fileNames);
}

From source file:com.googlecode.idea.red5.Red5Utils.java

private static Collection<String> getContextPathsFromDirectory(Red5Model model)
        throws RuntimeConfigurationException {
    File hostDir = new File(hostDir(model.getHomeDirectory()));
    File[] files = hostDir.listFiles(new FileFilter() {
        public boolean accept(File pathname) {
            return StringUtil.endsWithIgnoreCase(pathname.getName(), XML_SUFFIX);
        }//  ww w .  j  a v  a 2 s .c o  m
    });
    Set<String> names = new HashSet<String>();
    if (files != null) {
        for (File file : files) {
            String fName = file.getName();
            names.add("/" + fName.substring(0, fName.length() - 4));
        }
    }
    return names;
}

From source file:org.alfresco.bm.file.FileDataServiceTest.java

@BeforeClass
public static void setUp() throws IOException {
    // Create a test file
    File tempDir = new File(System.getProperty("java.io.tmpdir"));
    File testFiles = new File(tempDir, "FileDataServiceTest");
    testFiles.mkdirs();/*w w  w.j  a v  a 2  s  .c  om*/
    File testFile = new File(testFiles, "test.txt");
    if (!testFile.exists()) {
        String text = "SOME TEXT";
        Files.write(text, testFile, Charsets.UTF_8);
    }

    File localDir = new File(System.getProperty("java.io.tmpdir") + "/" + "fileset-123");
    if (localDir.exists()) {
        localDir.delete();
    }

    Properties props = new Properties();
    props.put("test.mongoCollection", COLLECTION_BM_FILE_DATA_SERVICE);
    props.put("test.localDir", localDir.getCanonicalFile());
    props.put("test.ftpHost", "ftp.mirrorservice.org");
    props.put("test.ftpPort", "21");
    props.put("test.ftpUsername", "anonymous");
    props.put("test.ftpPassword", "");
    props.put("test.ftpPath", "/sites/www.linuxfromscratch.org/images");
    props.put("test.testFileDir", testFiles.getCanonicalPath());

    ctx = new ClassPathXmlApplicationContext(new String[] { "test-MongoFileDataTest-context.xml" }, false);
    ctx.getEnvironment().getPropertySources().addFirst(new PropertiesPropertySource("TestProps", props));
    ctx.refresh();
    ctx.start();

    // Get the new beans
    fileDataService = ctx.getBean(FileDataService.class);
    ftpTestFileService = ctx.getBean(FtpTestFileService.class);
    localTestFileService = ctx.getBean(LocalTestFileService.class);

    // Do a directory listing and use that as the dataset
    File randomDir = new File(System.getProperty("user.dir"));
    File[] localFiles = randomDir.listFiles(new FileFilter() {
        @Override
        public boolean accept(File pathname) {
            return !pathname.isDirectory();
        }
    });
    fileDatas = new FileData[localFiles.length];
    for (int i = 0; i < localFiles.length; i++) {
        String remoteName = localFiles[i].getName();
        if (remoteName.length() == 0) {
            continue;
        }
        fileDatas[i] = FileDataServiceTest.createFileData(remoteName);
    }
}

From source file:me.totalfreedom.totalfreedommod.util.FUtil.java

public static void deleteCoreDumps() {
    final File[] coreDumps = new File(".").listFiles(new FileFilter() {
        @Override//from w  ww.j  a  v  a 2  s .c om
        public boolean accept(File file) {
            return file.getName().startsWith("java.core");
        }
    });

    for (File dump : coreDumps) {
        FLog.info("Removing core dump file: " + dump.getName());
        dump.delete();
    }
}

From source file:org.n52.car.io.schema.Validation.java

private List<String> findSchemas() throws URISyntaxException {
    URL url = getClass().getResource("/schema");
    File baseDir = new File(url.toURI());
    File[] files = baseDir.listFiles(new FileFilter() {
        @Override/* w ww  .  j  av  a2 s .  c o m*/
        public boolean accept(File pathname) {
            return pathname.getName().endsWith(".json");
        }
    });

    List<String> result = new ArrayList<String>(files.length);
    String path;
    for (File f : files) {
        path = f.getAbsolutePath();
        result.add(path.substring(path.lastIndexOf("/schema"), path.length()));
    }
    return result;
}

From source file:com.intellij.diagnostic.SubmitPerformanceReportAction.java

@Override
public void actionPerformed(final AnActionEvent e) {
    String reportFileName = "perf_" + ApplicationInfo.getInstance().getBuild().asString() + "_"
            + SystemProperties.getUserName() + "_" + myDateFormat.format(new Date()) + ".zip";
    final File reportPath = new File(SystemProperties.getUserHome(), reportFileName);
    final File logDir = new File(PathManager.getLogPath());
    final Project project = e.getData(CommonDataKeys.PROJECT);

    final boolean[] archiveCreated = new boolean[1];
    final boolean completed = ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {
        @Override//  w ww  .j  a  v a  2 s .com
        public void run() {
            try {
                ZipOutputStream zip = new ZipOutputStream(new FileOutputStream(reportPath));
                ZipUtil.addDirToZipRecursively(zip, reportPath, logDir, "", new FileFilter() {
                    @Override
                    public boolean accept(final File pathname) {
                        ProgressManager.checkCanceled();

                        if (logDir.equals(pathname.getParentFile())) {
                            return pathname.getPath().contains("threadDumps");
                        }
                        return true;
                    }
                }, null);
                zip.close();
                archiveCreated[0] = true;
            } catch (final IOException ex) {
                ApplicationManager.getApplication().invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        Messages.showErrorDialog(project,
                                "Failed to create performance report archive: " + ex.getMessage(),
                                MESSAGE_TITLE);
                    }
                });
            }
        }
    }, "Collecting Performance Report data", true, project);

    if (!completed || !archiveCreated[0]) {
        return;
    }

    int rc = Messages.showYesNoDialog(project,
            "The performance report has been saved to\n" + reportPath
                    + "\n\nWould you like to submit it to JetBrains?",
            MESSAGE_TITLE, Messages.getQuestionIcon());
    if (rc == Messages.YES) {
        ProgressManager.getInstance().run(new Task.Backgroundable(project, "Uploading Performance Report") {
            @Override
            public void run(@NotNull final ProgressIndicator indicator) {
                final String error = uploadFileToFTP(reportPath, "ftp.intellij.net", ".uploads", indicator);
                if (error != null) {
                    ApplicationManager.getApplication().invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            Messages.showErrorDialog(error, MESSAGE_TITLE);
                        }
                    });
                }
            }
        });
    }
}

From source file:com.meltmedia.cadmium.deployer.JBossUtil.java

public static List<String> listDeployedWars(final Logger log) {
    File deployDirectory = getDeployDirectory(log);
    File wars[] = deployDirectory.listFiles(new FileFilter() {

        @Override//from  w ww.j av  a 2 s . co m
        public boolean accept(File file) {
            if (file.getName().endsWith(".war")) {
                return isCadmiumWar(file, log);
            }
            return false;
        }

    });
    List<String> cadmiumWars = new ArrayList<String>();
    for (File war : wars) {
        cadmiumWars.add(war.getName());
    }
    return cadmiumWars;
}