/** * <p> * Applies an {@link IOFileFilter} to the provided {@link File} * objects. The resulting list is a subset of the original files that * matches the provided filter. * </p> * * <p> * The {@link List} returned by this method is not guaranteed to be thread safe. * </p> * * <pre> * List<File> filesAndDirectories = ... * List<File> directories = FileFilterUtils.filterList(filesAndDirectories, * FileFilterUtils.directoryFileFilter()); * </pre> * @param filter the filter to apply to each files in the list. * @param files the collection of files to apply the filter to. * * @return a subset of <code>files</code> that is accepted by the * file filter. * @throws IllegalArgumentException if the filter is {@code null} * or <code>files</code> contains a {@code null} value. * @since 2.0 */ public static List<File> filterList(final IOFileFilter filter, final Iterable<File> files) { return filter(filter, files, new ArrayList<File>()); }
/** * <p> * Applies an {@link IOFileFilter} to the provided {@link File} * objects. The resulting list is a subset of the original files that * matches the provided filter. * </p> * * <p> * The {@link List} returned by this method is not guaranteed to be thread safe. * </p> * * <pre> * List<File> filesAndDirectories = ... * List<File> directories = FileFilterUtils.filterList(filesAndDirectories, * FileFilterUtils.directoryFileFilter()); * </pre> * @param filter the filter to apply to each files in the list. * @param files the collection of files to apply the filter to. * * @return a subset of <code>files</code> that is accepted by the * file filter. * @throws IllegalArgumentException if the filter is {@code null} * or <code>files</code> contains a {@code null} value. * @since 2.0 */ public static List<File> filterList(final IOFileFilter filter, final File... files) { final File[] acceptedFiles = filter(filter, files); return Arrays.asList(acceptedFiles); }
/** * <p> * Applies an {@link IOFileFilter} to the provided {@link File} * objects. The resulting set is a subset of the original file list that * matches the provided filter. * </p> * * <p> * The {@link Set} returned by this method is not guaranteed to be thread safe. * </p> * * <pre> * Set<File> allFiles = ... * Set<File> javaFiles = FileFilterUtils.filterSet(allFiles, * FileFilterUtils.suffixFileFilter(".java")); * </pre> * @param filter the filter to apply to the set of files. * @param files the collection of files to apply the filter to. * * @return a subset of <code>files</code> that is accepted by the * file filter. * @throws IllegalArgumentException if the filter is {@code null} * or <code>files</code> contains a {@code null} value. * * @since 2.0 */ public static Set<File> filterSet(final IOFileFilter filter, final Iterable<File> files) { return filter(filter, files, new HashSet<File>()); }
/** * <p> * Applies an {@link IOFileFilter} to the provided {@link File} * objects. The resulting set is a subset of the original file list that * matches the provided filter. * </p> * * <p> * The {@link Set} returned by this method is not guaranteed to be thread safe. * </p> * * <pre> * Set<File> allFiles = ... * Set<File> javaFiles = FileFilterUtils.filterSet(allFiles, * FileFilterUtils.suffixFileFilter(".java")); * </pre> * @param filter the filter to apply to the set of files. * @param files the collection of files to apply the filter to. * * @return a subset of <code>files</code> that is accepted by the * file filter. * @throws IllegalArgumentException if the filter is {@code null} * or <code>files</code> contains a {@code null} value. * * @since 2.0 */ public static Set<File> filterSet(final IOFileFilter filter, final File... files) { final File[] acceptedFiles = filter(filter, files); return new HashSet<>(Arrays.asList(acceptedFiles)); }
@Test public void testFilterArrayNullParameters() throws Exception { final File fileA = TestUtils.newFile(getTestDirectory(), "A"); final File fileB = TestUtils.newFile(getTestDirectory(), "B"); try { FileFilterUtils.filter(null, fileA, fileB); fail(); } catch (final IllegalArgumentException iae) { // Test passes, exception thrown for null filter } final IOFileFilter filter = FileFilterUtils.trueFileFilter(); try { FileFilterUtils.filter(filter, fileA, null); fail(); } catch (final IllegalArgumentException iae) { // Test passes, exception thrown for list containing null } final File[] filtered = FileFilterUtils.filter(filter, (File[])null); assertEquals(0, filtered.length); }
@Test public void testFilterArray_fromList() throws Exception { final File fileA = TestUtils.newFile(getTestDirectory(), "A"); final File fileB = TestUtils.newFile(getTestDirectory(), "B"); final List<File> fileList = Arrays.asList(fileA, fileB); final IOFileFilter filter = FileFilterUtils.nameFileFilter("A"); final File[] filtered = FileFilterUtils.filter(filter, fileList); assertEquals(1, filtered.length); assertEquals(fileA, filtered[0]); }
@Test public void testFilterArray() throws Exception { final File fileA = TestUtils.newFile(getTestDirectory(), "A"); final File fileB = TestUtils.newFile(getTestDirectory(), "B"); final IOFileFilter filter = FileFilterUtils.nameFileFilter("A"); final File[] filtered = FileFilterUtils.filter(filter, fileA, fileB); assertEquals(1, filtered.length); assertEquals(fileA, filtered[0]); }
/** * <p> * Applies an {@link IOFileFilter} to the provided {@link File} * objects. The resulting list is a subset of the original files that * matches the provided filter. * </p> * * <p> * The {@link List} returned by this method is not guaranteed to be thread safe. * </p> * * <pre> * List<File> filesAndDirectories = ... * List<File> directories = FileFilterUtils.filterList(filesAndDirectories, * FileFilterUtils.directoryFileFilter()); * </pre> * @param filter the filter to apply to each files in the list. * @param files the collection of files to apply the filter to. * * @return a subset of <code>files</code> that is accepted by the * file filter. * @throws IllegalArgumentException if the filter is {@code null} * or <code>files</code> contains a {@code null} value. * @since 2.0 */ public static List<File> filterList(final IOFileFilter filter, final Iterable<File> files) { return filter(filter, files, new ArrayList<File>()); }
/** * <p> * Applies an {@link IOFileFilter} to the provided {@link File} * objects. The resulting set is a subset of the original file list that * matches the provided filter. * </p> * * <p> * The {@link Set} returned by this method is not guaranteed to be thread safe. * </p> * * <pre> * Set<File> allFiles = ... * Set<File> javaFiles = FileFilterUtils.filterSet(allFiles, * FileFilterUtils.suffixFileFilter(".java")); * </pre> * @param filter the filter to apply to the set of files. * @param files the collection of files to apply the filter to. * * @return a subset of <code>files</code> that is accepted by the * file filter. * @throws IllegalArgumentException if the filter is {@code null} * or <code>files</code> contains a {@code null} value. * * @since 2.0 */ public static Set<File> filterSet(IOFileFilter filter, Iterable<File> files) { return filter(filter, files, new HashSet<File>()); }
/** * <p> * Applies an {@link IOFileFilter} to the provided {@link File} * objects. The resulting list is a subset of the original files that * matches the provided filter. * </p> * * <p> * The {@link List} returned by this method is not guaranteed to be thread safe. * </p> * * <pre> * List<File> filesAndDirectories = ... * List<File> directories = FileFilterUtils.filterList(filesAndDirectories, * FileFilterUtils.directoryFileFilter()); * </pre> * @param filter the filter to apply to each files in the list. * @param files the collection of files to apply the filter to. * * @return a subset of <code>files</code> that is accepted by the * file filter. * @throws IllegalArgumentException if the filter is {@code null} * or <code>files</code> contains a {@code null} value. * @since 2.0 */ public static List<File> filterList(final IOFileFilter filter, final File... files) { final File[] acceptedFiles = filter(filter, files); return Arrays.asList(acceptedFiles); }
/** * <p> * Applies an {@link IOFileFilter} to the provided {@link File} * objects. The resulting list is a subset of the original files that * matches the provided filter. * </p> * * <p> * The {@link List} returned by this method is not guaranteed to be thread safe. * </p> * * <pre> * List<File> filesAndDirectories = ... * List<File> directories = FileFilterUtils.filterList(filesAndDirectories, * FileFilterUtils.directoryFileFilter()); * </pre> * @param filter the filter to apply to each files in the list. * @param files the collection of files to apply the filter to. * * @return a subset of <code>files</code> that is accepted by the * file filter. * @throws IllegalArgumentException if the filter is <code>null</code> * or <code>files</code> contains a <code>null</code> value. * @since 2.0 */ public static List<File> filterList(IOFileFilter filter, Iterable<File> files) { return filter(filter, files, new ArrayList<File>()); }
/** * <p> * Applies an {@link IOFileFilter} to the provided {@link File} * objects. The resulting set is a subset of the original file list that * matches the provided filter. * </p> * * <p> * The {@link Set} returned by this method is not guaranteed to be thread safe. * </p> * * <pre> * Set<File> allFiles = ... * Set<File> javaFiles = FileFilterUtils.filterSet(allFiles, * FileFilterUtils.suffixFileFilter(".java")); * </pre> * @param filter the filter to apply to the set of files. * @param files the collection of files to apply the filter to. * * @return a subset of <code>files</code> that is accepted by the * file filter. * @throws IllegalArgumentException if the filter is {@code null} * or <code>files</code> contains a {@code null} value. * * @since 2.0 */ public static Set<File> filterSet(final IOFileFilter filter, final Iterable<File> files) { return filter(filter, files, new HashSet<File>()); }
private ClassRealm createBootRealm() throws Exception { List<URL> classpath = new ArrayList<>() ; File confDir = new File(installDir, "conf"); log.info("Boot conf dir: {}", confDir); classpath.add(confDir.toURI().toURL()); File libDir = new File(installDir, "lib"); log.info("Boot lib dir: {}", libDir); File[] jars = filter(suffixFileFilter(".jar"), libDir.listFiles()); for (File jar : jars) { classpath.add(jar.toURI().toURL()); } ClassRealm realm = world.newRealm("it-boot", null); log.info("Boot classpath:"); for (URL url : classpath) { log.info(" {}", url); realm.addURL(url); } return realm; }
@Override public DataRecord getMetadataRecord(String name) { checkArgument(!Strings.isNullOrEmpty(name), "name should not be empty"); for (File file : FileFilterUtils .filter(FileFilterUtils.nameFileFilter(name), fsPathDir.listFiles())) { if (!file.isDirectory()) { return new FSBackendDataRecord(this, new DataIdentifier(file.getName()), file); } } return null; }
@Override public DataRecord getMetadataRecord(String name) { checkArgument(!Strings.isNullOrEmpty(name), "name should not be empty"); for (File file : FileFilterUtils .filter(FileFilterUtils.nameFileFilter(name), fsPathDir.listFiles())) { if (!file.isDirectory()) { return new FSBackendDataRecord(this, new DataIdentifier(file.getName()), file); } } return null; }
@Override public DataRecord getMetadataRecord(String name) { checkArgument(!Strings.isNullOrEmpty(name), "name should not be empty"); File root = new File(getPath()); for (File file : FileFilterUtils.filter(FileFilterUtils.nameFileFilter(name), root.listFiles())) { if (!file.isDirectory()) { return new FileDataRecord(this, new DataIdentifier(file.getName()), file); } } return null; }
@Override public DataRecord getMetadataRecord(String name) { checkArgument(!Strings.isNullOrEmpty(name), "name should not be empty"); File root = new File(getPath()); for (File file : FileFilterUtils.filter(FileFilterUtils.nameFileFilter(name), root.listFiles())) { if (!file.isDirectory()) { return new FileDataRecord(this, new DataIdentifier(file.getName()), file); } } return null; }
@Override public DataRecord getMetadataRecord(String name) { for (File file : FileFilterUtils .filter(FileFilterUtils.nameFileFilter(name), fsPathDir.listFiles())) { if (!file.isDirectory()) { return new FSBackendDataRecord(this, new DataIdentifier(file.getName()), file); } } return null; }
@Override public DataRecord getMetadataRecord(String name) { File root = new File(getPath()); for (File file : FileFilterUtils.filter(FileFilterUtils.nameFileFilter(name), root.listFiles())) { if (!file.isDirectory()) { return new FileDataRecord(this, new DataIdentifier(file.getName()), file); } } return null; }
private static void assertFileEquals(File dump, String prefix, Set<String> blobsAdded) throws IOException { File files[] = FileFilterUtils.filter(FileFilterUtils.prefixFileFilter(prefix), dump.listFiles()); Assert.assertNotNull(files); Assert.assertTrue(files.length == 1); Assert.assertTrue(files[0].exists()); assertEquals(blobsAdded, FileIOUtils.readStringsAsSet(new FileInputStream(files[0]), false)); }