List of usage examples for java.io FileFilter FileFilter
FileFilter
From source file:de.dakror.villagedefense.util.SaveHandler.java
public static File[] getSaves() { return new File(CFG.DIR, "saves").listFiles(new FileFilter() { @Override// ww w . ja v a 2s. c o m public boolean accept(File pathname) { return pathname.getName().endsWith(".save"); } }); }
From source file:dk.netarkivet.harvester.harvesting.ArchiveFilesReportGenerator.java
/** * Parses heritrix.out and generates the ARC/WARC files report. * @return the generated report file./*w w w . j a va 2 s.co m*/ */ protected File generateReport() { Map<String, ArchiveFileStatus> reportContents = parseHeritrixOut(); File reportFile = new File(crawlDir, REPORT_FILE_NAME); try { boolean created = reportFile.createNewFile(); if (!created) { throw new IOException("Unable to create '" + reportFile.getAbsolutePath() + "'."); } PrintWriter out = new PrintWriter(reportFile); out.println(REPORT_FILE_HEADER); HashSet<String> arcFilesFromHeritrixOut = new HashSet<String>(); for (Map.Entry<String, ArchiveFilesReportGenerator.ArchiveFileStatus> entry : reportContents .entrySet()) { String arcFileName = entry.getKey(); arcFilesFromHeritrixOut.add(arcFileName); ArchiveFileStatus afs = entry.getValue(); out.println(arcFileName + " " + afs.toString()); } // Inspect the contents of the local ARC folder //TODO check if this value is configurable File localArchiveFolder = new File(crawlDir, ARCHIVE_FORMAT + "s"); if (localArchiveFolder.exists() && localArchiveFolder.isDirectory()) { File[] localArchiveFiles = localArchiveFolder.listFiles(new FileFilter() { @Override public boolean accept(File f) { return f.isFile() && f.getName().contains("." + ARCHIVE_FORMAT); } }); for (File f : localArchiveFiles) { String arcFileName = f.getName(); if (!arcFilesFromHeritrixOut.contains(arcFileName)) { ArchiveFileStatus afs = new ArchiveFileStatus(); afs.setSize(f.length()); out.println(arcFileName + " " + afs.toString()); } } } out.close(); } catch (IOException e) { throw new IOFailure("Failed to create " + reportFile.getName(), e); } return reportFile; }
From source file:architecture.ee.plugin.impl.PluginManagerImpl.java
protected ClassLoader createPluginChainingClassloader() { ClassLoader parent = Thread.currentThread().getContextClassLoader(); if (parent == null) parent = ApplicationHelper.class.getClassLoader(); if (ApplicationHelper.isSetupComplete()) { File pluginDir = ApplicationHelper.getRepository().getFile("plugins"); pluginDir.mkdirs();//w w w. j a v a2 s .c o m File pluginDirs[] = pluginDir.listFiles(new FileFilter() { public boolean accept(File pathname) { return pathname.isDirectory(); } }); List pluginClassLoaders = Lists.newArrayList(); for (File f : pluginDirs) { PluginClassLoader pcl = getPluginClassloader(f.getName(), f); pluginClassLoaders.add(pcl.getClassLoader()); } if (Boolean.parseBoolean(System.getProperty("jive.devMode", "false"))) { List<String> devPluginPaths = PluginUtils.getDevPluginPaths(); for (String path : devPluginPaths) { File dir = new File(path); if (dir.exists()) { PluginClassLoader pcl = getPluginClassloader(dir.getName(), dir); pluginClassLoaders.add(pcl.getClassLoader()); } } } ChainingClassLoader classLoader = new ChainingClassLoader(parent, pluginClassLoaders); return classLoader; } else { return parent; } }
From source file:com.xtructure.xevolution.tool.impl.ReadPopulationsTool.java
/** * Creates a new {@link ReadPopulationsTool}. * /* w w w.j av a2s . c om*/ * @param dataTracker */ public ReadPopulationsTool(DataTracker<?, ?> dataTracker) { super("readPopulations", // new BooleanXOption(HELP, "h", "help", "print usage"), // new BooleanXOption(CONTINUOUS_READ, "c", "continuous", "continue reading files"), // new BooleanXOption(VERBOSE, "v", "verbose", "print progess"), // new BooleanXOption(RESUME, "r", "resume", "resume from previously built data (otherwise, all files in data directory will be erased)"), // new FileXOption(POPULATION_DIRECTORY, "p", "populations", "directory containing population files"), // new FileXOption(DATA_DIRECTORY, "d", "data", "directory to which data is written")); this.dataTracker = dataTracker; this.worker = new Thread(new Runnable() { private long latest; @Override public void run() { latest = readLatest(); try { // load existing data if (verbose) { System.out.println("Loading data..."); } ReadPopulationsTool.this.dataTracker.load(dataDir); if (verbose) { System.out.println("\tdone."); } while (true) { // collect population files File[] newFiles = populationDir.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return pathname.lastModified() > latest && pathname.getName().endsWith(".xml"); } }); if (newFiles.length == 0) { if (verbose) { System.out.println("no new files, waiting..."); } try { // polling for now... Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); break; } if (continuousRead) { continue; } else { break; } } Arrays.sort(newFiles, new Comparator<File>() { @Override public int compare(File o1, File o2) { Matcher matcher = POPULATION_FILE_PATTERN.matcher(o1.getName()); if (matcher.matches()) { int age1 = Integer.parseInt(matcher.group(1)); matcher = POPULATION_FILE_PATTERN.matcher(o2.getName()); if (matcher.matches()) { int age2 = Integer.parseInt(matcher.group(1)); return age1 - age2; } } return o1.compareTo(o2); } }); // process population files for (File populationFile : newFiles) { latest = Math.max(latest, populationFile.lastModified()); if (verbose) { System.out.println("Processing population : " + populationFile.getName()); } for (int j = 0; j < RETRIES; j++) { popLock.lock(); try { if (ReadPopulationsTool.this.dataTracker .processPopulation(populationFile) != null) { // success break; } } finally { popLock.unlock(); } // failed to read population, wait and try again try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } } try { ReadPopulationsTool.this.dataTracker.write(dataDir); } catch (IOException e) { e.printStackTrace(); } } writeLatest(latest); if (!continuousRead) { break; } } } catch (IOException e) { e.printStackTrace(); } catch (org.json.simple.parser.ParseException e) { e.printStackTrace(); } } }); }
From source file:de.tudarmstadt.lt.lm.app.Ngrams.java
@Override public void run() { _num_ngrams = 0l;/*w w w . j a v a2 s .c o m*/ _ngram = new FixedSizeFifoLinkedList<>(_order_to); _pout = System.out; if (!"-".equals(_out.trim())) { try { if (_out.endsWith(".gz")) _pout = new PrintStream(new GZIPOutputStream(new FileOutputStream(new File(_out)))); else _pout = new PrintStream(new FileOutputStream(new File(_out), true)); } catch (IOException e) { LOG.error("Could not open ouput file '{}' for writing.", _out, e); System.exit(1); } } try { if (_prvdr == null) { _prvdr = StartLM.getStringProviderInstance(_provider_type); _prvdr.setLanguageModel(new DummyLM<>(_order_to)); } } catch (Exception e) { LOG.error("Could not initialize Ngram generator. {}: {}", e.getClass(), e.getMessage(), e); } if ("-".equals(_file.trim())) { LOG.info("Processing text from stdin ('{}').", _file); try { run(new InputStreamReader(System.in, "UTF-8"), _file); } catch (Exception e) { LOG.error("Could not generate ngram from from file '{}'.", _file, e); } } else { File f_or_d = new File(_file); if (!f_or_d.exists()) throw new Error(String.format("File or directory '%s' not found.", _file)); if (f_or_d.isFile()) { LOG.info("Processing file '{}'.", f_or_d.getAbsolutePath()); try { run(new InputStreamReader(new FileInputStream(f_or_d), "UTF-8"), _file); } catch (Exception e) { LOG.error("Could not generate ngrams from file '{}'.", f_or_d.getAbsolutePath(), e); } } if (f_or_d.isDirectory()) { File[] txt_files = f_or_d.listFiles(new FileFilter() { @Override public boolean accept(File f) { return f.isFile() && f.getName().endsWith(".txt"); } }); for (int i = 0; i < txt_files.length; i++) { File f = txt_files[i]; LOG.info("Processing file '{}' ({}/{}).", f.getAbsolutePath(), i + 1, txt_files.length); try { run(new InputStreamReader(new FileInputStream(f), "UTF-8"), f.getAbsolutePath()); } catch (Exception e) { LOG.error("Could not generate ngrams from file '{}'.", f.getAbsolutePath(), e); } } } } LOG.info("Generated {} ngrams.", _num_ngrams); if (!"-".equals(_out.trim())) _pout.close(); }
From source file:com.yifanlu.PSXperiaTool.Extractor.CrashBandicootExtractor.java
private void extractZpaks() throws IOException { nextStep("Extracting ZPAKS"); WildcardFileFilter ff = new WildcardFileFilter("*.zpak"); File[] candidates = (new File(mOutputDir, "/assets")).listFiles((FileFilter) ff); if (candidates == null || candidates.length < 1) throw new FileNotFoundException("Cannot find the default ZPAK under /assets"); else if (candidates.length > 1) Logger.warning("Found more than one default ZPAK under /assets. Using the first one."); File defaultZpak = candidates[0]; extractZip(defaultZpak, new File(mOutputDir, "/assets/ZPAK"), null); FileFilter filter = new FileFilter() { public boolean accept(File file) { if (file.getName().equals("image.ps")) return false; if (file.getParentFile() == null) return true; if (file.getParentFile().getName().equals("manual")) return false; return true; }/*from w ww . j a v a 2s. com*/ }; extractZip(mZpakData, new File(mOutputDir, "/ZPAK"), filter); defaultZpak.delete(); }
From source file:frankhassanabad.com.github.Jasperize.java
/** * Compiles all the jrxml template files into an output directory. This does just a one directory * deep scan for files.//from w w w . j ava 2 s.c o m * @param inputDirectory The input directory containing all the jrxml's. * @param outputDirectory The output directory to put all the .jasper files. * @throws JRException If there's any problems compiling a jrxml, this will get thrown. */ private static void compileAllJrxmlTemplateFiles(String inputDirectory, String outputDirectory) throws JRException { //compile all .jrxml's from the JasperTemplates directory into the jasperOutput directory. File jrxmlInputFolder = new File(inputDirectory); File[] jrxmlFiles = jrxmlInputFolder.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return pathname.getName().endsWith("jrxml"); } }); for (File jrxmlFileFile : jrxmlFiles) { String inputFile = jrxmlFileFile.getPath(); String nameWithNoExtension = jrxmlFileFile.getName().split("\\.")[0]; String outputFile = outputDirectory + File.separator + nameWithNoExtension + ".jasper"; System.out.println("Compiling: " + jrxmlFileFile); Reporting.compile(inputFile, outputFile); } }
From source file:org.mwc.debrief.editable.test.EditableTests.java
private void openProjects(File rootFile) throws CoreException { File[] files = rootFile.listFiles(new FileFilter() { @Override/*from ww w. ja v a 2s . co m*/ public boolean accept(File pathname) { if (!pathname.isDirectory()) { return false; } if (!pathname.getName().startsWith("org.mwc")) { return false; } if (pathname.getName().endsWith(".test") || pathname.getName().endsWith(".tests") || pathname.getName().endsWith(".test2") || pathname.getName().endsWith(".feature") || pathname.getName().endsWith(".site") || pathname.getName().endsWith(".media") || pathname.getName().endsWith(".GNDManager")) { return false; } return true; } }); if (files == null) { return; } for (File file : files) { File projectFile = new File(file, ".project"); if (!projectFile.isFile()) { continue; } IProject project; IPath path = new Path(projectFile.getAbsolutePath()); IProjectDescription description = ResourcesPlugin.getWorkspace().loadProjectDescription(path); project = ResourcesPlugin.getWorkspace().getRoot().getProject(description.getName()); project.create(description, null); project.open(null); project.refreshLocal(IResource.DEPTH_INFINITE, null); } }
From source file:com.sun.socialsite.business.impl.JPAAppManagerImpl.java
public void initialize() throws InitializationException { String preLoadDirectoryPath = Config.getProperty("socialsite.gadgets.preload.path"); log.debug("socialsite.gadgets.preload.path: " + preLoadDirectoryPath); String baseUrl = Config.getProperty("socialsite.gadgets.preload.base.url"); log.debug("socialsite.gadgets.preload.base.url: " + baseUrl); ListenerManager listenerManager = Factory.getSocialSite().getListenerManager(); listenerManager.addListener(AppRegistration.class, new AppRegistrationListener()); PermissionManager permissionManager = Factory.getSocialSite().getPermissionManager(); // For now, auto-grant so that any person can execute any app try {/* w w w . jav a 2 s.c o m*/ PermissionGrant pg = new PermissionGrant(); pg.setType(AppPermission.class.getName()); pg.setName("*"); pg.setActions("read,execute"); pg.setProfileId("*"); permissionManager.savePermissionGrant(pg); Factory.getSocialSite().flush(); } catch (SocialSiteException e) { String msg = "Failed to grant AppPermission(*,'read,execute') to all users"; log.error(msg, e); } // For now, auto-grant so that any app can retrieve any URL via makeRequest try { PermissionGrant pg = new PermissionGrant(); pg.setType(HttpPermission.class.getName()); pg.setName("*"); pg.setActions("DELETE,GET,HEAD,POST,PUT"); pg.setGadgetDomain("*"); permissionManager.savePermissionGrant(pg); Factory.getSocialSite().flush(); } catch (SocialSiteException e) { String msg = "Failed to grant HttpPermission(*,*) to all apps"; log.error(msg, e); } if (preLoadDirectoryPath != null) { File preLoadDirectory = new File(preLoadDirectoryPath); if (!preLoadDirectory.exists()) { String msg = String.format("Gadgets dir (%s) not found", preLoadDirectoryPath); throw new InitializationException(msg); } if (!preLoadDirectory.exists()) { String msg = String.format("Gadgets dir (%s) is not a directory", preLoadDirectoryPath); throw new InitializationException(msg); } File[] files = preLoadDirectory.listFiles(new FileFilter() { public boolean accept(File f) { return f.getName().endsWith(".xml"); } }); log.debug("Loading registered apps, count = " + files.length); for (int i = 0; i < files.length; i++) { if (!files[i].isDirectory()) { try { URL url = new URL(baseUrl + "/" + files[i].getName()); App app = getAppByURL(url, true); if (app == null) { log.info("Loading Gadget " + files[i].getAbsolutePath() + " to URL " + url); app = App.readFromStream(new FileInputStream(files[i]), url); strategy.store(app); strategy.flush(); strategy.release(); } if (permissionManager.getPermissionGrants(app, 0, -1).size() == 0) { grantPermission(permissionManager, FeaturePermission.class, "*", app); Factory.getSocialSite().flush(); } } catch (Exception e) { String msg = String.format("Failed to read gadget spec: %s", files[i].getAbsolutePath()); log.error(msg, e); } } } try { List<AppRegistration> appregs = getAppRegistrations(null, "APPROVED"); log.debug("Loading registered apps, count = " + appregs.size()); for (AppRegistration appreg : appregs) { try { log.info("Checking Gadget Spec URL " + appreg.getAppUrl()); URL url = new URL(appreg.getAppUrl()); App app = getAppByURL(url, true); if (app == null) { log.info(" Adding " + appreg.getAppUrl()); app = App.readFromStream(new BufferedInputStream(url.openConnection().getInputStream()), url); app.setShowInDirectory(Boolean.TRUE); strategy.store(app); strategy.flush(); strategy.release(); } if (permissionManager.getPermissionGrants(app, 0, -1).size() == 0) { grantPermission(permissionManager, FeaturePermission.class, "*", app); Factory.getSocialSite().flush(); } } catch (Exception ex) { log.error("ERROR reading a registered gadget at URL: " + appreg.getAppUrl(), ex); } } } catch (SocialSiteException ex) { String msg = String.format("Failed to read app registration data"); log.error(msg, ex); } } }
From source file:BackupFiles.java
/** * Gets the files in the specified directory * //from w w w . j ava2 s . c om * @param arg0 * a String containing the directory */ public Object[] getElements(Object arg0) { File file = new File((String) arg0); if (file.isDirectory()) { return file.listFiles(new FileFilter() { public boolean accept(File pathName) { // Ignore directories; return only files return pathName.isFile(); } }); } return EMPTY; }