List of usage examples for org.apache.commons.io FileUtils readLines
public static List readLines(File file) throws IOException
From source file:fr.inria.eventcloud.deployment.cli.launchers.EventCloudsManagementServiceDeployer.java
private static void downloadResources(String resourcesUrl, boolean activateLoggers) throws IOException { resourcesDirPath = System.getProperty("java.io.tmpdir") + File.separator + "eventcloud-resources"; File tmpResourcesDir = new File(resourcesDirPath); tmpResourcesDir.mkdir();//from ww w . j a va2s. c om FileUtils.copyURLToFile(new URL(resourcesUrl + "proactive.security.policy"), new File(tmpResourcesDir, "proactive.security.policy")); if (activateLoggers) { FileUtils.copyURLToFile(new URL(resourcesUrl + "log4j-console.properties"), new File(tmpResourcesDir, "log4j-console.properties")); FileUtils.copyURLToFile(new URL(resourcesUrl + "logback-console.xml"), new File(tmpResourcesDir, "logback-console.xml")); } else { FileUtils.copyURLToFile(new URL(resourcesUrl + "log4j-inactive.properties"), new File(tmpResourcesDir, "log4j-inactive.properties")); FileUtils.copyURLToFile(new URL(resourcesUrl + "logback-inactive.xml"), new File(tmpResourcesDir, "logback-inactive.xml")); } FileUtils.copyURLToFile(new URL(resourcesUrl + "eventcloud.properties"), new File(tmpResourcesDir, "eventcloud.properties")); List<String> eventCloudProperties = FileUtils .readLines(new File(resourcesDirPath + File.separator + "eventcloud.properties")); for (String property : eventCloudProperties) { if (property.startsWith(EventCloudProperties.REPOSITORIES_PATH.getName() + "=")) { repositoriesDirPath = property.substring(property.indexOf('=') + 1); } } }
From source file:com.vecna.maven.jshint.mojo.JsHintMojo.java
/** * {@inheritDoc}//w w w. ja va 2s. com */ @Override public void execute() throws MojoExecutionException, MojoFailureException { if (skip) { getLog().info("skipping execution"); } else { String[] sourceFiles = getSourceFiles(); if (sourceFiles.length == 0) { getLog().info("no source files found"); } else { final InputStream jsHintSrc = openClasspathResource(jsHintJS); JsEngine engine; try { engine = new JsEngine().browserEnv().eval(jsHintSrc); } catch (IOException e) { throw new MojoExecutionException("failed to bootstrap JSHint", e); } NativeObject combinedOpts = readOptionsFromFile(engine); NativeObject combinedGlobals = extractGlobals(combinedOpts); addOptions(combinedOpts); addGlobals(combinedGlobals); Function jsHint = (Function) engine.get("JSHINT"); Multimap<String, JsHintError> errors = HashMultimap.create(); for (String srcFile : sourceFiles) { List<String> source; try { source = FileUtils.readLines(new File(srcDirectory, srcFile)); } catch (IOException e) { throw new MojoExecutionException("failed to read " + srcFile, e); } NativeArray array = new NativeArray(source.toArray()); engine.call(jsHint, array, combinedOpts, combinedGlobals); NativeArray nativeErrors = (NativeArray) engine.get(jsHint, "errors"); for (int i = 0; i < nativeErrors.size(); i++) { NativeObject nativeError = (NativeObject) nativeErrors.get(i); JsHintError error = new JsHintError(srcFile, nativeError); // handling the built-in JsHint error limit if (error.getReason().startsWith("Too many errors")) { break; } getLog().error(error.toString()); errors.put(error.getSource(), error); } } try { writeReport(errors); } catch (IOException e) { throw new MojoExecutionException("failed to write the report", e); } if (errors.size() > maxErrorsAllowed) { throw new MojoFailureException( "JSHint violations: " + errors.size() + ". Allowed violations: " + maxErrorsAllowed); } } } }
From source file:de.tudarmstadt.ukp.dkpro.core.io.ditop.DiTopWriterTest.java
@Test public void testCollectionValuesExactNoMatch() throws UIMAException, IOException { int expectedNDocuments = 0; String[] collectionValues = new String[] { "file:/home/schnober/workspace/de.tudarmstadt.ukp.dkpro.core-asl/de.tudarmstadt.ukp.dkpro.core.io.ditop/src/test/resources/" }; boolean exactMatch = true; CollectionReaderDescription reader = createReaderDescription(TextReader.class, TextReader.PARAM_SOURCE_LOCATION, CAS_DIR, TextReader.PARAM_PATTERNS, CAS_FILE_PATTERN, TextReader.PARAM_LANGUAGE, LANGUAGE); AnalysisEngineDescription segmenter = createEngineDescription(BreakIteratorSegmenter.class); AnalysisEngineDescription inferencer = createEngineDescription(MalletTopicModelInferencer.class, MalletTopicModelInferencer.PARAM_MODEL_LOCATION, MODEL_FILE); AnalysisEngineDescription ditopwriter = createEngineDescription(DiTopWriter.class, DiTopWriter.PARAM_TARGET_LOCATION, TARGET_DITOP, DiTopWriter.PARAM_MODEL_LOCATION, MODEL_FILE, DiTopWriter.PARAM_CORPUS_NAME, DITOP_CORPUSNAME, DiTopWriter.PARAM_COLLECTION_VALUES, collectionValues, DiTopWriter.PARAM_COLLECTION_VALUES_EXACT_MATCH, exactMatch); SimplePipeline.runPipeline(reader, segmenter, inferencer, ditopwriter); /* test whether target files and dirs exist */ File contentDir = new File(TARGET_DITOP, DITOP_CORPUSNAME + "_" + N_TOPICS); File topicsFile = new File(contentDir, "topics.csv"); File topicTermT15File = new File(contentDir, "topicTerm-T15.txt"); File topicTermFile = new File(contentDir, "topicTerm.txt"); File topicTermMatrixFile = new File(contentDir, "topicTermMatrix.txt"); assertTrue(new File(TARGET_DITOP, "config.all").exists()); assertTrue(contentDir.isDirectory()); assertTrue(topicTermT15File.exists()); assertTrue(topicTermFile.exists());/*from w w w. java 2 s . com*/ assertTrue(topicTermMatrixFile.exists()); assertTrue(topicsFile.exists()); /* check that file lengths are correct */ assertEquals(expectedNDocuments + 1, FileUtils.readLines(topicsFile).size()); assertEquals(N_TOPICS, FileUtils.readLines(topicTermT15File).size()); assertEquals(N_TOPICS, FileUtils.readLines(topicTermFile).size()); assertEquals(N_TOPICS, FileUtils.readLines(topicTermMatrixFile).size()); }