List of usage examples for java.io FilenameFilter FilenameFilter
FilenameFilter
From source file:com.netflix.ice.common.AwsUtils.java
public static void upload(String bucketName, String prefix, String localDir, final String filePrefix) { File dir = new File(localDir); File[] files = dir.listFiles(new FilenameFilter() { public boolean accept(File file, String fileName) { return fileName.startsWith(filePrefix); }/*from ww w . ja v a2 s. co m*/ }); for (File file : files) s3Client.putObject(bucketName, prefix + file.getName(), file); }
From source file:com.couchbase.lite.Manager.java
/** * An array of the names of all existing databases. *//*from w w w . j a v a 2 s .c o m*/ @InterfaceAudience.Public public List<String> getAllDatabaseNames() { String[] databaseFiles = directoryFile.list(new FilenameFilter() { @Override public boolean accept(File dir, String filename) { if (filename.endsWith(Manager.kDBExtension)) { return true; } return false; } }); List<String> result = new ArrayList<String>(); for (String databaseFile : databaseFiles) { String trimmed = databaseFile.substring(0, databaseFile.length() - Manager.kDBExtension.length()); String replaced = trimmed.replace(':', '/'); result.add(replaced); } Collections.sort(result); return Collections.unmodifiableList(result); }
From source file:com.appeligo.ccdataindexer.Indexer.java
public int indexChannel(File channel) throws IOException { log.info("indexing channel " + channel.getName()); boolean needToClose = openIndex(); int count = 0; try {// ww w .j a v a2 s. c o m String channelNumber = channel.getName(); String callSign = channelNumberToCallSign.get(channelNumber); if (callSign == null) { callSign = channelNumber; //log.error("Unable to indentify callsign for channel " + channelNumber); //return 0; } Network network = networks.get(callSign); if (network == null) { log.error("Unable to indentify network for callsign " + callSign); return 0; } File[] programFiles = channel.listFiles(new FilenameFilter() { public boolean accept(File dir, String name) { if (name.endsWith(".gz") || name.endsWith(".zip")) { return true; } else { return false; } } }); if (programFiles != null) { for (File program : programFiles) { try { if (afterDate == null || program.lastModified() > afterDate.getTime()) { if (indexProgram(program, network)) { count++; } } } catch (Exception e) { log.error("Exception on Program File " + program.getAbsolutePath() + "\n" + e.getMessage() + "\n" + e.getStackTrace().toString(), e); } } } log.info("processed " + count + " programs for channel :" + channelNumber); } finally { if (needToClose) { closeIndex(); } } return count; }
From source file:org.biopax.validator.Main.java
public static Collection<Resource> getResourcesToValidate(String input) throws IOException { Set<Resource> setRes = new HashSet<Resource>(); File fileOrDir = new File(input); if (fileOrDir.isDirectory()) { // validate all the OWL files in the folder FilenameFilter filter = new FilenameFilter() { public boolean accept(File dir, String name) { return (name.endsWith(".owl")); }// w w w.jav a2 s . c o m }; for (String s : fileOrDir.list(filter)) { String uri = "file:" + fileOrDir.getCanonicalPath() + File.separator + s; setRes.add(ctx.getResource(uri)); } } else if (input.startsWith("list:")) { // consider it's a file that contains a list of (pseudo-)URLs String batchFile = input.replaceFirst("list:", "file:"); Reader isr = new InputStreamReader(ctx.getResource(batchFile).getInputStream()); BufferedReader reader = new BufferedReader(isr); String line; while ((line = reader.readLine()) != null && !"".equals(line.trim())) { // check the source URL if (!ResourceUtils.isUrl(line)) { log.error("Invalid URL: " + line + ". A resource must be either a " + "pseudo URL (classpath: or file:) or standard URL!"); continue; } setRes.add(ctx.getResource(line)); } reader.close(); } else { // a single local OWL file or remote data Resource resource = null; if (!ResourceUtils.isUrl(input)) input = "file:" + input; resource = ctx.getResource(input); setRes.add(resource); } return setRes; }
From source file:com.btoddb.chronicle.FileTestUtils.java
public Matcher<? super File> countWithSuffix(final String suffix, final int count) { return new TypeSafeMatcher<File>() { int got;/* w w w. j a v a 2 s. c o m*/ @Override protected boolean matchesSafely(final File dir) { String[] files = dir.list(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.endsWith(suffix); } }); got = files.length; return got == count; } @Override public void describeTo(final Description description) { description.appendValue(count); } @Override protected void describeMismatchSafely(final File item, final Description mismatchDescription) { mismatchDescription.appendText(" was: ").appendValue(got); } }; }
From source file:com.linkedin.pinot.core.segment.index.converter.SegmentV1V2ToV3FormatConverter.java
private void deleteStaleConversionDirectories(File segmentDirectory) { final String prefix = segmentDirectory.getName() + V3_TEMP_DIR_SUFFIX; File[] files = segmentDirectory.listFiles(new FilenameFilter() { @Override// www. ja v a 2 s . c o m public boolean accept(File dir, String name) { return name.startsWith(prefix); } }); for (File file : files) { LOGGER.info("Deleting stale v3 directory: {}", file); FileUtils.deleteQuietly(file); } }
From source file:com.netflix.suro.sink.remotefile.TestS3FileSink.java
private File[] getFiles(String testDir) { // check no file uploaded, deleted, and notified File dir = new File(testDir); return dir.listFiles(new FilenameFilter() { @Override/*w ww .j av a2 s . c o m*/ public boolean accept(File file, String name) { if (!name.startsWith(".")) { return true; } else { return false; } } }); }
From source file:uk.ac.susx.tag.method51.webapp.handler.CodingInstanceHandler.java
private void list(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException { File f = new File(modelsFolder); List<String> names = new ArrayList<>(Arrays.asList(f.list(new FilenameFilter() { public boolean accept(File dir, String name) { return name.endsWith(Coder.SAMPLE_SUFFIX); }/*w w w .ja v a2 s. com*/ }))); for (int i = 0; i < names.size(); ++i) { names.set(i, names.get(i).replace(Coder.SAMPLE_SUFFIX, "")); } Collections.sort(names); okHereIsYourJson("models", names, response); }
From source file:com.clican.pluto.orm.dynamic.impl.DynamicORMManagePojoHibernateImpl.java
public void updateORM(ModelDescription oldOne, ModelDescription newOne) throws ORMManageException { modelContainer.update(oldOne, newOne); VelocityContext velocityContext = new VelocityContext(); if (!oldOne.getName().equals(newOne.getName())) { final ModelDescription md = oldOne; File filePath = new File(tempORMCfgPojoFolder + "/" + Constants.DYNAMIC_MODEL_PACKAGE_PATH); File[] files = filePath.listFiles(new FilenameFilter() { public boolean accept(File dir, String name) { return name.contains(md.getFirstCharUpperName()); }//from w ww . j a v a 2 s. c om }); for (File f : files) { f.delete(); } List<ModelDescription> modelDescriptionList = new ArrayList<ModelDescription>( modelContainer.getModelDescs()); velocityContext.put(modelDescListTempName, modelDescriptionList); generate(filePath.getAbsolutePath() + "/Directory.java", directoryTemplate, velocityContext); generate(filePath.getAbsolutePath() + "/Template.java", templateTemplate, velocityContext); } velocityContext.put(modelDescTempName, newOne); File filePath = new File(tempORMCfgPojoFolder + "/" + Constants.DYNAMIC_MODEL_PACKAGE_PATH); generate(filePath.getAbsolutePath() + "/" + newOne.getFirstCharUpperName() + ".java", modelTemplate, velocityContext); compile(filePath.getAbsolutePath()); try { dynamicClassLoader.refreshClasses(); } catch (ClassNotFoundException e) { throw new ORMManageException(e); } }
From source file:de.extra.client.starter.ExtraClient.java
private void readPropertiesFromDirectory(final File propertiesDirectory, final Properties properties) throws FileNotFoundException, IOException { checkDirectory(propertiesDirectory); final String[] propertyFiles = propertiesDirectory.list(new FilenameFilter() { @Override/*from w ww .j a v a 2 s .c o m*/ public boolean accept(final File dir, final String name) { return name != null && name.endsWith(".properties"); } }); // merge all found properties for (final String propertyFile : propertyFiles) { readPropertiesFromFile(properties, new File(propertiesDirectory, propertyFile)); } }