List of usage examples for org.apache.commons.io FileUtils iterateFiles
public static Iterator iterateFiles(File directory, String[] extensions, boolean recursive)
From source file:com.puffywhiteshare.PWSApp.java
/** * @param args// w ww. j a va 2 s. co m * @throws IOException */ public static void main(String[] args) throws IOException { CloudBucket cloud = new CloudBucket(); logger.info("Test my output bitches"); Yaml y = new Yaml(); File f = new File("Playing.yml"); FileInputStream fis = new FileInputStream(f); Map m = (Map) y.load(fis); Long startFiles = System.currentTimeMillis(); Iterator<File> fileIterator = FileUtils.iterateFiles(new File("/Users/chad/Pictures/."), null, true); do { File file = fileIterator.next(); cloud.add(file); } while (fileIterator.hasNext()); Long endFiles = System.currentTimeMillis(); System.out.println("Files processing took " + ((endFiles - startFiles))); Long startSer = System.currentTimeMillis(); String filename = "cloud.ser"; FileOutputStream fos = null; ObjectOutputStream out = null; try { fos = new FileOutputStream(filename); out = new ObjectOutputStream(fos); out.writeObject(cloud); out.close(); } catch (IOException ex) { ex.printStackTrace(); } Long endSer = System.currentTimeMillis(); System.out.println("Files processing took " + ((endSer - startSer))); logger.info(" Size = " + FileUtils.byteCountToDisplaySize(cloud.getSize())); logger.info("Count = " + cloud.getCount()); /* Set<String> buckets = m.keySet(); System.out.println(m.toString()); for(String bucket : buckets) { logger.info("Bucket = " + bucket); logger.info("Folders = " + m.get(bucket)); List<Object> folders = (List<Object>) m.get(bucket); for(Object folder : folders) { if(folder instanceof String) { logger.info("Folder Root = " + folder); } else if(folder instanceof Map) { logger.info("Folder Map = " + folder); } } BlockingQueue<File> fileFeed = new ArrayBlockingQueue<File>(10); Map folderMap = (Map) m.get(bucket); Set<String> folders = folderMap.entrySet(); for(String folder : folders) { logger.info("Folder = " + folder); } } */ }
From source file:be.redlab.maven.yamlprops.create.YamlConvertCli.java
public static void main(String... args) throws IOException { CommandLineParser parser = new DefaultParser(); Options options = new Options(); HelpFormatter formatter = new HelpFormatter(); options.addOption(Option.builder("s").argName("source").desc("the source folder or file to convert") .longOpt("source").hasArg(true).build()); options.addOption(Option.builder("t").argName("target").desc("the target file to store in") .longOpt("target").hasArg(true).build()); options.addOption(Option.builder("h").desc("print help").build()); try {/*from ww w .j ava 2 s . c o m*/ CommandLine cmd = parser.parse(options, args); if (cmd.hasOption('h')) { formatter.printHelp("converter", options); } File source = new File(cmd.getOptionValue("s", System.getProperty("user.dir"))); String name = source.getName(); if (source.isDirectory()) { PropertiesToYamlConverter yamlConverter = new PropertiesToYamlConverter(); String[] ext = { "properties" }; Iterator<File> fileIterator = FileUtils.iterateFiles(source, ext, true); while (fileIterator.hasNext()) { File next = fileIterator.next(); System.out.println(next); String s = StringUtils.removeStart(next.getParentFile().getPath(), source.getPath()); System.out.println(s); String f = StringUtils.split(s, IOUtils.DIR_SEPARATOR)[0]; System.out.println("key = " + f); Properties p = new Properties(); try { p.load(new FileReader(next)); yamlConverter.addProperties(f, p); } catch (IOException e) { e.printStackTrace(); } } FileWriter fileWriter = new FileWriter( new File(source.getParentFile(), StringUtils.substringBeforeLast(name, ".") + ".yaml")); yamlConverter.writeYaml(fileWriter); fileWriter.close(); } else { Properties p = new Properties(); p.load(new FileReader(source)); FileWriter fileWriter = new FileWriter( new File(source.getParentFile(), StringUtils.substringBeforeLast(name, ".") + ".yaml")); new PropertiesToYamlConverter().addProperties(name, p).writeYaml(fileWriter); fileWriter.close(); } } catch (ParseException e) { e.printStackTrace(); formatter.printHelp("converter", options); } }
From source file:id3Crawler.java
public static void main(String[] args) throws IOException { //Input for the directory to be searched. System.out.println("Please enter a directory: "); Scanner scanner = new Scanner(System.in); String input = scanner.nextLine(); //Start a timer to calculate runtime startTime = System.currentTimeMillis(); System.out.println("Starting scan..."); //Files for output PrintWriter pw1 = new PrintWriter(new FileWriter("C:/Users/gbob3_000/Desktop/id3CrawlerOutput/Song.txt")); PrintWriter pw2 = new PrintWriter(new FileWriter("C:/Users/gbob3_000/Desktop/id3CrawlerOutput/Artist.txt")); PrintWriter pw3 = new PrintWriter(new FileWriter("C:/Users/gbob3_000/Desktop/id3CrawlerOutput/Album.txt")); PrintWriter pw4 = new PrintWriter( new FileWriter("C:/Users/gbob3_000/Desktop/id3CrawlerOutput/PerformedBy.txt")); PrintWriter pw5 = new PrintWriter( new FileWriter("C:/Users/gbob3_000/Desktop/id3CrawlerOutput/TrackOf.txt")); PrintWriter pw6 = new PrintWriter( new FileWriter("C:/Users/gbob3_000/Desktop/id3CrawlerOutput/CreatedBy.txt")); //This is used for creating IDs for artists, songs, albums. int idCounter = 0; //This is used to prevent duplicate artists String previousArtist = " "; String currentArtist;/*from ww w.j a v a2 s . c om*/ int artistID = 0; //This is used to prevent duplicate albums String previousAlbum = " "; String currentAlbum; int albumID = 0; //This array holds valid extensions to iterate through String[] extensions = new String[] { "mp3" }; //iterate through all files in a directory Iterator<File> it = FileUtils.iterateFiles(new File(input), extensions, true); while (it.hasNext()) { //open the next file File file = it.next(); //instantiate an mp3file object with the opened file MP3 song = GetMP3(file); //pass the song through SongInfo and return the required information SongInfo info = new SongInfo(song); //This is used to prevent duplicate artists/albums currentArtist = info.getArtistInfo(); currentAlbum = info.getAlbumInfo(); //Append the song information to the end of a text file pw1.println(idCounter + "\t" + info.getTitleInfo()); //This prevents duplicates of artists if (!(currentArtist.equals(previousArtist))) { pw2.println(idCounter + "\t" + info.getArtistInfo()); previousArtist = currentArtist; artistID = idCounter; } //This prevents duplicates of albums if (!(currentAlbum.equals(previousAlbum))) { pw3.println(idCounter + "\t" + info.getAlbumInfo()); previousAlbum = currentAlbum; albumID = idCounter; //This formats the IDs for a "CreatedBy" relationship table pw6.println(artistID + "\t" + albumID); } //This formats the IDs for a "PerformedBy" relationship table pw4.println(idCounter + "\t" + artistID); //This formats the IDs for a "TrackOf" relationship table pw5.println(idCounter + "\t" + albumID); idCounter++; songCounter++; } scanner.close(); pw1.close(); pw2.close(); pw3.close(); pw4.close(); pw5.close(); pw6.close(); System.out.println("Scan took " + ((System.currentTimeMillis() - startTime) / 1000.0) + " seconds to scan " + songCounter + " items!"); }
From source file:com.github.xbn.examples.testdev.ReplaceAllIndentTabsWithSpacesXmpl.java
public static final void main(String[] directoryRoot_paramIdxZero) { //Setup and protection String dirRoot = GetFromCommandLineAtIndex.text(directoryRoot_paramIdxZero, 0, "directoryRoot_paramIdxZero", null);/*from w ww.j a v a 2s . c om*/ System.out.println("This example code will overwrite the files in \"" + dirRoot + "\". Enter the number 1234567890 to proceed."); if (!new Scanner(System.in).nextLine().equals("1234567890")) { System.out.println("Abort."); return; } Path dirPath = new PathMustBe().existing().writable().directory().noFollowLinks().getOrCrashIfBad(dirRoot, "directoryRoot_paramIdxZero[0]"); File fileRootDir = new File(dirRoot); //Go IOFileFilter allFileTypesKeepFilter = FileFilterUtils.and(FileFilterUtils.suffixFileFilter(".java"), FileFilterUtils.suffixFileFilter(".html")); Iterator<File> fileItr = FileUtils.iterateFiles(fileRootDir, allFileTypesKeepFilter, null); new ReplaceAllIndentTabsWithSpaces(3, System.out, TabToSpaceDebugLevel.FILE_SUMMARIES) .overwriteDirectory(fileItr); }
From source file:edu.gslis.ts.ChunkToFile.java
public static void main(String[] args) { try {//from w ww.ja va2s.c o m // Get the commandline options Options options = createOptions(); CommandLineParser parser = new GnuParser(); CommandLine cmd = parser.parse(options, args); String inputPath = cmd.getOptionValue("input"); String indexPath = cmd.getOptionValue("index"); String eventsPath = cmd.getOptionValue("events"); String stopPath = cmd.getOptionValue("stop"); String outputPath = cmd.getOptionValue("output"); IndexWrapper index = IndexWrapperFactory.getIndexWrapper(indexPath); Stopper stopper = new Stopper(stopPath); Map<Integer, FeatureVector> queries = readEvents(eventsPath, stopper); // Setup the filter ChunkToFile f = new ChunkToFile(); if (inputPath != null) { File infile = new File(inputPath); if (infile.isDirectory()) { Iterator<File> files = FileUtils.iterateFiles(infile, null, true); while (files.hasNext()) { File file = files.next(); System.err.println(file.getAbsolutePath()); f.filter(file, queries, index, stopper, outputPath); } } else System.err.println(infile.getAbsolutePath()); f.filter(infile, queries, index, stopper, outputPath); } } catch (Exception e) { e.printStackTrace(); } }
From source file:btrplace.fromEntropy.Converter.java
public static void main(String[] args) { String src, dst = null, output, scriptDC = null, dirScriptsCL = null; if (args.length < 5 || args.length > 6 || !args[args.length - 2].equals("-o")) { usage(1);//from w w w . j a v a2 s . c om } src = args[0]; output = args[args.length - 1]; if (args.length > 5) { dst = args[1]; } scriptDC = args[args.length - 4]; dirScriptsCL = args[args.length - 3]; OutputStreamWriter out = null; try { // Convert the src file ConfigurationConverter conv = new ConfigurationConverter(src); Instance i = conv.getInstance(); // Read the dst file, deduce and add the states constraints if (dst != null) { i.getSatConstraints().addAll(conv.getNextStates(dst)); } // Read the script files ScriptBuilder scriptBuilder = new ScriptBuilder(i.getModel()); //scriptBuilder.setIncludes(new PathBasedIncludes(scriptBuilder, // new File("src/test/resources"))); // Read the datacenter script file if exists if (scriptDC != null) { String strScriptDC = null; try { strScriptDC = readFile(scriptDC); } catch (IOException e) { e.printStackTrace(); } Script scrDC = null; try { // Build the DC script scrDC = scriptBuilder.build(strScriptDC); } catch (ScriptBuilderException sbe) { System.out.println(sbe); } // Set the DC script as an include BasicIncludes bi = new BasicIncludes(); bi.add(scrDC); scriptBuilder.setIncludes(bi); } // Read all the client script files String scriptCL = null, strScriptCL = null; Script scrCL = null; Iterator it = FileUtils.iterateFiles(new File(dirScriptsCL), null, false); while (it.hasNext()) { scriptCL = dirScriptsCL + "/" + ((File) it.next()).getName(); if (scriptCL != null) { // Read try { strScriptCL = readFile(scriptCL); } catch (IOException e) { e.printStackTrace(); } // Parse try { scrCL = scriptBuilder.build(strScriptCL); } catch (ScriptBuilderException sbe) { System.out.println(sbe); sbe.printStackTrace(); } // Add the resulting constraints if (scrCL.getConstraints() != null) { i.getSatConstraints().addAll(scrCL.getConstraints()); } } } /************** PATCH **************/ // State constraints; for (Node n : i.getModel().getMapping().getOnlineNodes()) { i.getSatConstraints().add(new Online(n)); } for (Node n : i.getModel().getMapping().getOfflineNodes()) { i.getSatConstraints().add(new Offline(n)); } // Remove preserve constraints for (Iterator<SatConstraint> ite = i.getSatConstraints().iterator(); ite.hasNext();) { SatConstraint s = ite.next(); if (s instanceof Preserve && src.contains("nr")) { ite.remove(); } } /************************************/ // Convert to JSON InstanceConverter iConv = new InstanceConverter(); JSONObject o = iConv.toJSON(i); // Check for gzip extension if (output.endsWith(".gz")) { out = new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(output))); } else { out = new FileWriter(output); } // Write the output file o.writeJSONString(out); out.close(); } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); System.exit(1); } finally { if (out != null) { try { out.close(); } catch (IOException e) { System.err.println(e.getMessage()); System.exit(1); } } } }
From source file:com.compomics.pladipus.core.control.util.JarLookupService.java
/** * This method looks for the appropriate jar in the given folder (excludes the lib folder) * @param regex the regex to match the file * @param searchRoot the root directory to start te search * @return a file matching the regex/* w ww . java2s. c om*/ * @throws UnspecifiedPladipusException */ public static File lookupFile(String regex, File searchRoot) throws UnspecifiedPladipusException { if (!searchRoot.isDirectory()) { throw new IllegalArgumentException(searchRoot + " is no directory."); } final Pattern p = Pattern.compile(regex); Iterator iterateFiles = FileUtils.iterateFiles(searchRoot, new String[] { "jar" }, true); List<File> matchingFiles = new ArrayList<>(); while (iterateFiles.hasNext()) { File file = (File) iterateFiles.next(); if (p.matcher(file.getName()).matches() & !file.getParent().equalsIgnoreCase("lib")) { matchingFiles.add(file); } } if (matchingFiles.size() > 1) { throw new UnspecifiedPladipusException("There are multiple file candidates (" + matchingFiles.size() + "), please ensure only a single version is present and try again"); } else if (matchingFiles.isEmpty()) { throw new UnspecifiedPladipusException("There are no matching files present"); } return matchingFiles.get(0); }
From source file:com.chingo247.structureapi.plan.PlanGenerator.java
public static void generate(File directory) { Iterator<File> fileIterator = FileUtils.iterateFiles(directory, new String[] { "schematic" }, true); while (fileIterator.hasNext()) { File schemaFile = fileIterator.next(); try {/*from w ww . j a v a 2 s. co m*/ generatePlanFromSchematic(schemaFile, directory); } catch (IOException ex) { Logger.getLogger(PlanGenerator.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:gov.nih.nci.caarray.external.v1_0.AbstractCaArrayEntityTest.java
public static <T> List<Class<? extends T>> findLocalSubclasses(Class<T> c) throws ClassNotFoundException, URISyntaxException { List<Class<? extends T>> l = new ArrayList<Class<? extends T>>(); File dir = new File(c.getProtectionDomain().getCodeSource().getLocation().toURI()); Iterator<File> fi = FileUtils.iterateFiles(dir, new String[] { "class" }, true); int prefix = dir.getAbsolutePath().length() + 1; int suffix = ".class".length(); while (fi.hasNext()) { File cf = fi.next();// w w w .ja v a2s.c o m String fn = cf.getAbsolutePath(); try { String cn = fn.substring(prefix, fn.length() - suffix); if (cn.endsWith("<error>")) { continue; } cn = cn.replace('/', '.'); System.out.println("cn = " + cn); Class tmp = c.getClassLoader().loadClass(cn); if ((tmp.getModifiers() & Modifier.ABSTRACT) != 0) { continue; } if (c.isAssignableFrom(tmp)) { l.add(tmp); System.out.println("added " + cf.getAbsolutePath() + " as " + cn); } } catch (Exception e) { System.err.println(fn); e.printStackTrace(); } } return l; }
From source file:cn.cuizuoli.gotour.utils.ThumbnailGenerator.java
public void generate() throws IOException { Iterator<File> iterator = FileUtils.iterateFiles(new File(ORIGINAL_PATH), new String[] { "jpg" }, false); while (iterator.hasNext()) { File file = iterator.next(); Thumbnails.of(file).forceSize(225, 100).toFile(new File(THUMBNAIL_PATH + file.getName())); }/*from w w w. j a v a 2s. co m*/ }