File[] dirs = new File(".").listFiles(new WildcardFileFilter("Test*.java"); for (int i=0; i<dirs.length; i++) { File dir = dirs[i]; if (dir.isDirectory()) { File[] files = dir.listFiles(new WildcardFileFilter("sample*.java")); } }
@Override protected Collection<File> initObjects() { final Collection<File> files = FileUtils.listFiles( Preconditions.checkNotNull(baseDir).getAbsoluteFile(), new WildcardFileFilter(filter), TrueFileFilter.INSTANCE ); log.info("Initialized with " + files + " files"); return files; }
/** * Loads the configuration from disk. */ public void load() throws IOException { logRecorders.clear(); File dir = configDir(); File[] files = dir.listFiles((FileFilter)new WildcardFileFilter("*.xml")); if(files==null) return; for (File child : files) { String name = child.getName(); name = name.substring(0,name.length()-4); // cut off ".xml" LogRecorder lr = new LogRecorder(name); lr.load(); logRecorders.put(name,lr); } }
/** * retrieve files with wildcard matching. * Only support "dir/*". Pattern like "dir/foo*" or "dir/*foo*" will not be supported * since user shouldn't upload the jars they don't want to import * the reason for supporting dir/* is to provide another packaging option * which let user upload a dir of all required jars * in addition to one fat jar. */ private File[] getFilesMatchingPath(final String path) { if (path.endsWith("*")) { final File dir = new File(path.substring(0, path.lastIndexOf("/") + 1)); final FileFilter fileFilter = new WildcardFileFilter(path.substring(path.lastIndexOf("/") + 1)); final File[] files = dir.listFiles(fileFilter); return files; } else { return new File[]{new File(path)}; } }
public void execute(EnforcerRuleHelper helper) throws EnforcerRuleException { if (files == null) { return; } for (File file : files) { final String filePath = file.getPath(); final String prefix = filePath.substring(0, filePath.indexOf("*")); final String dirName = prefix.substring(0, prefix.lastIndexOf(File.separator)); final String fileItselfPattern = filePath.substring(dirName.length() + 1); final File dir = new File(dirName); if (!dir.isDirectory()) { continue; } final Set<File> matchedFiles = new TreeSet<>(); for (File matchedFile : dir.listFiles((FileFilter) new WildcardFileFilter(fileItselfPattern))) { matchedFiles.add(matchedFile); } if (!matchedFiles.isEmpty()) { throw new EnforcerRuleException("Files found! " + Arrays.toString(matchedFiles.toArray())); } } } }
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { LOG.info("Requesting jdbc standalone jar download"); response.setHeader("Content-disposition", JAR_CONTENT_DISPOSITION); response.setContentType(JAR_CONTENT_TYPE); File dir = new File(JDBC_JAR_DIR); FileFilter fileFilter = new WildcardFileFilter(JDBC_JAR_PATTERN); File[] files = dir.listFiles(fileFilter); if (files == null || files.length != 1) { handleError(files); response.sendError(HttpServletResponse.SC_NOT_FOUND); return; } File file = files[0]; LOG.info("Jdbc standalone jar found: " + file.getAbsolutePath()); try (FileInputStream in = new FileInputStream(file); OutputStream out = response.getOutputStream()) { byte[] buffer = new byte[4096]; int length; while ((length = in.read(buffer)) > 0) { out.write(buffer, 0, length); } } catch (Exception e) { LOG.error("Exception during downloading standalone jdbc jar", e); response.sendError(HttpServletResponse.SC_NOT_FOUND); } LOG.info("Jdbc standalone jar " + file.getAbsolutePath() + " was downloaded"); }
/** * Font file filter. Currently searches for files with .ttf, .ttc, .otf, and .pfb extensions. * @return IOFileFilter font file filter */ protected static IOFileFilter getFileFilter() { return FileFilterUtils.andFileFilter( FileFilterUtils.fileFileFilter(), new WildcardFileFilter( new String[] {"*.ttf", "*.otf", "*.pfb", "*.ttc"}, IOCase.INSENSITIVE) ); }
new WildcardFileFilter("*.*"), new WildcardFileFilter("*")); while (files.hasNext()) { filesCount++;
new WildcardFileFilter("*.*"), new WildcardFileFilter("*"));
new WildcardFileFilter("*.*"), new WildcardFileFilter("*"));
@Test public void testListFilesWithDirs() throws IOException { final File srcDir = getTestDirectory(); final File subDir1 = new File(srcDir, "subdir"); subDir1.mkdir(); final File subDir2 = new File(subDir1, "subdir2"); subDir2.mkdir(); final File someFile = new File(subDir2, "a.txt"); if (!someFile.getParentFile().exists()) { throw new IOException("Cannot create file " + someFile + " as the parent directory does not exist"); } final BufferedOutputStream output = new BufferedOutputStream(new FileOutputStream(someFile)); try { TestUtils.generateTestData(output, 100); } finally { IOUtils.closeQuietly(output); } final File subDir3 = new File(subDir2, "subdir3"); subDir3.mkdir(); final Collection<File> files = FileUtils.listFilesAndDirs(subDir1, new WildcardFileFilter("*.*"), new WildcardFileFilter("*")); assertEquals(4, files.size()); assertTrue("Should contain the directory.", files.contains(subDir1)); assertTrue("Should contain the directory.", files.contains(subDir2)); assertTrue("Should contain the file.", files.contains(someFile)); assertTrue("Should contain the directory.", files.contains(subDir3)); subDir1.delete(); }
@Test public void testWildcard() throws Exception { IOFileFilter filter = new WildcardFileFilter("*.txt"); assertFiltering(filter, new File("log.txt"), true); assertFiltering(filter, new File("log.TXT"), false); filter = new WildcardFileFilter("*.txt", IOCase.SENSITIVE); assertFiltering(filter, new File("log.txt"), true); assertFiltering(filter, new File("log.TXT"), false); filter = new WildcardFileFilter("*.txt", IOCase.INSENSITIVE); assertFiltering(filter, new File("log.txt"), true); assertFiltering(filter, new File("log.TXT"), true); filter = new WildcardFileFilter("*.txt", IOCase.SYSTEM); assertFiltering(filter, new File("log.txt"), true); assertFiltering(filter, new File("log.TXT"), WINDOWS); filter = new WildcardFileFilter("*.txt", null); assertFiltering(filter, new File("log.txt"), true); assertFiltering(filter, new File("log.TXT"), false); filter = new WildcardFileFilter(new String[] {"*.java", "*.class"}); assertFiltering(filter, new File("Test.java"), true); assertFiltering(filter, new File("Test.class"), true); assertFiltering(filter, new File("Test.jsp"), false); filter = new WildcardFileFilter(new String[] {"*.java", "*.class"}, IOCase.SENSITIVE); assertFiltering(filter, new File("Test.java"), true); assertFiltering(filter, new File("Test.JAVA"), false);
private void loadJarsFromFolder(List<URL> urls, File folder) { if (!folder.exists()) { return; } FilenameFilter fileFilter = new WildcardFileFilter(JAR_FILE); File[] files = folder.listFiles(fileFilter); for (File jarFile : files) { urls.add(getFileUrl(jarFile)); } }
Map<File, List<URL>> classpathFolders = groupArtifactUrlsByFolder(classpathURLs); FileFilter snapshotFileFilter = new WildcardFileFilter(SNAPSHOT_WILCARD_FILE_FILTER); ListIterator<URL> listIterator = resolvedURLs.listIterator(); while (listIterator.hasNext()) {
@SuppressWarnings("unused") private static void validateFiles() throws Exception { // START SNIPPET: validateFiles FhirContext ctx = FhirContext.forDstu3(); // Create a validator and configure it FhirValidator validator = ctx.newValidator(); validator.setValidateAgainstStandardSchema(true); validator.setValidateAgainstStandardSchematron(true); // Get a list of files in a given directory String[] fileList = new File("/home/some/dir").list(new WildcardFileFilter("*.txt")); for (String nextFile : fileList) { // For each file, load the contents into a string String nextFileContents = IOUtils.toString(new FileReader(nextFile)); // Parse that string (this example assumes JSON encoding) IBaseResource resource = ctx.newJsonParser().parseResource(nextFileContents); // Apply the validation. This will throw an exception on the first // validation failure ValidationResult result = validator.validateWithResult(resource); if (result.isSuccessful() == false) { throw new Exception("We failed!"); } } // END SNIPPET: validateFiles }
public static boolean checkFileExistByPattern(String path, String pattern) { if (path == null) { path = "."; } File dir = new File(path); FileFilter ff = new WildcardFileFilter(pattern); File[] found = dir.listFiles(ff); return found != null && found.length > 0; } }
/** * Compares files with the same name from sourceFolder against it's counterpart in targetFolder, but allows source and * target files to have different extensions. TODO run tests in parallel */ public static void compareFromDifferentFoldersByName(final File sourceFolder, final File targetFolder, final String srcExtension, final String targetExtension, final ResourcePostProcessor processor) throws IOException { compareFromDifferentFolders(sourceFolder, targetFolder, new WildcardFileFilter("*." + srcExtension), Transformers.extensionTransformer("css"), processor); }
public static void compareFromDifferentFoldersByExtension(final File sourceFolder, final File targetFolder, final String extension, final ResourcePreProcessor processor) throws IOException { compareFromDifferentFolders(sourceFolder, targetFolder, new WildcardFileFilter("*." + extension), Transformers.noOpTransformer(), processor); }
/** * TODO run tests in parallel */ public static void compareFromDifferentFoldersByExtension(final File sourceFolder, final File targetFolder, final String extension, final ResourcePostProcessor processor) throws IOException { compareFromDifferentFolders(sourceFolder, targetFolder, new WildcardFileFilter("*." + extension), Transformers.noOpTransformer(), processor); }
new WildcardFileFilter( configHandler.getRunConfiguration().getParameter(Prop.WILDCARD), IOCase.INSENSITIVE);