List of usage examples for org.apache.commons.io.filefilter TrueFileFilter INSTANCE
IOFileFilter INSTANCE
To view the source code for org.apache.commons.io.filefilter TrueFileFilter INSTANCE.
Click Source Link
From source file:org.eclipse.thym.core.internal.util.FileUtils.java
/** * Resolves a filename including wildcard characters to files in the * given directory tree. This method recurses in the the subdirectories. * @param parent a directory// w ww. j a v a 2 s . co m * @param filename name for file * @return array of files found matching filename or an empty array */ public static File[] resolveFile(File parent, String filename) { if (parent == null) { return new File[0]; } if (!parent.isDirectory() || filename == null || filename.isEmpty() || filename.equals(".")) { return new File[] { parent }; } File f = new File(parent, filename); if (f.exists()) { return new File[] { f }; } Collection<File> theFiles = org.apache.commons.io.FileUtils.listFiles(parent, new WildcardFileFilter(filename), TrueFileFilter.INSTANCE); return theFiles.toArray(new File[theFiles.size()]); }
From source file:org.efaps.esjp.admin.store.Migration.java
/** * Migrate teh files from a vfs repository to jcr repository; * <ol>/*from w w w. j av a 2 s . c om*/ * <li>Change the repository definition for the type to be migrated</li> * <li>Get the files from the file system.</li> * </ol> * @param _parameter Parameter as passed by the eFaps API * @return new Return * @throws EFapsException */ public Return vfs2jcs(final Parameter _parameter) throws EFapsException { final String baseDirPath = "/efaps/store/archives"; final File baseDir = new File(baseDirPath); final IOFileFilter fileFilter = new RegexFileFilter("[0-9]*\\.[0-9]*"); final Collection<File> files = FileUtils.listFiles(baseDir, fileFilter, TrueFileFilter.INSTANCE); for (final File file : files) { final Instance inst = Instance.get(file.getName()); try { System.out.println(file); //GeneralStoreVFS final QueryBuilder queryBldr = new QueryBuilder( UUID.fromString("cd21d9e9-9009-46bf-9ed7-26bedc623149")); queryBldr.addWhereAttrEqValue("InstanceID", inst.getId()); queryBldr.addWhereAttrEqValue("InstanceTypeID", inst.getType().getId()); final MultiPrintQuery multi = queryBldr.getPrint(); multi.addAttribute("FileLength", "FileName"); multi.execute(); multi.next(); final String fileName = multi.<String>getAttribute("FileName"); final Long fileLength = multi.<Long>getAttribute("FileLength"); final FileInputStream finput = new FileInputStream(file); final InputStream input = new GZIPInputStream(finput); final Checkin checkin = new Checkin(inst); checkin.execute(fileName, input, fileLength.intValue()); } catch (final FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (final IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return new Return(); }
From source file:org.evosuite.junit.TestSuiteWriter.java
/** * Update/create the main file of the test suite. The main test file simply * includes all automatically generated test suites in the same directory * //w w w . j a va2s .c o m * @param directory * Directory of generated test files */ public void writeTestSuiteMainFile(String directory) { File file = new File(mainDirectory(directory) + "/GeneratedTestSuite.java"); StringBuilder builder = new StringBuilder(); if (!Properties.PROJECT_PREFIX.equals("")) { builder.append("package "); builder.append(Properties.PROJECT_PREFIX); // builder.append(".GeneratedTests;"); builder.append(";\n\n"); } List<String> suites = new ArrayList<String>(); File basedir = new File(directory); Iterator<File> i = FileUtils.iterateFiles(basedir, new TestFilter(), TrueFileFilter.INSTANCE); while (i.hasNext()) { File f = i.next(); String name = f.getPath().replace(directory, "").replace(".java", "").replace("/", "."); if (name.startsWith(".")) name = name.substring(1); suites.add(name); } builder.append(adapter.getSuite(suites)); Utils.writeFile(builder.toString(), file); }
From source file:org.fcrepo.integration.connector.file.AbstractFedoraFileSystemConnectorIT.java
protected static void cleanUpJsonFilesFiles(final File directory) { final WildcardFileFilter filter = new WildcardFileFilter("*.modeshape.json"); final Collection<File> files = FileUtils.listFiles(directory, filter, TrueFileFilter.INSTANCE); final Iterator<File> iterator = files.iterator(); // Clean up files persisted in previous runs while (iterator.hasNext()) { final File f = iterator.next(); final String path = f.getAbsolutePath(); try {//w w w. j a va 2 s. c o m Files.deleteIfExists(Paths.get(path)); } catch (final IOException e) { logger.error("Error in clean up", e); fail("Unable to delete work files from a previous test run. File=" + path); } } }
From source file:org.fcrepo.integration.connector.file.FedoraFileSystemConnectorIT.java
/** * Sets a system property and ensures artifacts from previous tests are * cleaned up./*from www .j a v a2 s . c o m*/ */ @BeforeClass public static void beforeClass() { final File testDir = new File("target/test-classes"); final WildcardFileFilter filter = new WildcardFileFilter("*.modeshape.json"); final Collection<File> files = FileUtils.listFiles(testDir, filter, TrueFileFilter.INSTANCE); final Iterator<File> iterator = files.iterator(); // Clean up files persisted in previous runs while (iterator.hasNext()) { if (!iterator.next().delete()) { fail("Unable to delete work files from a previous test run"); } } // Note: This property is used in the repository.json setProperty(PROP_TEST_DIR, testDir.getAbsolutePath()); }
From source file:org.finra.dm.service.helper.DmHelper.java
/** * Validate downloaded S3 files per storage unit information. * * @param baseDirectory the local parent directory path, relative to which the files are expected to be located * @param s3KeyPrefix the S3 key prefix that was prepended to the S3 file paths, when they were uploaded to S3 * @param storageUnit the storage unit that contains a list of storage files to be validated * * @throws IllegalStateException if files are not valid. *///from ww w .j a va 2s .c o m public void validateDownloadedS3Files(String baseDirectory, String s3KeyPrefix, StorageUnit storageUnit) throws IllegalStateException { // Build a target local directory path, which is the parent directory plus the S3 key prefix. File targetLocalDirectory = Paths.get(baseDirectory, s3KeyPrefix).toFile(); // Get a list of all files within the target local directory and its subdirectories. Collection<File> actualLocalFiles = FileUtils.listFiles(targetLocalDirectory, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE); // Validate the total file count. int storageFilesCount = CollectionUtils.isEmpty(storageUnit.getStorageFiles()) ? 0 : storageUnit.getStorageFiles().size(); if (storageFilesCount != actualLocalFiles.size()) { throw new IllegalStateException(String.format( "Number of downloaded files does not match the storage unit information (expected %d files, actual %d files).", storageUnit.getStorageFiles().size(), actualLocalFiles.size())); } // Validate each downloaded file. if (storageFilesCount > 0) { for (StorageFile storageFile : storageUnit.getStorageFiles()) { // Create a "real file" that points to the actual file on the file system. File localFile = Paths.get(baseDirectory, storageFile.getFilePath()).toFile(); // Verify that the file exists. if (!localFile.isFile()) { throw new IllegalStateException( String.format("Downloaded \"%s\" file doesn't exist.", localFile)); } // Validate the file size. if (localFile.length() != storageFile.getFileSizeBytes()) { throw new IllegalStateException(String.format( "Size of the downloaded \"%s\" S3 file does not match the expected value (expected %d bytes, actual %d bytes).", localFile.getPath(), storageFile.getFileSizeBytes(), localFile.length())); } } } }
From source file:org.finra.dm.tools.downloader.DownloaderController.java
/** * Logs all files found in the specified local directory. * * @param directory the target local directory *//*from w w w .ja v a2 s.com*/ private void logLocalDirectoryContents(File directory) { Collection<File> files = DmFileUtils.listFiles(directory, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE); LOGGER.info(String.format("Found %d files in \"%s\" target local directory:", files.size(), directory.getPath())); for (File file : files) { LOGGER.info(String.format(" %s", file.getPath())); } }
From source file:org.finra.herd.service.helper.HerdHelper.java
/** * Validate downloaded S3 files per specified list of storage files. * * @param baseDirectory the local parent directory path, relative to which the files are expected to be located * @param s3KeyPrefix the S3 key prefix that was prepended to the S3 file paths, when they were uploaded to S3 * @param storageFiles the list of storage files * * @throws IllegalStateException if files are not valid *//*from w ww .j av a 2s . co m*/ public void validateDownloadedS3Files(String baseDirectory, String s3KeyPrefix, List<StorageFile> storageFiles) throws IllegalStateException { // Build a target local directory path, which is the parent directory plus the S3 key prefix. File targetLocalDirectory = Paths.get(baseDirectory, s3KeyPrefix).toFile(); // Get a list of all files within the target local directory and its subdirectories. Collection<File> actualLocalFiles = FileUtils.listFiles(targetLocalDirectory, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE); // Validate the total file count. int storageFilesCount = CollectionUtils.isEmpty(storageFiles) ? 0 : storageFiles.size(); if (storageFilesCount != actualLocalFiles.size()) { throw new IllegalStateException(String.format( "Number of downloaded files does not match the storage unit information (expected %d files, actual %d files).", storageFiles.size(), actualLocalFiles.size())); } // Validate each downloaded file. if (storageFilesCount > 0) { for (StorageFile storageFile : storageFiles) { // Create a "real file" that points to the actual file on the file system. File localFile = Paths.get(baseDirectory, storageFile.getFilePath()).toFile(); // Verify that the file exists. if (!localFile.isFile()) { throw new IllegalStateException( String.format("Downloaded \"%s\" file doesn't exist.", localFile)); } // Validate the file size. if (localFile.length() != storageFile.getFileSizeBytes()) { throw new IllegalStateException(String.format( "Size of the downloaded \"%s\" S3 file does not match the expected value (expected %d bytes, actual %d bytes).", localFile.getPath(), storageFile.getFileSizeBytes(), localFile.length())); } } } }
From source file:org.finra.herd.tools.downloader.DownloaderController.java
/** * Logs all files found in the specified local directory. * * @param directory the target local directory *//* ww w . ja v a2s . c om*/ private void logLocalDirectoryContents(File directory) { Collection<File> files = HerdFileUtils.listFiles(directory, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE); LOGGER.info(String.format("Found %d files in \"%s\" target local directory:", files.size(), directory.getPath())); for (File file : files) { LOGGER.info(String.format(" %s", file.getPath())); } }
From source file:org.geoserver.bkprst.rest.test.Utils.java
static int getNumFiles(File dir) { return FileUtils.listFiles(dir, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE).size(); }