List of usage examples for org.apache.commons.io IOUtils readLines
public static List readLines(InputStream input, String encoding) throws IOException
InputStream
as a list of Strings, one entry per line, using the specified character encoding. From source file:de.tudarmstadt.ukp.dkpro.keyphrases.core.evaluator.util.EvaluatorUtils.java
/** * Get the gold keyphrases from the file system. * By convention gold keyphrase files should have the same name as the document file. * Standard extension is .key, but something else can be specified in the corresponding parameter. * * @param metaData The DocumentMetaData annotation of this document. * @param goldSuffix The suffix of the gold standard file. * @param toLowerCase If gold keys should be lowercased or not. * * @return The set of gold keyphrases for this document. * @throws AnalysisEngineProcessException an analysis engine process exception *///www . ja v a 2s . c om public static Set<String> getGoldKeyphrases(DocumentMetaData metaData, String goldSuffix, boolean toLowerCase) throws AnalysisEngineProcessException { Set<String> goldKeyphrases = new TreeSet<String>(); String uri = metaData.getDocumentUri(); URL keyUrl; try { keyUrl = URI.create(uri.substring(0, indexOfExtension(uri)) + goldSuffix).toURL(); List<String> lines = IOUtils.readLines(keyUrl.openStream(), "UTF-8"); for (String line : lines) { if (toLowerCase) { line = line.toLowerCase().trim(); } else { line = line.trim(); } if (line.length() > 0) { if (line.contains(";")) { for (String part : line.split(";")) { goldKeyphrases.add(part.trim()); } } else { goldKeyphrases.add(line); } } } return goldKeyphrases; } catch (IOException e) { throw new AnalysisEngineProcessException(e); } }
From source file:com.prodyna.devcon.backend.ChuckNorrisFactController.java
/** * Load facts about Chuck Norris from a file into memory. * //from ww w . j a v a 2 s . co m * @throws IOException * is thrown if the Chuck Norris facts could not be loaded. */ @PostConstruct public void loadChuckNorrisFacts() throws IOException { InputStream in = getClass().getClassLoader().getResource(CHUCK_NORRIS_FACTS_FILE_NAME).openStream(); chuckNorrisFacts = IOUtils.readLines(in, "UTF-8"); }
From source file:de.blizzy.backup.LicenseDialog.java
@Override protected Control createDialogArea(Composite parent) { Composite composite = (Composite) super.createDialogArea(parent); Text text = new Text(composite, SWT.BORDER | SWT.READ_ONLY | SWT.MULTI | SWT.V_SCROLL); InputStream in = null;//from ww w . j a v a2 s . c om try { in = BackupPlugin.getDefault().openBundleFile("etc/license.txt"); //$NON-NLS-1$ String licenseText = StringUtils.join(IOUtils.readLines(in, "ISO-8859-1"), '\n'); //$NON-NLS-1$ text.setText(licenseText); } catch (IOException e) { IOUtils.closeQuietly(in); } GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); gd.widthHint = convertWidthInCharsToPixels(80); gd.heightHint = convertWidthInCharsToPixels(40); text.setLayoutData(gd); return composite; }
From source file:fi.ilmoeuro.membertrack.db.DatabaseInitializer.java
public void init(SessionToken<DSLContext> sessionToken) { if (config.isEnabled()) { try (final InputStream setupStream = ResourceRoot.class.getResourceAsStream(config.getSetupList())) { if (setupStream != null) { final List<String> setupFiles = IOUtils.readLines(setupStream, Charsets.UTF_8); runMigrations(sessionToken.getValue(), setupFiles); }//w w w . j a va 2 s . c o m } catch (IOException ex) { throw new RuntimeException("Error loading setup list", ex); } } }
From source file:de.tudarmstadt.ukp.dkpro.tc.api.features.util.FeatureUtil.java
/** * @param inputFile Location of the file that contains the stopwords. One stopword per line. * @param toLowerCase Whether the stopwords should be converted to lowercase or not. * @return A set of stopwords.//from ww w . j av a2 s . co m * @throws IOException */ public static Set<String> getStopwords(String inputFile, boolean toLowerCase) throws IOException { Set<String> stopwords = new HashSet<String>(); if (inputFile != null) { URL stopUrl = ResourceUtils.resolveLocation(inputFile, null); InputStream is = stopUrl.openStream(); for (String stopword : IOUtils.readLines(is, "UTF-8")) { if (toLowerCase) { stopwords.add(stopword.toLowerCase()); } else { stopwords.add(stopword); } } } return stopwords; }
From source file:com.mammothdata.samplepipeline.ApplicationTest.java
@Test public void testApplication() throws Exception { try {// w w w. j a va 2s. c om // Pull in sample data and shovel it into kafka KafkaTestProducer p = new KafkaTestProducer(TOPIC); List<String> lines = IOUtils.readLines(this.getClass().getResourceAsStream("/data/sample.short.json"), "UTF-8"); p.setMessages(lines); LOG.info("Kafka data loaded"); new Thread(p).start(); LocalMode lma = LocalMode.newInstance(); Configuration conf = new Configuration(false); conf.addResource(this.getClass().getResourceAsStream("/META-INF/properties.xml")); conf.set("dt.operator.kafkaInput.prop.topic", TOPIC); conf.set("dt.operator.kafkaInput.prop.zookeeper", "localhost:" + KafkaOperatorTestBase.TEST_ZOOKEEPER_PORT[0]); conf.set("dt.operator.kafkaInput.prop.maxTuplesPerWindow", "1"); // consume one word per window lma.prepareDAG(new Application(), conf); LocalMode.Controller lc = lma.getController(); LOG.info("Application run started"); lc.run(10000); LOG.info("Application run finished"); lc.shutdown(); } catch (ConstraintViolationException e) { Assert.fail("constraint violations: " + e.getConstraintViolations()); } }
From source file:au.org.ala.bhl.service.WebServiceHelper.java
/** * Performs a GET on the specified URI, and returns the body without any transformation * //w ww .j av a2 s . c om * @param uri * @return * @throws IOException */ public static String getText(String uri) throws IOException { HttpClient httpclient = new DefaultHttpClient(); HttpGet httpget = new HttpGet(uri); httpget.setHeader("Accept", "application/text"); HttpResponse response = httpclient.execute(httpget); HttpEntity entity = response.getEntity(); if (entity != null) { InputStream instream = entity.getContent(); @SuppressWarnings("unchecked") List<String> lines = IOUtils.readLines(instream, "utf-8"); return StringUtils.join(lines, "\n"); } return null; }
From source file:com.chiorichan.lang.ApacheParser.java
public ApacheParser appendWithFile(File conf) throws IOException { if (conf.exists() && conf.isFile()) { InputStream is = new FileInputStream(conf); List<String> contents = IOUtils.readLines(is, Charsets.US_ASCII); for (String l : contents) { l = l.trim();// w w w. j a v a 2s .c o m // ErrorDocument 403 http://www.yahoo.com/ // Order deny,allow // Deny from all // Allow from 208.113.134.190 if (l == null || l.isEmpty() || l.startsWith("#")) continue; ApacheConfElement e = new ApacheConfElement(l); } } return this; }
From source file:com.github.dozermapper.osgitests.support.BundleOptions.java
public static UrlProvisionOption localBundle(String link) { try (InputStream resourceAsStream = BundleOptions.class.getClassLoader().getResourceAsStream(link)) { assertNotNull("Invalid link file was provided: " + link, resourceAsStream); List<String> urls = IOUtils.readLines(resourceAsStream, Charset.forName("UTF-8")); assertEquals("Invalid link file was provided: " + link, 1, urls.size()); return url(urls.get(0)); } catch (IOException e) { throw new IllegalArgumentException(e); }// w ww . j a v a 2 s . c o m }
From source file:com.fizzed.blaze.internal.DependencyHelper.java
static public List<Dependency> alreadyBundled() { String resourceName = "/com/fizzed/blaze/bundled.txt"; URL url = DependencyHelper.class.getResource(resourceName); if (url == null) { throw new BlazeException( "Unable to find resource " + resourceName + ". Maybe not packaged as jar correctly?"); }/*from w ww . ja va 2 s . c o m*/ List<Dependency> dependencies = new ArrayList<>(); try (InputStream is = url.openStream()) { List<String> lines = IOUtils.readLines(is, "UTF-8"); for (String line : lines) { line = line.trim(); if (!line.equals("")) { if (line.contains("following files have been resolved")) { // skip } else { String d = cleanMavenDependencyLine(line); dependencies.add(Dependency.parse(d)); } } } } catch (IOException e) { throw new BlazeException("Unable to detect bundled dependencies", e); } return dependencies; }