List of usage examples for org.apache.commons.io.filefilter IOFileFilter IOFileFilter
IOFileFilter
From source file:$.MessageLogParser.java
/** * Gets lines from the log file which corresponds with specified correlation ID. *// ww w . j a v a 2s. c o m * @param correlationId the correlation ID * @param logDate which date to search log files for * @return log lines * @throws IOException when error occurred during file reading */ List<String> getLogLines(String correlationId, Date logDate) throws IOException { File logFolder = new File(logFolderPath); if (!logFolder.exists() || !logFolder.canRead()) { throw new FileNotFoundException("there is no readable log folder - " + logFolderPath); } final String logDateFormatted = fileFormat.format(logDate); // filter log files for current date IOFileFilter nameFilter = new IOFileFilter() { @Override public boolean accept(File file) { return logNameFilter.accept(file) && (StringUtils.contains(file.getName(), logDateFormatted) || file.getName().endsWith(BASE_FILE_EXTENSION)); } @Override public boolean accept(File dir, String name) { return StringUtils.contains(name, logDateFormatted) || name.endsWith(BASE_FILE_EXTENSION); } }; List<File> logFiles = new ArrayList<File>(FileUtils.listFiles(logFolder, nameFilter, null)); Collections.sort(logFiles, LastModifiedFileComparator.LASTMODIFIED_COMPARATOR); // go through all log files List<String> logLines = new ArrayList<String>(); for (File logFile : logFiles) { logLines.addAll(getLogLines(logFile, correlationId)); } return logLines; }
From source file:ch.unibas.fittingwizard.infrastructure.RealFitScript.java
public static List<File> getAllFitTabFiles(File rootDir) { logger.info("getAllFitTabFiles"); List<File> files = new ArrayList<>(FileUtils.listFiles(rootDir, new IOFileFilter() { @Override/*from w w w. j ava 2 s . co m*/ public boolean accept(File file) { return file.getName().endsWith(MtpfittabExtension); } @Override public boolean accept(File dir, String name) { return false; } }, TrueFileFilter.TRUE)); if (files.size() == 0) { throw new ScriptExecutionException("Could not find any fit tab results file in " + FilenameUtils.normalize(rootDir.getAbsolutePath())); } for (File file : files) { logger.info("Found fit tab file: " + FilenameUtils.normalize(file.getAbsolutePath())); } return files; }
From source file:io.cloudslang.lang.commons.services.impl.SlangCompilationServiceImpl.java
@Override public Collection<File> listSlangFiles(File directory, boolean recursive) { Validate.isTrue(directory.isDirectory(), "Parameter '" + directory.getPath() + INVALID_DIRECTORY_ERROR_MESSAGE_SUFFIX); return FileUtils.listFiles(directory, new IOFileFilter() { @Override// w w w .j a va 2 s.com public boolean accept(File file) { return Extension.SL == Extension.findExtension(file.getName()); } @Override public boolean accept(File file, String name) { return Extension.SL == Extension.findExtension(name); } }, recursive ? TrueFileFilter.INSTANCE : null); }
From source file:com.amalto.core.query.SystemStorageTest.java
private static Collection<String> getConfigFiles() throws Exception { URL data = InitDBUtil.class.getResource("data"); //$NON-NLS-1$ List<String> result = new ArrayList<String>(); if ("jar".equals(data.getProtocol())) { //$NON-NLS-1$ JarURLConnection connection = (JarURLConnection) data.openConnection(); JarEntry entry = connection.getJarEntry(); JarFile file = connection.getJarFile(); Enumeration<JarEntry> entries = file.entries(); while (entries.hasMoreElements()) { JarEntry e = entries.nextElement(); if (e.getName().startsWith(entry.getName()) && !e.isDirectory()) { result.add(IOUtils.toString(file.getInputStream(e))); }/*from www. j a va 2 s . co m*/ } } else { Collection<File> files = FileUtils.listFiles(new File(data.toURI()), new IOFileFilter() { @Override public boolean accept(File file) { return true; } @Override public boolean accept(File file, String s) { return true; } }, new IOFileFilter() { @Override public boolean accept(File file) { return !".svn".equals(file.getName()); //$NON-NLS-1$ } @Override public boolean accept(File file, String s) { return !".svn".equals(file.getName()); //$NON-NLS-1$ } }); for (File f : files) { result.add(IOUtils.toString(new FileInputStream(f))); } } return result; }
From source file:dpfmanager.shell.interfaces.gui.component.show.ShowController.java
public IOFileFilter customFilter(String extension) { return new IOFileFilter() { @Override/*ww w .j a v a 2s . c o m*/ public boolean accept(File file) { if (file.isDirectory()) { return false; } if (file.getName().startsWith("summary")) { return false; } if (extension.equals("xml") && file.getName().endsWith(extension) && !file.getName().endsWith(".mets.xml")) { return true; } else if (!extension.equals("xml")) { return file.getName().endsWith(extension); } return false; } @Override public boolean accept(File file, String s) { return true; } }; }
From source file:com.bluexml.tools.miscellaneous.PrepareSIDEModulesMigration.java
private static void executeInpath(boolean inplace, String frameworkmodulesPath, String classifier_base, String version_base, String classifier_target, String version_target, String frameworkmodulesInplace, File workspaceFile, final String versionInProjectName, String versionInProjectName2) { File frameworkmodulesPathFile = new File(frameworkmodulesPath); if (inplace) { frameworkmodulesPathFile = new File(frameworkmodulesInplace); Collection<?> listFiles = FileUtils.listFiles(frameworkmodulesPathFile, TrueFileFilter.INSTANCE, new IOFileFilter() { public boolean accept(File dir, String name) { return !name.equals(".svn"); }//from www . j av a2 s . co m public boolean accept(File file) { return !file.getName().equals(".svn"); } }); for (Object object : listFiles) { File f = (File) object; // System.out.println("PrepareSIDEModulesMigration.main() file :" + f); replaceVersionInFile(versionInProjectName, versionInProjectName2, version_base, classifier_base, version_target, classifier_target, f, true); } } else if (frameworkmodulesPathFile.exists()) { // copy resource // get project to copy File[] listFilesT = frameworkmodulesPathFile.listFiles(); System.out.println("PrepareSIDEModulesMigration.main() all :" + listFilesT.length); File[] listFiles = frameworkmodulesPathFile.listFiles(new FileFilter() { public boolean accept(File file) { if (file.isDirectory()) { String pat = versionInProjectName; pat = ".*" + Pattern.quote(pat) + ".*"; boolean matches = file.getName().matches(pat); System.out.println("accept() file" + file.getName() + " pattern :" + pat + " ?" + matches); return matches; } System.out .println("PrepareSIDEModulesMigration.main(...).new FileFilter() {...}.accept() FALSE"); return false; } }); System.out.println("PrepareSIDEModulesMigration.main() to copy : " + listFiles.length); for (File srcDir : listFiles) { System.out.println("PrepareSIDEModulesMigration.main() copy dir :" + srcDir); File copyDir = copyDir(workspaceFile, srcDir); reNameResources(versionInProjectName, copyDir, versionInProjectName2, version_base, classifier_base, version_target, classifier_target); } } else { System.err.println("frameworkmodulesPathFile do not exists :" + frameworkmodulesPathFile); } }
From source file:dpfmanager.shell.interfaces.gui.component.show.ShowController.java
public IOFileFilter customFilterDir(String path) { return new IOFileFilter() { @Override//w w w .j a va 2s.c om public boolean accept(File file) { return true; } @Override public boolean accept(File file, String s) { return file.getPath().equals(path); } }; }
From source file:info.magnolia.importexport.Bootstrapper.java
/** * Get the files to bootstrap. The method garantees that only one file is imported if it occures twice in the * bootstrap dir. The set is returned sorted, so that the execution fo the import will import the upper most nodes * first. This is done using the filelength. * * @return the sorted set//from w w w. j ava 2s . co m */ private static SortedSet<File> getBootstrapFiles(String[] bootdirs, final String repositoryName, final BootstrapFilter filter) { SortedSet<File> xmlfileset = new TreeSet<File>(new BootstrapFilesComparator()); for (int j = 0; j < bootdirs.length; j++) { String bootdir = bootdirs[j]; File xmldir = new File(bootdir); if (!xmldir.exists() || !xmldir.isDirectory()) { continue; } @SuppressWarnings("unchecked") Collection<File> files = FileUtils.listFiles(xmldir, new IOFileFilter() { @Override public boolean accept(File file) { return accept(file.getParentFile(), file.getName()); } @Override public boolean accept(File dir, String name) { return name.startsWith(repositoryName + ".") && filter.accept(name) && (name.endsWith(DataTransporter.XML) || name.endsWith(DataTransporter.ZIP) || name.endsWith(DataTransporter.GZ) || name.endsWith(DataTransporter.PROPERTIES)); } }, FileFilterUtils.trueFileFilter()); xmlfileset.addAll(files); } return xmlfileset; }
From source file:com.edgenius.core.util.ZipFileUtil.java
/** * Creates a ZIP file and places it in the current working directory. The zip file is compressed * at the default compression level of the Deflater. * /*from w w w . j a v a 2 s .c o m*/ * @param listToZip. Key is file or directory, value is parent directory which will remove from given file/directory because * compression only save relative directory. For example, c:\geniuswiki\data\repository\somefile, if value is c:\geniuswiki, then only * \data\repository\somefile will be saved. It is very important, the value must be canonical path, ie, c:\my document\geniuswiki, * CANNOT like this "c:\my doc~1\" * * */ public static void createZipFile(String zipFileName, Map<File, String> listToZip, boolean withEmptyDir) throws ZipFileUtilException { ZipOutputStream zop = null; try { zop = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zipFileName))); zop.setMethod(ZipOutputStream.DEFLATED); zop.setLevel(Deflater.DEFAULT_COMPRESSION); for (Entry<File, String> entry : listToZip.entrySet()) { File file = entry.getKey(); if (!file.exists()) { log.warn("Unable to find file " + file + " to zip"); continue; } if (file.isDirectory()) { Collection<File> list = FileUtils.listFiles(file, null, true); for (File src : list) { addEntry(zop, src, createRelativeDir(src.getCanonicalPath(), entry.getValue())); } if (withEmptyDir) { final List<File> emptyDirs = new ArrayList<File>(); if (file.list().length == 0) { emptyDirs.add(file); } else { //I just don't know how quickly to find out all empty sub directories recursively. so use below hack: FileUtils.listFiles(file, FileFilterUtils.falseFileFilter(), new IOFileFilter() { //JDK1.6 @Override public boolean accept(File f) { if (!f.isDirectory()) return false; int size = f.listFiles().length; if (size == 0) { emptyDirs.add(f); } return true; } //JDK1.6 @Override public boolean accept(File arg0, String arg1) { return true; } }); } for (File src : emptyDirs) { addEntry(zop, null, createRelativeDir(src.getCanonicalPath(), entry.getValue())); } } } else { addEntry(zop, file, createRelativeDir(file.getCanonicalPath(), entry.getValue())); } } } catch (IOException e1) { throw new ZipFileUtilException( "An error has occurred while trying to zip the files. Error message is: ", e1); } finally { try { if (zop != null) zop.close(); } catch (Exception e) { } } }
From source file:jenkins.plugins.shiningpanda.ShiningPandaTestCase.java
/** * Delete a VIRTUALENV./*from w w w .j a va 2 s . com*/ * * @param home * The home folder of the VIRTUALENV. * @throws IOException */ protected void deleteVirtualenv(File home) throws IOException { // Check if exists if (!home.exists()) return; // Do not follow symbolic links IOFileFilter filter = new IOFileFilter() { /* * (non-Javadoc) * * @see * org.apache.commons.io.filefilter.IOFileFilter#accept(java.io. * File, java.lang.String) */ public boolean accept(File dir, String name) { return accept(dir); } /* * (non-Javadoc) * * @see * org.apache.commons.io.filefilter.IOFileFilter#accept(java.io. * File) */ public boolean accept(File file) { try { return !FileUtils.isSymlink(file); } catch (IOException e) { e.printStackTrace(); } return false; } }; // Go threw the selected files to set write permission for (File file : FileUtils.listFiles(home, filter, filter)) { // Set write permission file.setWritable(true); } // Delete the directory FileUtils.deleteDirectory(home); }