List of usage examples for org.apache.commons.io.filefilter FileFilterUtils makeFileOnly
public static IOFileFilter makeFileOnly(IOFileFilter filter)
From source file:LicenseHeaderUpdate.java
public static void handleJavaStyleComments(String baseDir) throws Exception { IOFileFilter sourceFileFilter = FileFilterUtils.orFileFilter(FileFilterUtils.suffixFileFilter("java"), FileFilterUtils.suffixFileFilter("js")); sourceFileFilter = FileFilterUtils.orFileFilter(sourceFileFilter, FileFilterUtils.suffixFileFilter("css")); sourceFileFilter = FileFilterUtils.orFileFilter(sourceFileFilter, FileFilterUtils.suffixFileFilter("groovy")); sourceFileFilter = FileFilterUtils.makeSVNAware(sourceFileFilter); sourceFileFilter = FileFilterUtils.makeFileOnly(sourceFileFilter); LicensableFileDirectoryWalker dw = new LicensableFileDirectoryWalker(sourceFileFilter, "/*", " * ", " */"); Collection<String> results = dw.run(baseDir); System.out.println(results);/*from w w w . j a v a2 s.c o m*/ }
From source file:LicenseHeaderUpdate.java
public static void handleJSPStyleComments(String baseDir) throws Exception { IOFileFilter sourceFileFilter = FileFilterUtils.orFileFilter(FileFilterUtils.suffixFileFilter("jsp"), FileFilterUtils.suffixFileFilter("tag")); sourceFileFilter = FileFilterUtils.orFileFilter(sourceFileFilter, FileFilterUtils.suffixFileFilter("inc")); sourceFileFilter = FileFilterUtils.makeSVNAware(sourceFileFilter); sourceFileFilter = FileFilterUtils.makeFileOnly(sourceFileFilter); LicensableFileDirectoryWalker dw = new LicensableFileDirectoryWalker(sourceFileFilter, "<%--", " - ", "--%>"); Collection<String> results = dw.run(baseDir); System.out.println(results);//from w ww . j av a 2s .c om }
From source file:LicenseHeaderUpdate.java
public static void handlePropertyStyleComments(String baseDir) throws Exception { IOFileFilter sourceFileFilter = FileFilterUtils.orFileFilter(FileFilterUtils.suffixFileFilter("properties"), FileFilterUtils.suffixFileFilter("cmd")); sourceFileFilter = FileFilterUtils.orFileFilter(sourceFileFilter, FileFilterUtils.suffixFileFilter("sh")); sourceFileFilter = FileFilterUtils.makeSVNAware(sourceFileFilter); sourceFileFilter = FileFilterUtils.makeFileOnly(sourceFileFilter); LicensableFileDirectoryWalker dw = new LicensableFileDirectoryWalker(sourceFileFilter, "########################################", "# ", "########################################"); Collection<String> results = dw.run(baseDir); System.out.println(results);/*w ww .j av a 2 s . c om*/ }
From source file:LicenseHeaderUpdate.java
public static void handleSQLStyleComments(String baseDir) throws Exception { IOFileFilter sourceFileFilter = FileFilterUtils.suffixFileFilter("sql"); sourceFileFilter = FileFilterUtils.makeSVNAware(sourceFileFilter); sourceFileFilter = FileFilterUtils.makeFileOnly(sourceFileFilter); LicensableFileDirectoryWalker dw = new LicensableFileDirectoryWalker(sourceFileFilter, "--", "-- ", LINE_SEPARATOR);/*from w ww.j a v a 2 s .c o m*/ Collection<String> results = dw.run(baseDir); System.out.println(results); }
From source file:LicenseHeaderUpdate.java
public static void handleXMLStyleComments(String baseDir) throws Exception { IOFileFilter sourceFileFilter = FileFilterUtils.orFileFilter(FileFilterUtils.suffixFileFilter("xml"), FileFilterUtils.suffixFileFilter("jrxml")); sourceFileFilter = FileFilterUtils.orFileFilter(sourceFileFilter, FileFilterUtils.suffixFileFilter("html")); sourceFileFilter = FileFilterUtils.orFileFilter(sourceFileFilter, FileFilterUtils.suffixFileFilter("htm")); sourceFileFilter = FileFilterUtils.orFileFilter(sourceFileFilter, FileFilterUtils.suffixFileFilter("xsd")); sourceFileFilter = FileFilterUtils.orFileFilter(sourceFileFilter, FileFilterUtils.suffixFileFilter("tld")); sourceFileFilter = FileFilterUtils.makeSVNAware(sourceFileFilter); sourceFileFilter = FileFilterUtils.makeFileOnly(sourceFileFilter); LicensableFileDirectoryWalker dw = new LicensableFileDirectoryWalker(sourceFileFilter, "<!--", " - ", " -->"); Collection<String> results = dw.run(baseDir); System.out.println(results);//from ww w. j av a 2s . co m }
From source file:ome.services.blitz.repo.PublicRepositoryI.java
/** * Get a filtered file listing based on the config options. */*w ww.j a v a2 s.com*/ * @param file * A File object representing the directory to be listed. * @param config * A RepositoryListConfig object holding the filter options. * @return A list of File objects * */ private List<File> filteredFiles(File file, RepositoryListConfig config) throws ServerError { List<File> files; IOFileFilter filter; // If hidden is true list all files otherwise only those files not starting with "." if (config.hidden) { filter = FileFilterUtils.trueFileFilter(); } else { filter = FileFilterUtils.notFileFilter(FileFilterUtils.prefixFileFilter(".")); } // Now decorate the filter to restrict to files or directories, // the else case is for a bizarre config of wanting nothing returned! if (!(config.dirs && config.files)) { if (config.dirs) { filter = FileFilterUtils.makeDirectoryOnly(filter); } else if (config.files) { filter = FileFilterUtils.makeFileOnly(filter); } else { filter = FileFilterUtils.falseFileFilter(); } } files = Arrays.asList(file.listFiles((FileFilter) filter)); return files; }
From source file:org.archive.bdb.BdbModule.java
@SuppressWarnings("unchecked") protected void doRecover() throws IOException { File cpDir = new File(dir.getFile(), recoveryCheckpoint.getName()); File logfilesList = new File(cpDir, "jdbfiles.manifest"); List<String> filesAndLengths = FileUtils.readLines(logfilesList); HashMap<String, Long> retainLogfiles = new HashMap<String, Long>(); for (String line : filesAndLengths) { String[] fileAndLength = line.split(","); long expectedLength = Long.valueOf(fileAndLength[1]); retainLogfiles.put(fileAndLength[0], expectedLength); // check for files in checkpoint directory; relink to environment as necessary File cpFile = new File(cpDir, line); File destFile = new File(dir.getFile(), fileAndLength[0]); if (cpFile.exists()) { if (cpFile.length() != expectedLength) { LOGGER.warning(cpFile.getName() + " expected " + expectedLength + " actual " + cpFile.length()); // TODO: is truncation necessary? }//from www .java 2 s . c om if (destFile.exists()) { if (!destFile.delete()) { LOGGER.log(Level.SEVERE, "unable to delete obstructing file " + destFile); } } boolean status = FilesystemLinkMaker.makeHardLink(cpFile.getAbsolutePath(), destFile.getAbsolutePath()); if (!status) { LOGGER.log(Level.SEVERE, "unable to create required restore link " + destFile); } } } IOFileFilter filter = FileFilterUtils.orFileFilter(FileFilterUtils.suffixFileFilter(".jdb"), FileFilterUtils.suffixFileFilter(".del")); filter = FileFilterUtils.makeFileOnly(filter); // reverify environment directory is as it was at checkpoint time, // deleting any extra files for (File f : dir.getFile().listFiles((FileFilter) filter)) { if (retainLogfiles.containsKey(f.getName())) { // named file still exists under original name long expectedLength = retainLogfiles.get(f.getName()); if (f.length() != expectedLength) { LOGGER.warning(f.getName() + " expected " + expectedLength + " actual " + f.length()); // TODO: truncate? this unexpected length mismatch // probably only happens if there was already a recovery // where the affected file was the last of the set, in // which case BDB appends a small amount of (harmless?) data // to the previously-undersized file } retainLogfiles.remove(f.getName()); continue; } // file as now-named not in restore set; check if un-".DEL" renaming needed String undelName = f.getName().replace(".del", ".jdb"); if (retainLogfiles.containsKey(undelName)) { // file if renamed matches desired file name long expectedLength = retainLogfiles.get(undelName); if (f.length() != expectedLength) { LOGGER.warning(f.getName() + " expected " + expectedLength + " actual " + f.length()); // TODO: truncate to expected size? } if (!f.renameTo(new File(f.getParentFile(), undelName))) { throw new IOException("Unable to rename " + f + " to " + undelName); } retainLogfiles.remove(undelName); } // file not needed; delete/move-aside if (!f.delete()) { LOGGER.warning("unable to delete " + f); org.archive.util.FileUtils.moveAsideIfExists(f); } // TODO: log/warn of ruined later checkpoints? } if (retainLogfiles.size() > 0) { // some needed files weren't present LOGGER.severe("Checkpoint corrupt, needed log files missing: " + retainLogfiles); } }
From source file:org.geotools.gce.imagemosaic.catalogbuilder.CatalogBuilder.java
/** * @return//from w w w . j a v a 2 s. co m */ private IOFileFilter createGranuleFilterRules() { final IOFileFilter specialWildCardFileFilter = new WildcardFileFilter(runConfiguration.getWildcard(), IOCase.INSENSITIVE); IOFileFilter dirFilter = FileFilterUtils.andFileFilter(FileFilterUtils.directoryFileFilter(), HiddenFileFilter.VISIBLE); IOFileFilter fileFilter = Utils.excludeFilters( FileFilterUtils.makeSVNAware(FileFilterUtils.makeFileOnly( FileFilterUtils.andFileFilter(specialWildCardFileFilter, HiddenFileFilter.VISIBLE))), FileFilterUtils.suffixFileFilter("shp"), FileFilterUtils.suffixFileFilter("dbf"), FileFilterUtils.suffixFileFilter("shx"), FileFilterUtils.suffixFileFilter("qix"), FileFilterUtils.suffixFileFilter("lyr"), FileFilterUtils.suffixFileFilter("prj"), FileFilterUtils.nameFileFilter("error.txt"), FileFilterUtils.nameFileFilter("error.txt.lck"), FileFilterUtils.suffixFileFilter("properties"), FileFilterUtils.suffixFileFilter("svn-base")); // exclude common extensions Set<String> extensions = WorldImageFormat.getWorldExtension("png"); for (String ext : extensions) { fileFilter = FileFilterUtils.andFileFilter(fileFilter, FileFilterUtils.notFileFilter(FileFilterUtils.suffixFileFilter(ext.substring(1)))); } extensions = WorldImageFormat.getWorldExtension("gif"); for (String ext : extensions) { fileFilter = FileFilterUtils.andFileFilter(fileFilter, FileFilterUtils.notFileFilter(FileFilterUtils.suffixFileFilter(ext.substring(1)))); } extensions = WorldImageFormat.getWorldExtension("jpg"); for (String ext : extensions) { fileFilter = FileFilterUtils.andFileFilter(fileFilter, FileFilterUtils.notFileFilter(FileFilterUtils.suffixFileFilter(ext.substring(1)))); } extensions = WorldImageFormat.getWorldExtension("tiff"); for (String ext : extensions) { fileFilter = FileFilterUtils.andFileFilter(fileFilter, FileFilterUtils.notFileFilter(FileFilterUtils.suffixFileFilter(ext.substring(1)))); } extensions = WorldImageFormat.getWorldExtension("bmp"); for (String ext : extensions) { fileFilter = FileFilterUtils.andFileFilter(fileFilter, FileFilterUtils.notFileFilter(FileFilterUtils.suffixFileFilter(ext.substring(1)))); } //sdw fileFilter = FileFilterUtils.andFileFilter(fileFilter, FileFilterUtils.notFileFilter(FileFilterUtils.suffixFileFilter("sdw"))); //aux fileFilter = FileFilterUtils.andFileFilter(fileFilter, FileFilterUtils.notFileFilter(FileFilterUtils.suffixFileFilter("aux"))); //wld fileFilter = FileFilterUtils.andFileFilter(fileFilter, FileFilterUtils.notFileFilter(FileFilterUtils.suffixFileFilter("wld"))); //svn fileFilter = FileFilterUtils.andFileFilter(fileFilter, FileFilterUtils.notFileFilter(FileFilterUtils.suffixFileFilter("svn"))); final IOFileFilter finalFilter = FileFilterUtils.orFileFilter(dirFilter, fileFilter); return finalFilter; }
From source file:org.geotools.gce.imagemosaic.ImageMosaicDirectoryWalker.java
/** * @return/*ww w .j a va 2 s .co m*/ */ private IOFileFilter createDefaultGranuleExclusionFilter() { final IOFileFilter specialWildCardFileFilter = new WildcardFileFilter( configHandler.getRunConfiguration().getParameter(Prop.WILDCARD), IOCase.INSENSITIVE); IOFileFilter dirFilter = FileFilterUtils.and(FileFilterUtils.directoryFileFilter(), HiddenFileFilter.VISIBLE); IOFileFilter filesFilter = Utils.excludeFilters( FileFilterUtils.makeSVNAware(FileFilterUtils .makeFileOnly(FileFilterUtils.and(specialWildCardFileFilter, HiddenFileFilter.VISIBLE))), FileFilterUtils.suffixFileFilter("shp"), FileFilterUtils.suffixFileFilter("dbf"), FileFilterUtils.suffixFileFilter("sbn"), FileFilterUtils.suffixFileFilter("sbx"), FileFilterUtils.suffixFileFilter("shx"), FileFilterUtils.suffixFileFilter("qix"), FileFilterUtils.suffixFileFilter("lyr"), FileFilterUtils.suffixFileFilter("prj"), FileFilterUtils.nameFileFilter("error.txt"), FileFilterUtils.nameFileFilter("error.txt.lck"), FileFilterUtils.suffixFileFilter("properties"), FileFilterUtils.suffixFileFilter("svn-base"), FileFilterUtils.suffixFileFilter("ncx"), FileFilterUtils.suffixFileFilter("gbx9")); filesFilter = FileFilterUtils.or(filesFilter, FileFilterUtils.nameFileFilter("indexer.properties")); // exclude common extensions Set<String> extensions = WorldImageFormat.getWorldExtension("png"); for (String ext : extensions) { filesFilter = FileFilterUtils.and(filesFilter, FileFilterUtils.notFileFilter(FileFilterUtils.suffixFileFilter(ext.substring(1)))); } extensions = WorldImageFormat.getWorldExtension("gif"); for (String ext : extensions) { filesFilter = FileFilterUtils.and(filesFilter, FileFilterUtils.notFileFilter(FileFilterUtils.suffixFileFilter(ext.substring(1)))); } extensions = WorldImageFormat.getWorldExtension("jpg"); for (String ext : extensions) { filesFilter = FileFilterUtils.and(filesFilter, FileFilterUtils.notFileFilter(FileFilterUtils.suffixFileFilter(ext.substring(1)))); } extensions = WorldImageFormat.getWorldExtension("tiff"); for (String ext : extensions) { filesFilter = FileFilterUtils.and(filesFilter, FileFilterUtils.notFileFilter(FileFilterUtils.suffixFileFilter(ext.substring(1)))); } extensions = WorldImageFormat.getWorldExtension("bmp"); for (String ext : extensions) { filesFilter = FileFilterUtils.and(filesFilter, FileFilterUtils.notFileFilter(FileFilterUtils.suffixFileFilter(ext.substring(1)))); } // sdw filesFilter = FileFilterUtils.and(filesFilter, FileFilterUtils.notFileFilter(FileFilterUtils.suffixFileFilter("sdw")), FileFilterUtils.notFileFilter(FileFilterUtils.suffixFileFilter("aux")), FileFilterUtils.notFileFilter(FileFilterUtils.suffixFileFilter("wld")), FileFilterUtils.notFileFilter(FileFilterUtils.suffixFileFilter("svn"))); if (this.fileFilter != null) { filesFilter = FileFilterUtils.and(this.fileFilter, filesFilter); } final IOFileFilter finalFilter = FileFilterUtils.or(dirFilter, filesFilter); return finalFilter; }
From source file:org.geotools.gce.imagemosaic.ImageMosaicFormat.java
@SuppressWarnings("unchecked") private static boolean checkForUrl(Object source, Hints hints) { try {/*from w ww . j a v a 2s . co m*/ URL sourceURL = Utils.checkSource(source, hints); if (sourceURL == null) { return false; } if (source instanceof File) { File file = (File) source; if (!file.exists()) { return false; // file does not exist } } // // Load tiles informations, especially the bounds, which will be // reused // DataStore tileIndexStore = null; CoordinateReferenceSystem crs = null; boolean shapefile = true; try { final File sourceF = DataUtilities.urlToFile(sourceURL); if (FilenameUtils.getName(sourceF.getAbsolutePath()).equalsIgnoreCase("datastore.properties")) { shapefile = false; // load spi anche check it // read the properties file final Properties properties = new Properties(); final FileInputStream stream = new FileInputStream(sourceF); try { properties.load(stream); } finally { IOUtils.closeQuietly(stream); } // SPI final String SPIClass = properties.getProperty("SPI"); // create a datastore as instructed final DataStoreFactorySpi spi = (DataStoreFactorySpi) Class.forName(SPIClass).newInstance(); // get the params final Map<String, Serializable> params = new HashMap<String, Serializable>(); final Param[] paramsInfo = spi.getParametersInfo(); for (Param p : paramsInfo) { // search for this param and set the value if found if (properties.containsKey(p.key)) params.put(p.key, (Serializable) Converters.convert(properties.getProperty(p.key), p.type)); else if (p.required && p.sample == null) { if (LOGGER.isLoggable(Level.FINE)) LOGGER.fine("Required parameter missing: " + p.toString()); return false; } } // H2 workadound if (spi instanceof H2DataStoreFactory || spi instanceof H2JNDIDataStoreFactory) { if (params.containsKey(H2DataStoreFactory.DATABASE.key)) { String dbname = (String) params.get(H2DataStoreFactory.DATABASE.key); // H2 database URLs must not be percent-encoded: see GEOT-4262. params.put(H2DataStoreFactory.DATABASE.key, "file:" + (new File(sourceF.getParentFile(), dbname)).getPath()); } } tileIndexStore = spi.createDataStore(params); if (tileIndexStore == null) return false; } else { URL testPropertiesUrl = DataUtilities.changeUrlExt(sourceURL, "properties"); File testFile = DataUtilities.urlToFile(testPropertiesUrl); if (!testFile.exists()) { return false; } ShapefileDataStore store = new ShapefileDataStore(sourceURL); store.setDbftimeZone(Utils.UTC_TIME_ZONE); tileIndexStore = store; } // // Now look for the properties file and try to parse relevant fields // URL propsUrl = null; if (shapefile) propsUrl = DataUtilities.changeUrlExt(sourceURL, "properties"); else { // // do we have a datastore properties file? It will preempt on the shapefile // final File parent = DataUtilities.urlToFile(sourceURL).getParentFile(); // this can be used to look for properties files that do NOT define a datastore final File[] properties = parent.listFiles((FilenameFilter) FileFilterUtils.and( FileFilterUtils.notFileFilter(FileFilterUtils.nameFileFilter("indexer.properties")), FileFilterUtils.and( FileFilterUtils .notFileFilter(FileFilterUtils.nameFileFilter("datastore.properties")), FileFilterUtils .makeFileOnly(FileFilterUtils.suffixFileFilter(".properties"))))); // do we have a valid datastore + mosaic properties pair? for (File propFile : properties) if (Utils.checkFileReadable(propFile) && Utils.loadMosaicProperties(DataUtilities.fileToURL(propFile), "") != null) { propsUrl = DataUtilities.fileToURL(propFile); break; } } //get the properties file final MosaicConfigurationBean configuration = Utils.loadMosaicProperties(propsUrl, Utils.DEFAULT_LOCATION_ATTRIBUTE); if (configuration == null) return false; // we need the type name with a DB to pick up the right table // for shapefiles this can be null so taht we select the first and ony one String typeName = configuration.getTypeName(); if (typeName == null) { final String[] typeNames = tileIndexStore.getTypeNames(); if (typeNames.length <= 0) return false; typeName = typeNames[0]; } if (typeName == null) return false; // now try to connect to the index SimpleFeatureSource featureSource = null; try { featureSource = tileIndexStore.getFeatureSource(typeName); } catch (Exception e) { featureSource = tileIndexStore.getFeatureSource(typeName.toUpperCase()); } if (featureSource == null) { return false; } final SimpleFeatureType schema = featureSource.getSchema(); if (schema == null) return false; crs = featureSource.getSchema().getGeometryDescriptor().getCoordinateReferenceSystem(); if (crs == null) return false; // looking for the location attribute final String locationAttributeName = configuration.getLocationAttribute(); if (schema.getDescriptor(locationAttributeName) == null && schema.getDescriptor(locationAttributeName.toUpperCase()) == null) return false; return true; } finally { try { if (tileIndexStore != null) tileIndexStore.dispose(); } catch (Throwable e) { if (LOGGER.isLoggable(Level.FINE)) LOGGER.log(Level.FINE, e.getLocalizedMessage(), e); } } } catch (Throwable e) { if (LOGGER.isLoggable(Level.FINE)) LOGGER.log(Level.FINE, e.getLocalizedMessage(), e); return false; } }