List of usage examples for java.io FileFilter FileFilter
FileFilter
From source file:com.github.braully.graph.UtilResultMerge.java
public static void processDirectory(File file, String[] excludes) throws FileNotFoundException, NumberFormatException, IOException { if (file == null || file.isFile()) { return;/*from ww w . j a va2 s. c o m*/ } File ftmp = new File(file, "resultado"); if (!ftmp.exists() || !ftmp.isDirectory()) { File[] files = file.listFiles(new FileFilter() { public boolean accept(File file) { if (file != null && file.isDirectory()) { return true; } return false; } }); if (files != null) { for (File f : files) { processDirectory(f, excludes); } } return; } File[] files = ftmp.listFiles(new FileFilter() { public boolean accept(File file) { if (file != null && file.isFile() && file.getName().startsWith("resultado-") && (file.getName().endsWith(".txt") || file.getName().endsWith(".txt.gz"))) { return true; } return false; } }); if (files != null) { List<File> listFiles = BatchExecuteOperation.sortFileArrayByName(files); for (File f : listFiles) { if (verbose) { System.out.println("Process: " + f); } processFile(f, file.getName(), excludes); } } }
From source file:com.willowtreeapps.androidcontentprovidergenerator.Main.java
private void loadModel(File inputDir) throws IOException, JSONException { File[] entityFiles = inputDir.listFiles(new FileFilter() { @Override//from w ww. j a v a 2 s . c om public boolean accept(File pathname) { return !pathname.getName().startsWith("_") && pathname.getName().endsWith(".json"); } }); for (File entityFile : entityFiles) { if (Config.LOGD) Log.d(TAG, entityFile.getCanonicalPath()); String entityName = FilenameUtils.getBaseName(entityFile.getCanonicalPath()); if (Config.LOGD) Log.d(TAG, "entityName=" + entityName); Entity entity = new Entity(entityName); String fileContents = FileUtils.readFileToString(entityFile); JSONObject entityJson = new JSONObject(fileContents); entity.setUrl(entityJson.optString("urlPath")); // Fields JSONArray fieldsJson = entityJson.getJSONArray("fields"); int len = fieldsJson.length(); for (int i = 0; i < len; i++) { JSONObject fieldJson = fieldsJson.getJSONObject(i); if (Config.LOGD) Log.d(TAG, "fieldJson=" + fieldJson); String name = fieldJson.getString(Field.Json.NAME); String serializedName = fieldJson.optString(Field.Json.SERIALIZED_NAME); String type = fieldJson.getString(Field.Json.TYPE); boolean isIndex = fieldJson.optBoolean(Field.Json.INDEX, false); boolean isNullable = fieldJson.optBoolean(Field.Json.NULLABLE, true); String defaultValue = fieldJson.optString(Field.Json.DEFAULT_VALUE); String enumName = fieldJson.optString(Field.Json.ENUM_NAME); JSONArray enumValuesJson = fieldJson.optJSONArray(Field.Json.ENUM_VALUES); List<String> enumValues = new ArrayList<String>(); if (enumValuesJson != null) { int enumLen = enumValuesJson.length(); for (int j = 0; j < enumLen; j++) { String valueName = enumValuesJson.getString(j); enumValues.add(valueName); } } Field field = new Field(name, serializedName, type, isIndex, isNullable, defaultValue, enumName, enumValues); entity.addField(field); } // Constraints (optional) JSONArray constraintsJson = entityJson.optJSONArray("constraints"); if (constraintsJson != null) { len = constraintsJson.length(); for (int i = 0; i < len; i++) { JSONObject constraintJson = constraintsJson.getJSONObject(i); if (Config.LOGD) Log.d(TAG, "constraintJson=" + constraintJson); String name = constraintJson.getString(Constraint.Json.NAME); String definition = constraintJson.getString(Constraint.Json.DEFINITION); Constraint constraint = new Constraint(name, definition); entity.addConstraint(constraint); } } // QueryParams (optional) JSONArray paramsJson = entityJson.optJSONArray("queryParams"); if (paramsJson != null) { len = paramsJson.length(); for (int i = 0; i < len; i++) { JSONObject constraintJson = paramsJson.getJSONObject(i); String name = constraintJson.getString(Constraint.Json.NAME); entity.addQueryParam(name); } } Model.get().addEntity(entity); } // Header (optional) File headerFile = new File(inputDir, "header.txt"); if (headerFile.exists()) { String header = FileUtils.readFileToString(headerFile).trim(); Model.get().setHeader(header); } if (Config.LOGD) Log.d(TAG, Model.get().toString()); }
From source file:WebstartLauncher.java
private List<String> listJars() { File[] jars = new File(libraryResourceDir).listFiles(new FileFilter() { public boolean accept(File pathname) { return pathname.getName().toLowerCase().endsWith(".jar"); }// w ww .j a va 2s . c o m }); return toUrlFormat(jars); }
From source file:org.alfresco.services.ModelTracker.java
/** * @param alfrescoModelDir//w w w. j a va 2 s. com * @param modelName */ private void removeMatchingModels(File alfrescoModelDir, QName modelName) { final String prefix = modelName.toPrefixString(namespaceService).replace(":", ".") + "."; final String postFix = ".xml"; File[] toDelete = alfrescoModelDir.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { if (pathname.isDirectory()) { return false; } String name = pathname.getName(); if (false == name.endsWith(postFix)) { return false; } if (false == name.startsWith(prefix)) { return false; } // check is number between String checksum = name.substring(prefix.length(), name.length() - postFix.length()); try { Long.parseLong(checksum); return true; } catch (NumberFormatException nfe) { return false; } } }); if (toDelete != null) { for (File file : toDelete) { file.delete(); } } }
From source file:eu.esdihumboldt.util.scavenger.AbstractResourceScavenger.java
/** * @see ResourceScavenger#triggerScan()//w w w .ja v a 2s .c o m */ @Override public void triggerScan() { synchronized (resources) { if (huntingGrounds != null) { if (huntingGrounds.isDirectory()) { // scan for sub-directories Set<String> foundIds = new HashSet<String>(); File[] resourceDirs = huntingGrounds.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { // accept non-hidden directories return pathname.isDirectory() && !pathname.isHidden(); } }); for (File resourceDir : resourceDirs) { String resourceId = resourceDir.getName(); foundIds.add(resourceId); if (!resources.containsKey(resourceId)) { // resource reference not loaded yet T reference; try { reference = loadReference(resourceDir, null, resourceId); resources.put(resourceId, reference); onAdd(reference, resourceId); } catch (IOException e) { log.error("Error creating resource reference", e); } } else { // update existing resource updateResource(resources.get(resourceId), resourceId); } } Set<String> removed = new HashSet<String>(resources.keySet()); removed.removeAll(foundIds); // deal with resources that have been removed for (String resourceId : removed) { T reference = resources.remove(resourceId); if (reference != null) { // remove active environment onRemove(reference, resourceId); } } } else { // one project mode if (!resources.containsKey(DEFAULT_RESOURCE_ID)) { // project configuration not loaded yet T reference; try { reference = loadReference(huntingGrounds.getParentFile(), huntingGrounds.getName(), DEFAULT_RESOURCE_ID); resources.put(DEFAULT_RESOURCE_ID, reference); onAdd(reference, DEFAULT_RESOURCE_ID); } catch (IOException e) { log.error("Error creating project handler", e); } } else { // update existing project updateResource(resources.get(DEFAULT_RESOURCE_ID), DEFAULT_RESOURCE_ID); } } } } }
From source file:nl.edia.sakai.tool.skinmanager.impl.SkinFileSystemServiceImpl.java
@Override public List<SkinDirectory> fetchInstalledSkins() throws SkinException, IOException { File mySkinHome = getSkinHome(); File[] mySkins;//from w w w .j a va 2 s. c o m mySkins = mySkinHome.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return pathname.isDirectory(); } }); List<SkinDirectory> myFoundSkins = new ArrayList<SkinDirectory>(mySkins.length - 1); for (File myFile : mySkins) { if (looksLikeSkinDir(myFile)) { myFoundSkins.add(createSkinValueObject(myFile)); } else { LOG.debug("Skipping directory '" + myFile + "', it does not seem a valid skin directory"); } } Collections.sort(myFoundSkins, new Comparator<SkinDirectory>() { @Override public int compare(SkinDirectory o1, SkinDirectory o2) { return o1.getName().compareToIgnoreCase(o2.getName()); } }); return myFoundSkins; }
From source file:edu.unc.lib.dl.services.BatchIngestQueue.java
/** * @return/*from www . j av a2 s.co m*/ */ public File[] getReadyIngestDirectories() { File[] batchDirs = this.queuedDirectory.listFiles(new FileFilter() { @Override public boolean accept(File arg0) { if (arg0.isDirectory()) { String[] readyFiles = arg0.list(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return (READY_FILE.equals(name)); } }); if (readyFiles != null && readyFiles.length > 0) { return true; } } return false; } }); if (batchDirs != null) { Arrays.sort(batchDirs, new Comparator<File>() { @Override public int compare(File o1, File o2) { if (o1 == null || o2 == null) return 0; return (int) (o1.lastModified() - o2.lastModified()); } }); return batchDirs; } else { return new File[] {}; } }
From source file:eu.esdihumboldt.util.resource.scavenger.AbstractResourceScavenger.java
/** * @see ResourceScavenger#triggerScan()// w w w . ja va 2 s. com */ @Override public void triggerScan() { synchronized (resources) { if (huntingGrounds != null) { if (huntingGrounds.isDirectory()) { // scan for sub-directories Set<String> foundIds = new HashSet<String>(); File[] resourceDirs = huntingGrounds.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { // accept non-hidden directories return pathname.isDirectory() && !pathname.isHidden(); } }); for (File resourceDir : resourceDirs) { String resourceId = resourceDir.getName(); foundIds.add(resourceId); if (!resources.containsKey(resourceId)) { // resource reference not loaded yet T handler; try { handler = loadReference(resourceDir, null, resourceId); resources.put(resourceId, handler); } catch (IOException e) { log.error("Error creating resource reference", e); } } else { // update existing resource updateResource(resources.get(resourceId), resourceId); } } Set<String> removed = new HashSet<String>(resources.keySet()); removed.removeAll(foundIds); // deal with resources that have been removed for (String resourceId : removed) { T reference = resources.remove(resourceId); if (reference != null) { // remove active environment onRemove(reference, resourceId); } } } else { // one project mode if (!resources.containsKey(DEFAULT_RESOURCE_ID)) { // project configuration not loaded yet T handler; try { handler = loadReference(huntingGrounds.getParentFile(), huntingGrounds.getName(), DEFAULT_RESOURCE_ID); resources.put(DEFAULT_RESOURCE_ID, handler); } catch (IOException e) { log.error("Error creating project handler", e); } } else { // update existing project updateResource(resources.get(DEFAULT_RESOURCE_ID), DEFAULT_RESOURCE_ID); } } } } }
From source file:com.liferay.portal.deploy.hot.ExtHotDeployListener.java
protected void createWebInfJar(String portalWebDir, String pluginWebDir, String servletContextName) throws Exception { String zipName = portalWebDir + "WEB-INF/lib/ext-" + servletContextName + "-webinf.jar"; File dir = new File(pluginWebDir + "WEB-INF/ext-web/docroot/WEB-INF"); if (!dir.isDirectory()) { throw new IllegalArgumentException("Not a directory: " + dir); }// w w w . jav a 2 s.c o m File[] files = dir.listFiles(new FileFilter() { public boolean accept(File pathname) { return ExtRegistry.isMergedFile(pathname.getPath()); } }); zipWebInfJar(zipName, files); }
From source file:dk.statsbiblioteket.alto.AnagramHashing.java
/** * Get all ALTO XML files from the folder and sub folders. * @param altos located ALTO XML files will be added to this. * @param folder where to start looking for ALTO XML files. *///from www . j a v a2 s . com public void getALTOs(List<File> altos, File folder) { altos.addAll(Arrays.asList(folder.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return (name.endsWith(".alto.xml")); } }))); for (File sub : folder.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return pathname.isDirectory(); } })) { getALTOs(altos, sub); } }