/** * Returns a filter that returns true if the filename matches the specified text. * * @param name the filename * @param caseSensitivity how to handle case sensitivity, null means case-sensitive * @return a name checking filter * @see NameFileFilter * @since 2.0 */ public static IOFileFilter nameFileFilter(final String name, final IOCase caseSensitivity) { return new NameFileFilter(name, caseSensitivity); }
/** * Returns a filter that returns true if the filename matches the specified text. * * @param name the filename * @return a name checking filter * @see NameFileFilter */ public static IOFileFilter nameFileFilter(final String name) { return new NameFileFilter(name); }
/** * Returns a filter that returns true if the filename matches the specified text. * * @param name the filename * @return a name checking filter */ public static IOFileFilter nameFileFilter(String name) { return new NameFileFilter(name); }
/** * Create a name filter containing the names of the files * in the array. */ private static IOFileFilter createNameFilter(final File[] files) { final String[] names = new String[files.length]; for (int i = 0; i < files.length; i++) { names[i] = files[i].getName(); } return new NameFileFilter(names); }
/** * Create a name filter containing the names of the files * in the array. */ private static IOFileFilter createNameFilter(final File[] files) { final String[] names = new String[files.length]; for (int i = 0; i < files.length; i++) { names[i] = files[i].getName(); } return new NameFileFilter(names); }
public String getIndexPageURL() { try { File testOutputFolder = artifactsService.findArtifact(job.getIdentifier(), TEST_OUTPUT_FOLDER); if (testOutputFolder.exists()) { Collection<File> files = FileUtils.listFiles(testOutputFolder, new NameFileFilter("index.html"), TrueFileFilter.TRUE); if (files.isEmpty()) { return null; } File testIndexPage = files.iterator().next(); return getRestfulUrl(testIndexPage.getPath().substring(testIndexPage.getPath().indexOf(TEST_OUTPUT_FOLDER))); } } catch (Exception ignore) { } return null; }
/** * Builds the filter and returns it. * * @return a filter that is the logical OR of all the conditions provided by the add... methods * @throws IllegalStateException if no add... method has been called with one or more arguments */ public FileFilter build() { if (filenames.isEmpty() && extensions.isEmpty() && fileFilters.isEmpty()) { throw new IllegalStateException("May only be invoked after at least one add... method has been invoked."); } final OrFileFilter filter = new OrFileFilter(); if (!filenames.isEmpty()) { filter.addFileFilter(new NameFileFilter(new ArrayList<>(filenames))); } if (!extensions.isEmpty()) { filter.addFileFilter(new SuffixFileFilter(new ArrayList<>(extensions), IOCase.INSENSITIVE)); } for (IOFileFilter iof : fileFilters) { filter.addFileFilter(iof); } return filter; } }
@Test(expected = IllegalArgumentException.class) public void testNameFilterNullListArgument() throws Exception { final List<String> test = null; new NameFileFilter(test); fail("constructing a NameFileFilter with a null List argument should fail."); }
@Test(expected = IllegalArgumentException.class) public void testNameFilterNullArrayArgument() throws Exception { new NameFileFilter((String[]) null); fail( "constructing a NameFileFilter with a null String[] argument should fail."); }
@Test public void testCopyDirectoryFiltered() throws Exception { final File grandParentDir = new File(getTestDirectory(), "grandparent"); final File parentDir = new File(grandParentDir, "parent"); final File childDir = new File(parentDir, "child"); createFilesForTestCopyDirectory(grandParentDir, parentDir, childDir); final NameFileFilter filter = new NameFileFilter(new String[]{"parent", "child", "file3.txt"}); final File destDir = new File(getTestDirectory(), "copydest"); FileUtils.copyDirectory(grandParentDir, destDir, filter); final List<File> files = LIST_WALKER.list(destDir); assertEquals(3, files.size()); assertEquals("parent", files.get(0).getName()); assertEquals("child", files.get(1).getName()); assertEquals("file3.txt", files.get(2).getName()); }
@Test public void testNameFilter() throws Exception { IOFileFilter filter = new NameFileFilter(new String[] { "foo", "bar" }); assertFiltering(filter, new File("foo"), true); assertFiltering(filter, new File("bar"), true); assertFiltering(filter, new File("fred"), false); filter = new NameFileFilter(new String[] { "foo", "bar" }, IOCase.SENSITIVE); assertFiltering(filter, new File("foo"), true); assertFiltering(filter, new File("bar"), true); filter = new NameFileFilter(new String[] { "foo", "bar" }, IOCase.INSENSITIVE); assertFiltering(filter, new File("foo"), true); assertFiltering(filter, new File("bar"), true); filter = new NameFileFilter(new String[] { "foo", "bar" }, IOCase.SYSTEM); assertFiltering(filter, new File("foo"), true); assertFiltering(filter, new File("bar"), true); filter = new NameFileFilter(new String[]{"foo", "bar"}, null); assertFiltering(filter, new File("foo"), true); assertFiltering(filter, new File("bar"), true); list.add("foo"); list.add("bar"); filter = new NameFileFilter(list); assertFiltering(filter, new File("foo"), true); assertFiltering(filter, new File("bar"), true); assertFiltering(filter, new File("fred"), false);
@Test public void testNameFilterNullArgument() throws Exception { final String test = null; try { new NameFileFilter(test); fail( "constructing a NameFileFilter with a null String argument should fail."); } catch( final IllegalArgumentException ignore ) { } try { FileFilterUtils.nameFileFilter(test, IOCase.INSENSITIVE); fail( "constructing a NameFileFilter with a null String argument should fail."); } catch( final IllegalArgumentException ignore ) { } }
private File getCompiledClass(File targetFolder, String name) { String className = name.replace("java", "class"); Collection<File> classes = listFiles(targetFolder, new NameFileFilter(className), TRUE); if (classes.size() > 1) { throw new IllegalStateException("Cannot return compiled class as there are more than one compiled class file"); } return classes.iterator().next(); }
/** * Returns a filter that returns true if the filename matches the specified text. * * @param name the filename * @return a name checking filter * @see NameFileFilter */ public static IOFileFilter nameFileFilter(String name) { return new NameFileFilter(name); }
/** * Returns a filter that returns true if the filename matches the specified text. * * @param name the filename * @param caseSensitivity how to handle case sensitivity, null means case-sensitive * @return a name checking filter * @see NameFileFilter * @since 2.0 */ public static IOFileFilter nameFileFilter(String name, IOCase caseSensitivity) { return new NameFileFilter(name, caseSensitivity); }
/** * Returns a filter that returns true if the filename matches the specified text. * * @param name the filename * @param caseSensitivity how to handle case sensitivity, null means case-sensitive * @return a name checking filter * @see NameFileFilter * @since 2.0 */ public static IOFileFilter nameFileFilter(String name, IOCase caseSensitivity) { return new NameFileFilter(name, caseSensitivity); }
/** * Returns a filter that returns true if the filename matches the specified text. * * @param name the filename * @return a name checking filter * @see NameFileFilter */ public static IOFileFilter nameFileFilter(final String name) { return new NameFileFilter(name); }
/** * Returns a filter that returns true if the filename matches the specified text. * * @param name the filename * @param caseSensitivity how to handle case sensitivity, null means case-sensitive * @return a name checking filter * @see NameFileFilter * @since 2.0 */ public static IOFileFilter nameFileFilter(String name, IOCase caseSensitivity) { return new NameFileFilter(name, caseSensitivity); }
/** * Returns a filter that returns true if the filename matches the specified text. * * @param name the filename * @return a name checking filter * @see NameFileFilter */ public static IOFileFilter nameFileFilter(final String name) { return new NameFileFilter(name); }
private File getCompiledClass(File targetFolder, String name) { String className = name.replace("java", "class"); Collection<File> classes = listFiles(targetFolder, new NameFileFilter(className), TRUE); if (classes.size() > 1) { throw new IllegalStateException("Cannot return compiled class as there are more than one compiled class file"); } return classes.iterator().next(); }