List of usage examples for org.apache.commons.io IOCase INSENSITIVE
IOCase INSENSITIVE
To view the source code for org.apache.commons.io IOCase INSENSITIVE.
Click Source Link
From source file:io.manasobi.utils.FileUtils.java
/** * ? ? . ? ? ? ? ? .<br>/*from w ww . j a v a 2 s. com*/ * preserveFileDate true ?? ? ?? false ?? ? * . * * @param srcDir ? * @param destDir ? * @param extList ? ? * @param preserveFileDate ? * @return enum ? Result.SUCCESS Result.FAIL? */ public static Result copyDirAfterCheckFileExt(File srcDir, File destDir, boolean preserveFileDate, String... extList) { Result result = Result.EMPTY; if (notExistsDir(srcDir)) { return buildFailResult(result, srcDir + " ."); } if (isNotDir(srcDir)) { return buildFailResult(result, srcDir + " ."); } if (notExistsDir(destDir)) { result = createDir(destDir.getAbsolutePath()); if (result == Result.FAIL) { return buildFailResult(result, destDir + " ? ? ? ?."); } } if (isNotDir(destDir)) { return buildFailResult(result, destDir + " ."); } IOFileFilter suffixFilters = new SuffixFileFilter(extList, IOCase.INSENSITIVE); FileFilter filter = FileFilterUtils.or(DirectoryFileFilter.DIRECTORY, suffixFilters); try { org.apache.commons.io.FileUtils.copyDirectory(srcDir, destDir, filter, preserveFileDate); } catch (Exception e) { return buildFailResult(result, e.getMessage()); } return Result.SUCCESS; }
From source file:net.sf.jvifm.util.AutoCompleteUtil.java
@SuppressWarnings("all") public static String[] getBookmarkFileOptions(String name) { ArrayList result = new ArrayList(); BookmarkManager bookmarkManager = BookmarkManager.getInstance(); boolean lowerCase = false; if (name.toLowerCase().equals(name)) { lowerCase = true;/* w ww. ja va 2s. co m*/ } List bookmarkList = bookmarkManager.getAll(); if (bookmarkList != null) { for (Iterator it = bookmarkList.iterator(); it.hasNext();) { Bookmark bookmark = (Bookmark) it.next(); String bookmarkName = bookmark.getName(); if (lowerCase) { bookmarkName = bookmarkName.toLowerCase(); } if (FilenameUtils.wildcardMatch(bookmarkName, name, IOCase.INSENSITIVE) || bookmarkName.startsWith(name)) { result.add(bookmark.getPath()); } } } if (result.size() <= 0) return null; String[] resultArray = new String[result.size()]; for (int i = 0; i < resultArray.length; i++) { resultArray[i] = (String) result.get(i); } return resultArray; }
From source file:fi.uta.infim.usaproxyreportgenerator.App.java
private static void setupDataProvider() { // A data provider class can be specified on the CLI. if (cli.hasOption("dataProvider")) { // Look for JAR files in the plugin dir File[] jars = PLUGINS_DIR.listFiles((FileFilter) new WildcardFileFilter("*.jar", IOCase.INSENSITIVE)); URL[] jarUrls = new URL[jars.length]; for (int i = 0; i < jars.length; ++i) { try { jarUrls[i] = jars[i].toURI().toURL(); } catch (MalformedURLException e) { // Skip URL if not valid continue; }//from ww w .j a va2s .c o m } ClassLoader loader = URLClassLoader.newInstance(jarUrls, ClassLoader.getSystemClassLoader()); String className = cli.getOptionValue("dataProvider"); // Try to load the named class using a class loader. Fall back to // default if this fails. try { @SuppressWarnings("unchecked") Class<? extends DataProvider> cliOptionClass = (Class<? extends DataProvider>) Class .forName(className, true, loader); if (!DataProvider.class.isAssignableFrom(cliOptionClass)) { throw new ClassCastException(cliOptionClass.getCanonicalName()); } dataProviderClass = cliOptionClass; } catch (ClassNotFoundException e) { System.out.flush(); System.err.println("Specified data provider class not found: " + e.getMessage()); System.err.println("Falling back to default provider."); } catch (ClassCastException e) { System.out.flush(); System.err.println("Specified data provider class is invalid: " + e.getMessage()); System.err.println("Falling back to default provider."); } System.err.flush(); } }
From source file:com.thoughtworks.studios.shine.cruise.stage.details.JobResourceImporter.java
File[] getArtifactFilesOfType(String artifactsPathFromRoot, String jobArtifactPath, final String fileExtension) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("getArtifactFilesOfType(" + artifactsPathFromRoot + ", " + jobArtifactPath + ", " + fileExtension + ")"); }//from w w w . ja va 2s. co m File jobArtifactFile = new File(artifactBaseDir, artifactsPathFromRoot + File.separator + jobArtifactPath); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Artifact directory calculated to be " + jobArtifactFile.getAbsolutePath()); } if (!jobArtifactFile.exists() || !jobArtifactFile.isDirectory()) { return new File[0]; } Collection collection = FileUtils.listFiles(jobArtifactFile, new SuffixFileFilter(fileExtension, IOCase.INSENSITIVE), TrueFileFilter.INSTANCE); if (LOGGER.isDebugEnabled()) { LOGGER.debug("" + collection.size() + " artifact files found."); } return (File[]) collection.toArray(new File[0]); }
From source file:com.mirth.connect.server.launcher.MirthLauncher.java
private static void addExtensionsToClasspath(List<URL> urls, String currentVersion) throws Exception { FileFilter extensionFileFilter = new NameFileFilter( new String[] { "plugin.xml", "source.xml", "destination.xml" }, IOCase.INSENSITIVE); FileFilter directoryFilter = FileFilterUtils.directoryFileFilter(); File extensionPath = new File(EXTENSIONS_DIR); Properties extensionProperties = new Properties(); File extensionPropertiesFile = new File(appDataDir, EXTENSION_PROPERTIES); /*//from ww w .ja v a 2 s .co m * If the file does not exist yet, an empty Properties object will be used, returning the * default of true for all extensions. */ if (extensionPropertiesFile.exists()) { extensionProperties.load(new FileInputStream(extensionPropertiesFile)); } if (extensionPath.exists() && extensionPath.isDirectory()) { File[] directories = extensionPath.listFiles(directoryFilter); for (File directory : directories) { File[] extensionFiles = directory.listFiles(extensionFileFilter); for (File extensionFile : extensionFiles) { try { Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder() .parse(extensionFile); Element rootElement = document.getDocumentElement(); boolean enabled = extensionProperties .getProperty(rootElement.getElementsByTagName("name").item(0).getTextContent(), "true") .equalsIgnoreCase("true"); boolean compatible = isExtensionCompatible( rootElement.getElementsByTagName("mirthVersion").item(0).getTextContent(), currentVersion); // Only add libraries from extensions that are not disabled and are compatible with the current version if (enabled && compatible) { NodeList libraries = rootElement.getElementsByTagName("library"); for (int i = 0; i < libraries.getLength(); i++) { Element libraryElement = (Element) libraries.item(i); String type = libraryElement.getAttribute("type"); if (type.equalsIgnoreCase("server") || type.equalsIgnoreCase("shared")) { File pathFile = new File(directory, libraryElement.getAttribute("path")); if (pathFile.exists()) { logger.trace("adding library to classpath: " + pathFile.getAbsolutePath()); urls.add(pathFile.toURI().toURL()); } else { logger.error("could not locate library: " + pathFile.getAbsolutePath()); } } } } } catch (Exception e) { logger.error("failed to parse extension metadata: " + extensionFile.getAbsolutePath(), e); } } } } else { logger.warn("no extensions found"); } }
From source file:de.ee.hezel.PDFCorpusAnalyser.java
/** * Run thru the given folders and find pdf document which have the same name. * For every pair, a PDFInfoHolder objects gets created. * //from ww w .j a va2 s . co m * @param pdfs1 for the 1st directory * @param pdfs2 for the 2nd directory * @param prefix * @return list of all pdf pairs */ public static Set<PDFInfoHolder> getSimplePDFInfoHolders(File pdfs1, File pdfs2, String prefix) { Set<PDFInfoHolder> pdfInfoHolders = new HashSet<PDFInfoHolder>(); // are those valid pathes if (pdfs1 != null && pdfs2 != null && pdfs1.isDirectory() && pdfs2.isDirectory()) { // create a filter to only get pdf files List<FilenameFilter> filters = new ArrayList<FilenameFilter>(); if (null != prefix && prefix.length() > 0) { PrefixFileFilter filter = new PrefixFileFilter(prefix, IOCase.SYSTEM); filters.add(filter); } filters.add(new SuffixFileFilter(".pdf", IOCase.INSENSITIVE)); FilenameFilter filter = new AndFileFilter(filters); //get all pdf file sin this folder String[] pdfDocuments1 = pdfs1.list(filter); for (int i = 0; i < pdfDocuments1.length; i++) { // get the pdf file name String pdfFilename1 = pdfDocuments1[i]; // get the path for both pdf files File pdfFile1 = new File(pdfs1, pdfFilename1); File pdfFile2 = new File(pdfs2, pdfFilename1); // bind them together in a PDFInfoHolder objects PDFInfoHolder newPDFInfoHolder = new PDFInfoHolder(pdfFile1, pdfFile2); // remember them all pdfInfoHolders.add(newPDFInfoHolder); } // TODO what should happen if there are less reference documents than new generated ones } else { log.error("The path is not valid."); } return pdfInfoHolders; }
From source file:kihira.tails.common.FoxLibManager.java
private void deleteOldVersions() { File modsFolder = new File(Minecraft.getMinecraft().mcDataDir + File.separator + "mods"); File[] files = modsFolder/*from w w w . j av a 2 s .c o m*/ .listFiles((FileFilter) new WildcardFileFilter("*FoxLib*.jar", IOCase.INSENSITIVE)); if (files != null) { for (File file : files) { if (file.exists()) { logger.info("Deleting file " + file.toString() + " on exit"); file.deleteOnExit(); } } } }
From source file:com.quinsoft.zeidon.utils.JoeUtils.java
/** * Returns java.io.File for a file matching path using CASE-INSENSITIVE file * matching. This makes it easier for us to run on Windows. * * @param path//from w ww .ja v a 2 s.c o m * @return */ public static File getFile(String path) { try { File file = new File(path); if (file.exists()) return file; // Try searching for the file without regard to case. String parentPath = file.getParent(); if (StringUtils.isBlank(parentPath)) return file; // No parent path so just return. File dir = new File(parentPath); NameFileFilter filter = new NameFileFilter(file.getName(), IOCase.INSENSITIVE); String[] files = dir.list(filter); if (files == null) return file; // We probably didn't find a directory so just return the unknown file. if (files.length == 1) return new File(parentPath + File.separator + files[0]); if (files.length > 1) throw new ZeidonException("Found multiple matching entries for %s", path); // We didn't find an exact match so just return. return file; } catch (Exception e) { throw ZeidonException.wrapException(e).prependFilename(path); } }
From source file:it.geosolutions.geobatch.imagemosaic.ImageMosaicAction.java
/** * Public or update an ImageMosaic layer on the specified GeoServer *//* w w w . j a v a 2s. c o m*/ public Queue<EventObject> execute(Queue<EventObject> events) throws ActionException { if (LOGGER.isInfoEnabled()) LOGGER.info("Start processing..."); listenerForwarder.started(); try { // looking for file if (events == null) throw new IllegalArgumentException("Unable to execute action with incoming null parameter"); if (events.size() == 0) throw new IllegalArgumentException("Wrong number of elements for this action: " + events.size()); /* * If here: we can execute the action */ Queue<EventObject> ret = new LinkedList<EventObject>(); /** * For each event into the queue */ while (events.size() > 0) { final Object evObj = events.remove(); /** * If the input file exists and it is a file: Check if it is: - * A Directory - An XML -> Serialized ImageMosaicCommand * * Building accordingly the ImageMosaicCommand command. */ final ImageMosaicCommand cmd; if (evObj == null) { ActionExceptionHandler.handleError(getConfiguration(), this, "Input null object."); continue; } if (evObj instanceof FileSystemEvent) { /* * Checking input files. */ final File input = ((FileSystemEvent) evObj).getSource(); if (!input.exists()) { // no file is found for this event try with the next one ActionExceptionHandler.handleError(getConfiguration(), this, "The input file does not exists at url: " + input.getAbsolutePath()); continue; } /** * the file event points to an XML file... * * @see ImageMosaicCommand */ if (input.isFile() && FilenameUtils.getExtension(input.getName()).equalsIgnoreCase("xml")) { if (LOGGER.isInfoEnabled()) { LOGGER.info("Working on an XML command file: " + input.getAbsolutePath()); } // try to deserialize cmd = ImageMosaicCommand.deserialize(input.getAbsoluteFile()); if (cmd == null) { ActionExceptionHandler.handleError(getConfiguration(), this, "Unable to deserialize the passed file: " + input.getAbsolutePath()); continue; } } else if (input.isDirectory()) { if (LOGGER.isInfoEnabled()) { LOGGER.info("Input file event points to a directory: " + input.getAbsolutePath()); } String format = ((ImageMosaicConfiguration) super.getConfiguration()).getGranuleFormat(); if (format == null || format.isEmpty()) { LOGGER.warn( "No granule format specified in flow configuration... try force it to .tif"); format = "tif"; } StringBuilder builder = new StringBuilder(); builder.append("*."); builder.append(format); final Collector coll = new Collector( new WildcardFileFilter(builder.toString(), IOCase.INSENSITIVE)); // try to deserialize cmd = new ImageMosaicCommand(input, coll.collect(input), null); } else { // the file event does not point to a directory nor to an xml file ActionExceptionHandler.handleError(getConfiguration(), this, "The file event does not point to a directory nor to an xml file: " + input.getAbsolutePath()); continue; } } else if (evObj instanceof EventObject) { Object innerObject = ((EventObject) evObj).getSource(); if (innerObject instanceof ImageMosaicCommand) { cmd = (ImageMosaicCommand) innerObject; } else { // the file event does not point to a directory nor to an xml file ActionExceptionHandler.handleError(getConfiguration(), this, "The file event does not point to a valid object: " + evObj); continue; } } else { // the file event does not point to a directory nor to an xml file ActionExceptionHandler.handleError(getConfiguration(), this, "The file event does not point to a valid object: " + evObj); continue; } /** * the file pointing to the directory which the layer will refer * to. */ final File baseDir = cmd.getBaseDir(); /** * a descriptor for the mosaic to handle */ final ImageMosaicGranulesDescriptor mosaicDescriptor = ImageMosaicGranulesDescriptor .buildDescriptor(baseDir, getConfiguration()); if (mosaicDescriptor == null) { ActionExceptionHandler.handleError(getConfiguration(), this, "Unable to build the imageMosaic descriptor" + cmd.getBaseDir()); continue; } // Perform tests on the base dir file if (!baseDir.exists() || !baseDir.isDirectory()) { // no base dir exists try to build a new one using // addList() if (cmd.getAddFiles() != null) { if (cmd.getAddFiles().size() > 0) { // try build the baseDir if (!baseDir.mkdirs()) { ActionExceptionHandler.handleError(getConfiguration(), this, "Unable to create the base directory named \'" + baseDir.getAbsolutePath() + "\'."); continue; } } else { final StringBuilder msg = new StringBuilder(); msg.append("Unexpected not existent baseDir for this layer '") .append(baseDir.getAbsolutePath()) .append("'.\n If you want to build a new layer try using an ") .append("existent or writeable baseDir and append a list of file to use to the addFile list."); ActionExceptionHandler.handleError(getConfiguration(), this, msg.toString()); continue; } } else { final StringBuilder msg = new StringBuilder(); msg.append("Unexpected not existent baseDir for this layer '") .append(baseDir.getAbsolutePath()) .append("'.\n If you want to build a new layer try using an ") .append("existent or writeable baseDir and append a list of file to use to the addFile list."); ActionExceptionHandler.handleError(getConfiguration(), this, msg.toString()); continue; } } // override local cmd null params with the getConfiguration() cmd.copyConfigurationIntoCommand(getConfiguration()); // prepare configuration for layername and storename final String layerName; if (cmd.getLayerName() == null) { layerName = baseDir.getName(); cmd.setLayerName(layerName); } else { layerName = cmd.getLayerName(); } final String storeName; if (cmd.getStoreName() == null) { storeName = layerName; cmd.setStoreName(storeName); } else { storeName = cmd.getStoreName(); } /** * HERE WE HAVE A 'cmd' COMMAND FILE WHICH MAY HAVE GETADDFILE * OR GETDELFILE !=NULL USING THOSE LIST WE MAY:<br> * DEL ->DELETE FROM THE DATASTORE AN IMAGE USING THE ABSOLUTE * PATH.<br> * ADD ->INSERT INTO THE DATASTORE AN IMAGE USING THE ABSOLUTE * PATH.<br> */ // REST library read GeoServerRESTReader gsReader = new GeoServerRESTReader(cmd.getGeoserverURL(), cmd.getGeoserverUID(), cmd.getGeoserverPWD()); // REST library write final GeoServerRESTPublisher gsPublisher = new GeoServerRESTPublisher(cmd.getGeoserverURL(), cmd.getGeoserverUID(), cmd.getGeoserverPWD()); final String workspace = cmd.getDefaultNamespace() != null ? cmd.getDefaultNamespace() : ""; /* * Check if ImageMosaic layer already exists... */ final boolean layerExists; if (cmd.getIgnoreGeoServer()) { if (LOGGER.isInfoEnabled()) { LOGGER.info( "GeoServer will be ignored by configuration. Assuming that an updated is required. "); } layerExists = true; } else { final RESTLayer layer = gsReader.getLayer(layerName); layerExists = layer != null; } if (layerExists) { if (!updateMosaicLayer(cmd, baseDir, layerName, mosaicDescriptor, gsPublisher)) { ActionExceptionHandler.handleError(getConfiguration(), this, "Mosaic not Updated..."); continue; } } else { if (!createMosaicLayer(cmd, baseDir, workspace, mosaicDescriptor, layerName, gsPublisher, storeName)) { ActionExceptionHandler.handleError(getConfiguration(), this, "Mosaic not Created..."); continue; } } /** * The returned file: - one for each event - .layer file - will * be added to the output queue */ final File layerDescriptor; // generate a RETURN file and append it to the return queue // TODO get info about store and workspace name... layerDescriptor = ImageMosaicOutput.writeReturn(baseDir, baseDir, cmd); if (layerDescriptor != null) { LOGGER.info("Created layer descriptor file " + layerDescriptor); ret.add(new FileSystemEvent(layerDescriptor, FileSystemEventType.FILE_ADDED)); } } // while listenerForwarder.completed(); // ... setting up the appropriate event for the next action return ret; } catch (Exception t) { if (LOGGER.isErrorEnabled()) LOGGER.error(t.getLocalizedMessage(), t); listenerForwarder.failed(t); throw new ActionException(this, t.getMessage(), t); } }
From source file:net.sf.jvifm.util.AutoCompleteUtil.java
@SuppressWarnings("all") public static Shortcut[] getShortcutsCompleteList2(String cmd) { ArrayList result = new ArrayList(); ShortcutsManager scm = ShortcutsManager.getInstance(); boolean lowerCase = false; if (cmd.toLowerCase().equals(cmd)) { lowerCase = true;// ww w . j a v a 2 s .com } ArrayList customCmdNameList = scm.getAll(); if (customCmdNameList != null) { for (Iterator it = customCmdNameList.iterator(); it.hasNext();) { Shortcut shortcut = (Shortcut) it.next(); String cmdName = shortcut.getName(); if (lowerCase) { cmdName = cmdName.toLowerCase(); } if (FilenameUtils.wildcardMatch(cmdName, cmd, IOCase.INSENSITIVE) || cmdName.startsWith(cmd)) { result.add(shortcut); } } } if (result.size() <= 0) return null; Shortcut[] resultArray = new Shortcut[result.size()]; for (int i = 0; i < resultArray.length; i++) { resultArray[i] = (Shortcut) result.get(i); } return resultArray; }