List of usage examples for org.apache.commons.io FileUtils listFiles
public static Collection listFiles(File directory, String[] extensions, boolean recursive)
From source file:com.hurence.logisland.processor.CsvLoaderTest.java
@Test public void CsvLoaderTest() throws IOException { File f = new File(RESOURCES_DIRECTORY); for (File file : FileUtils.listFiles(f, new SuffixFileFilter(".csv"), TrueFileFilter.INSTANCE)) { BufferedReader reader = Files.newBufferedReader(file.toPath(), ENCODING); List<Record> records = TimeSeriesCsvLoader.load(reader, true, inputDateFormat); Assert.assertTrue(!records.isEmpty()); //Assert.assertTrue("should be 4032, was : " + events.size(), events.size() == 4032); for (Record record : records) { Assert.assertTrue("should be sensors, was " + record.getType(), record.getType().equals("sensors")); Assert.assertTrue("should be 5, was " + record.getFieldsEntrySet().size(), record.getFieldsEntrySet().size() == 5); Assert.assertTrue(record.getAllFieldNames().contains("timestamp")); if (!record.getAllFieldNames().contains("value")) System.out.println("stop"); Assert.assertTrue(record.getAllFieldNames().contains("value")); Assert.assertTrue(record.getField("timestamp").getRawValue() instanceof Long); Assert.assertTrue(record.getField("value").getRawValue() instanceof Double); }/*from www . ja va2 s . co m*/ } }
From source file:com.sleepcamel.ifdtoutils.MvnPluginMojo.java
@SuppressWarnings("deprecation") public void execute() throws MojoExecutionException { try {/*w w w.j a v a 2 s . c o m*/ if (outputDirectory == null || !outputDirectory.exists()) { throw new MojoExecutionException("Class directory must exist"); } URLClassLoader urlClassLoader = new URLClassLoader(new URL[] { outputDirectory.toURL() }, getClass().getClassLoader()); Thread.currentThread().setContextClassLoader(urlClassLoader); Collection<File> listFiles = FileUtils.listFiles(outputDirectory, new String[] { "class" }, true); for (File file : listFiles) { getLog().debug("\nClass found: " + file.getName()); try { Class<?> loadedClass = urlClassLoader.loadClass(fileToClass(outputDirectory, file)); getLog().debug("Class " + loadedClass.getName() + " loaded"); if (!loadedClass.isInterface()) { getLog().debug("Not an interface :("); continue; } ToDTO annotation = loadedClass.getAnnotation(ToDTO.class); if (annotation == null) { getLog().debug("No annotation not found :("); } else { dtosToGenerate.add(loadedClass); getLog().debug("Annotation found!"); } } catch (ClassNotFoundException e) { } } getLog().info("Found " + dtosToGenerate.size() + " interfaces to generate their DTOs...\n"); for (Class<?> interfaceClass : dtosToGenerate) { String interfaceClassName = interfaceClass.getName(); try { Thread.currentThread().getContextClassLoader() .loadClass(InterfaceDTOInfo.getInfo(interfaceClass).getDTOCanonicalName()); getLog().info("DTO for interface " + interfaceClassName + " exists, skipping generation\n"); } catch (ClassNotFoundException e) { getLog().info("Generating dto for interface " + interfaceClassName + "..."); DTOClassGenerator.generateDTOForInterface(interfaceClass, outputDirectory.getAbsolutePath()); getLog().info("DTO generated for interface " + interfaceClassName + "\n"); } } } catch (Exception e1) { throw new MojoExecutionException(e1.getMessage()); } }
From source file:de.tudarmstadt.ukp.experiments.dip.wp1.documents.Step12GolDataExporter.java
/** * Exporting final data/*from www . java 2 s . c om*/ * * @param inputDir input directory with xml files * @param outputDir output directory * @throws Exception exception */ public static void exportGoldDataSimple(File inputDir, File outputDir) throws Exception { // iterate over query containers for (File f : FileUtils.listFiles(inputDir, new String[] { "xml" }, false)) { QueryResultContainer queryResultContainer = QueryResultContainer .fromXML(FileUtils.readFileToString(f, "utf-8")); SimpleSingleQueryResultContainer outputContainer = new SimpleSingleQueryResultContainer(); outputContainer.query = queryResultContainer.query; outputContainer.queryID = queryResultContainer.qID; for (QueryResultContainer.SingleRankedResult rankedResult : queryResultContainer.rankedResults) { if (rankedResult.plainText != null && !rankedResult.plainText.isEmpty()) { // first, get all the sentence IDs byte[] bytes = new BASE64Decoder() .decodeBuffer(new ByteArrayInputStream(rankedResult.originalXmi.getBytes())); JCas jCas = JCasFactory.createJCas(); XmiCasDeserializer.deserialize(new ByteArrayInputStream(bytes), jCas.getCas()); // for each sentence, we'll collect all its annotations TreeMap<Integer, Sentence> sentencesAndRelevanceAnnotations = collectSentenceIDs(jCas); // prepare output container SimpleSingleDocumentQueryResultContainer singleOutputDocument = new SimpleSingleDocumentQueryResultContainer(); singleOutputDocument.clueWebID = rankedResult.clueWebID; if (rankedResult.goldEstimatedLabels != null && !rankedResult.goldEstimatedLabels.isEmpty()) { for (QueryResultContainer.SingleSentenceRelevanceVote sentenceRelevanceVote : rankedResult.goldEstimatedLabels) { String sentenceIDString = sentenceRelevanceVote.sentenceID; Integer sentenceIDInt = Integer.valueOf(sentenceIDString); String value = sentenceRelevanceVote.relevant; Sentence sentence = sentencesAndRelevanceAnnotations.get(sentenceIDInt); ExportedSentence s = new ExportedSentence(); s.content = sentence.getCoveredText(); s.relevant = Boolean.valueOf(value); // add to the list singleOutputDocument.sentences.add(s); } outputContainer.documents.add(singleOutputDocument); } // save String xml = toXML(outputContainer); File outputFile = new File(outputDir, outputContainer.queryID + ".xml"); FileUtils.writeStringToFile(outputFile, xml, "utf-8"); } } } }
From source file:com.mohawk.webcrawler.lang.verb.GetPdf_Verb.java
@Override public Object run(ScriptContext pageContext, Object... params) throws Exception { String dataDirectory = System.getenv("OPENSHIFT_DATA_DIR"); String cacheDirectory = null; if (dataDirectory != null) cacheDirectory = dataDirectory + "webcrawler/cache"; else//from ww w. j av a 2 s . c om cacheDirectory = "C:\\Users\\cnguyen\\Projects\\ProjectMohawk\\Scripts\\cache"; Object param = LangCore.resolveParameter(pageContext, params[0]); Document doc = null; Config config = pageContext.getConfig(); if (config.getCacheDirectory() != null) { // pull the HTML from cache String prefix = null; //config.getProviderId() + "_"; Collection<File> files = FileUtils.listFiles(new File(cacheDirectory), null, false); for (File file : files) { String filename = file.getName(); if (file.getName().startsWith(prefix) && filename.endsWith(".html")) { doc = (Document) Jsoup.parse(file, "UTF-8"); break; } } if (doc == null) throw new Exception("Unable to find cached file for script>> " + config.getScriptFilename()); } else { // get it from the web System.out.println("URL>> " + param); } // clear out any other contexts pageContext.setTableContext(null); pageContext.setDocument(doc); pageContext.setDocumentHtml(doc.html()); pageContext.setCursorPosition(0); return null; }
From source file:de.uni.bremen.monty.moco.CompileFilesBaseTest.java
protected static Collection<File> getFiles4Filter(String folderPath, String[] filter) throws URISyntaxException { Class aClass = CompileTestProgramsTest.class; ClassLoader classLoader = aClass.getClassLoader(); File testprogramFolder = new File(classLoader.getResource(folderPath).toURI()); return FileUtils.listFiles(testprogramFolder, filter, true); }
From source file:com.offbynull.coroutines.mavenplugin.AbstractInstrumentMojo.java
/** * Instruments all classes in a path recursively. * @param log maven logger/* w w w . j a va 2s.c om*/ * @param instrumenter coroutine instrumenter * @param path directory containing files to instrument * @throws MojoExecutionException if any exception occurs */ protected final void instrumentPath(Log log, Instrumenter instrumenter, File path) throws MojoExecutionException { try { for (File classFile : FileUtils.listFiles(path, new String[] { "class" }, true)) { log.info("Instrumenting " + classFile); byte[] input = FileUtils.readFileToByteArray(classFile); byte[] output = instrumenter.instrument(input); log.debug("File size changed from " + input.length + " to " + output.length); FileUtils.writeByteArrayToFile(classFile, output); } } catch (Exception ex) { throw new MojoExecutionException("Unable to get compile classpath elements", ex); } }
From source file:lineage2.commons.data.xml.AbstractDirParser.java
/** * Method parse./*from w ww . j av a 2s . c o m*/ */ @Override protected final void parse() { File dir = getXMLDir(); if (!dir.exists()) { warn("Dir " + dir.getAbsolutePath() + " not exists"); return; } File dtd = new File(dir, getDTDFileName()); if (!dtd.exists()) { info("DTD file: " + dtd.getName() + " not exists."); return; } initDTD(dtd); try { Collection<File> files = FileUtils.listFiles(dir, FileFilterUtils.suffixFileFilter(".xml"), FileFilterUtils.directoryFileFilter()); for (File f : files) { if (!f.isHidden()) { if (!isIgnored(f)) { try { parseDocument(new FileInputStream(f), f.getName()); } catch (Exception e) { info("Exception: " + e + " in file: " + f.getName(), e); } } } } } catch (Exception e) { warn("Exception: " + e, e); } }
From source file:cc.kave.commons.utils.exec.ReadAllContextsRunner.java
private List<File> findAllZips(String dir) { List<File> zips = Lists.newLinkedList(); for (File f : FileUtils.listFiles(new File(dir), new String[] { "zip" }, true)) { zips.add(f);/*from ww w .java 2s .c o m*/ } return zips; }
From source file:fr.dutra.tools.maven.deptree.extras.JQueryJSTreeRenderer.java
@Override protected Collection<File> getFilesToCopy() { return FileUtils.listFiles(staticDir, FileFilterUtils.or(new PathContainsFilter("jstree"), new PathContainsFilter("common")), TrueFileFilter.TRUE);//from w ww.ja va2 s. com }
From source file:com.redhat.victims.VictimsScanner.java
/** * //from w w w . j a v a2s .co m * Iteratively finds all jar files in a given directory and scans them, * producing {@link VictimsRecord}. The string values of the resulting * records will be written to the specified output stream. * * @param dir * @param os * @throws IOException */ private static void scanDir(File dir, VictimsOutputStream vos) throws IOException { Collection<File> files = FileUtils.listFiles(dir, new RegexFileFilter("^(.*?)\\.jar"), DirectoryFileFilter.DIRECTORY); Iterator<File> fi = files.iterator(); while (fi.hasNext()) { scanFile(fi.next(), vos); } }