List of usage examples for java.io FilenameFilter FilenameFilter
FilenameFilter
From source file:interactivespaces.workbench.tasks.WorkbenchTaskContext.java
/** * Add all extension classpath entries that the controller specifies. * * @param classpath//from ww w .j a v a 2 s. c o m * the list of files to add to * @param extraComponent * the extra component to add */ public void addExtrasControllerExtensionsClasspath(List<File> classpath, String extraComponent) { File[] extraComponentFiles = new File( new File(workbench.getWorkbenchFileSystem().getInstallDirectory(), EXTRAS_BASE_FOLDER), extraComponent).listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.endsWith(FILENAME_JAR_EXTENSION); } }); if (extraComponentFiles != null) { Collections.addAll(classpath, extraComponentFiles); } }
From source file:com.frostwire.gui.updates.InstallerUpdater.java
private void cleanupOldUpdates() { final Pattern p = Pattern .compile("^frostwire-([0-9]+[0-9]?\\.[0-9]+[0-9]?\\.[0-9]+[0-9]?)(.*?)(\\.torrent)?$"); for (File f : UpdateSettings.UPDATES_DIR.listFiles(new FilenameFilter() { @Override/* w ww. j av a 2 s . c om*/ public boolean accept(File dir, String name) { Matcher m = p.matcher(name); if (m.matches()) { return !m.group(1).equals(_updateMessage.getVersion()); } return false; } })) { f.delete(); } }
From source file:eu.optimis.ip.gui.server.IPManagerWebServiceImpl.java
@Override public ArrayList<String> getFileList(String selectedComponent) { ArrayList<String> ret = new ArrayList<String>(); File dir = null;//ww w . j a va 2 s. c o m if (!selectedComponent.equalsIgnoreCase("OPTIMIS Global")) { dir = new File(ConfigManager.getFilePath(ConfigManager.COMPONENT_CONFIGURATION_FOLDER) + "/" + selectedComponent); } else { dir = new File(ConfigManager.getFilePath(ConfigManager.COMPONENT_CONFIGURATION_FOLDER)); } File[] files = dir.listFiles(new FilenameFilter() { public boolean accept(File dir, String name) { return name.toLowerCase().endsWith(".properties"); } }); for (File file : files) { ret.add(file.getName()); } return ret; }
From source file:com.hp.test.framework.Utlis.java
public static int getLastRun(String path) { File file = new File(path + "\\results\\"); String[] directories = file.list(new FilenameFilter() { @Override/* w w w .j a v a2 s.c o m*/ public boolean accept(File current, String name) { return new File(current, name).isDirectory(); } }); String temp_ar[] = directories[0].split("_"); int max = Integer.parseInt(temp_ar[1]); for (int i = 1; i < directories.length; i++) { String temp_ar1[] = directories[i].split("_"); int run = Integer.parseInt(temp_ar1[1]); if (run > max) { max = run; } } System.out.println(Arrays.toString(directories)); System.out.println("Latest Run" + max); return max; }
From source file:com.esri.squadleader.controller.AdvancedSymbolController.java
@Override public String getMessageLayerName(String messageType) { if (null == messageType) { return null; }//from w w w.j ava 2 s. c o m if (SpotReportController.REPORT_TYPE.equals(messageType)) { return SPOT_REPORT_LAYER_NAME; } File messageTypesDir = new File(symDictDir, "MessageTypes"); File[] files = messageTypesDir.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String filename) { return null != filename && filename.toLowerCase(Locale.getDefault()).endsWith(".json"); } }); for (File file : files) { BufferedReader in = null; try { in = new BufferedReader(new FileReader(file)); StringBuffer sb = new StringBuffer(); String line = null; while (null != (line = in.readLine())) { sb.append(line); } JSONObject obj = new JSONObject(sb.toString()); if (messageType.equals(obj.getString("type"))) { return obj.getString("layerName"); } } catch (Throwable t) { Log.e(TAG, "Could not read and parse " + file.getAbsolutePath(), t); } finally { if (null != in) { try { in.close(); } catch (IOException e) { Log.e(TAG, "Could not close file", e); } } } } return null; }
From source file:org.ambraproject.admin.service.impl.DocumentManagementServiceImpl.java
/** * @return List of filenames of files in uploadable directory on server *//* w ww . j a v a 2s.c om*/ @Override public List<String> getUploadableFiles() { List<String> documents = new ArrayList<String>(); File dir = new File(documentDirectory); if (dir.isDirectory()) { Collections.addAll(documents, dir.list(new FilenameFilter() { //check the file extensions public boolean accept(File file, String fileName) { for (String extension : new String[] { ".tar", ".tar.bz", ".tar.bz2", ".tar.gz", ".tb2", ".tbz", ".tbz2", ".tgz", ".zip" }) { if (fileName.endsWith(extension)) { return true; } } return false; } })); } Collections.sort(documents); return documents; }
From source file:com.kyne.webby.rtk.web.WebServer.java
@SuppressWarnings("unchecked") public JSONObject getBackupJSON() { final JSONArray dateListJSON = new JSONArray(); final File backupDir = new File("Backups"); if (!backupDir.exists()) { backupDir.mkdir();/*from ww w .j av a 2 s. co m*/ } final File[] backupFiles = backupDir.listFiles(new FilenameFilter() { @Override public boolean accept(final File dir, final String name) { return new File(dir, name).isFile() && name.endsWith("zip"); } }); final SimpleDateFormat zipFormat = new SimpleDateFormat("yyyyMMdd_HHmmss"); final SimpleDateFormat friendlyFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); final SimpleDateFormat dayFormat = new SimpleDateFormat("yyyy-MM-dd"); final Map<Date, List<File>> backupByDays = new HashMap<Date, List<File>>(); for (final File backupFile : backupFiles) { Date backupDate = null; Date backupDay = null; try { backupDate = zipFormat.parse(backupFile.getName()); final String day = dayFormat.format(backupDate); backupDay = dayFormat.parse(day); } catch (final ParseException e) { LogHelper.warn("The backup file " + backupFile.getName() + " is not well formed. Format should be yyyyMMdd_HHmmss.zip"); } if (!backupByDays.containsKey(backupDay)) { backupByDays.put(backupDay, new ArrayList<File>()); } backupByDays.get(backupDay).add(backupFile); } final ArrayList<Date> sortedDays = new ArrayList<Date>(backupByDays.keySet()); Collections.sort(sortedDays, new Comparator<Date>() { @Override public int compare(final Date o1, final Date o2) { return o2.compareTo(o1); } }); final double MB = 1024 * 1024; for (final Date day : sortedDays) { final String dayStr = dayFormat.format(day); final JSONObject dateJSON = new JSONObject(); final JSONArray backups = new JSONArray(); for (final File backupFile : backupByDays.get(day)) { final JSONObject backup = new JSONObject(); Date backupDate = null; try { backupDate = zipFormat.parse(backupFile.getName()); } catch (final ParseException e) { /**/ } backup.put("date", backupDate == null ? "???" : friendlyFormat.format(backupDate)); final long byteSize = backupFile.length(); backup.put("size", NumberFormat.getInstance().format(byteSize / MB) + " MB"); backup.put("name", backupFile.getName()); backups.add(backup); } dateJSON.put("day", dayStr); dateJSON.put("backups", backups); dateListJSON.add(dateJSON); } final JSONObject backupJSON = new JSONObject(); backupJSON.put("dates", dateListJSON); return backupJSON; }
From source file:com.otway.picasasync.syncutil.AlbumSync.java
private void updateFolderTimeStamp(File localFolder) { long maxDate = 0; File[] files = localFolder.listFiles(new FilenameFilter() { public boolean accept(File current, String name) { File file = new File(current, name); return file.isFile() && !file.isHidden(); }//from ww w . j a v a 2 s .c o m }); if (files != null) { for (File file : files) if (file.lastModified() > maxDate) maxDate = file.lastModified(); if (!localFolder.setLastModified(maxDate)) log.debug("Unable to set modification date for " + localFolder); } }
From source file:net.jawr.web.bundle.processor.BundleProcessor.java
/** * Initialize the classloader// w w w. j a v a 2 s .c om * * @param baseDirPath * the base directory path * @return the class loader * @throws MalformedURLException */ protected ClassLoader initClassLoader(String baseDirPath) throws MalformedURLException { File webAppClasses = new File(baseDirPath + WEB_INF_CLASSES_DIR_PATH); File[] webAppLibs = new File(baseDirPath + WEB_INF_LIB_DIR_PATH).listFiles(new FilenameFilter() { public boolean accept(File dir, String name) { return name.endsWith(JAR_FILE_EXTENSION); } }); int length = webAppLibs != null ? webAppLibs.length + 1 : 1; URL[] urls = new URL[length]; urls[0] = webAppClasses.toURI().toURL(); for (int i = 1; i < length; i++) { urls[i] = webAppLibs[i - 1].toURI().toURL(); } ClassLoader webAppClassLoader = new JawrBundleProcessorCustomClassLoader(urls, getClass().getClassLoader()); Thread.currentThread().setContextClassLoader(webAppClassLoader); return webAppClassLoader; }