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.tc.features.ngram.io.TestReaderSentenceToDocument.java
@Override public void initialize(UimaContext context) throws ResourceInitializationException { super.initialize(context); texts = new ArrayList<String>(); try {/*w w w . j av a 2 s . com*/ URL resourceUrl = ResourceUtils.resolveLocation(sentencesFile, this, context); InputStream is = resourceUrl.openStream(); for (String sentence : IOUtils.readLines(is, "UTF-8")) { texts.add(sentence); } is.close(); } catch (IOException e) { throw new ResourceInitializationException(e); } offset = 0; }
From source file:com.github.ilmoeuro.hackmikkeli2016.DatabaseInitializer.java
public void init(DSLContext jooq) { if (config.isEnabled()) { try (final InputStream clearStream = ResourceRoot.class.getResourceAsStream(config.getClearList())) { if (clearStream != null) { final List<String> clearFiles = IOUtils.readLines(clearStream, Charsets.UTF_8); runSqlFiles(jooq, clearFiles); }// www. j ava 2 s .c om } catch (DataAccessException ex) { log.info("Exception while clearing db", ex); } catch (IOException ex) { throw new RuntimeException("Error loading clear list", ex); } try (final InputStream setupStream = ResourceRoot.class.getResourceAsStream(config.getSetupList())) { if (setupStream != null) { final List<String> setupFiles = IOUtils.readLines(setupStream, Charsets.UTF_8); runSqlFiles(jooq, setupFiles); } } catch (IOException ex) { throw new RuntimeException("Error loading setup list", ex); } if (config.isUseExampleData()) { exampleData.populate(jooq); } } }
From source file:de.tudarmstadt.ukp.dkpro.core.textnormalizer.transformation.HyphenationRemover.java
@Override public void initialize(UimaContext aContext) throws ResourceInitializationException { super.initialize(aContext); try {/*from w w w .j a va 2s . c om*/ URL url = ResourceUtils.resolveLocation(modelLocation); try (InputStream is = url.openStream()) { dict = new HashSet<>(IOUtils.readLines(is, modelEncoding)); } } catch (IOException e) { throw new ResourceInitializationException(e); } }
From source file:com.github.robozonky.app.runtime.LivenessCheck.java
@Override protected String getLatestSource() { logger.trace("Running."); // need to send parsed version, since the object itself changes every time due to currentApiTime field return Try.withResources(() -> UrlUtil.open(new URL(url))).of(s -> { final String source = IOUtils.readLines(s, Defaults.CHARSET).stream() .collect(Collectors.joining(System.lineSeparator())); logger.trace("API info coming from Zonky: {}.", source); return read(source); }).getOrElseGet(ex -> {//from w w w .ja v a2s . c om // don't propagate this exception as it is likely to happen and the calling code would WARN about it logger.debug("Zonky servers are likely unavailable.", ex); return null; // will fail during transform() }); }
From source file:com.alibaba.china.talos.service.impl.LwAuditTask.java
@Override public void execute() { String filepath = System.getProperty(RUN_PROPERTY); InputStream in = null;/*w ww. j a va 2 s . c om*/ try { in = new FileInputStream(filepath); @SuppressWarnings("unchecked") List<String> auditResults = IOUtils.readLines(in, FILE_ENCODING); for (String auditResult : auditResults) { handler(auditResult); } } catch (Exception e) { LOGGER.error("[LwAuditTask.execute] cann't open file, path=" + filepath, e); } finally { if (in != null) { try { in.close(); } catch (IOException e) { } } } }
From source file:de.uni_freiburg.informatik.ultimate.licence_manager.authors.SvnAuthorProvider.java
private static boolean isSvnAvailable() { final ProcessBuilder pbuilder = new ProcessBuilder("svn", "--version"); try {// w w w . ja v a2 s. c om final Process process = pbuilder.start(); if (process.waitFor(1000, TimeUnit.MILLISECONDS)) { final List<String> lines = IOUtils.readLines(process.getInputStream(), Charset.defaultCharset()); if (lines == null || lines.isEmpty()) { return false; } sSvnVersion = lines.get(0); return true; } } catch (IOException | InterruptedException e) { System.err.println("Could not find 'svn' executable, disabling author provider"); return false; } return false; }
From source file:de.tudarmstadt.ukp.experiments.argumentation.convincingness.io.ArgumentPairReader.java
protected void loadNextFile() throws IOException { Resource res = nextFile();/*from ww w .j a va 2 s. co m*/ currentFileName = res.getResource().getFile().getName().replace(".csv", ""); currentLines.addAll(IOUtils.readLines(res.getInputStream(), "utf-8")); // remove the first line (comment) currentLines.poll(); }
From source file:de.micromata.genome.gwiki.plugin.rogmp3_1_0.CsvTable.java
public List<String> loadLines(InputStream is) { try {/*from www. j a va 2 s . c o m*/ return IOUtils.readLines(is, encoding); } catch (IOException ex) { throw new RuntimeException(ex); } }
From source file:com.github.frapontillo.pulse.crowd.lemmatize.morphit.MorphITLemmatizer.java
/** * Build the TANL-to-MorphIT mapping dictionary as <key:(tanl-tag), * value:(morphit-tag-1,...)>.//from w w w . j a v a2 s. c o m * Values are read from the resource file "tanl-morphit". * * @return A {@link HashMap} where the key is a {@link String} representing the TANL tag and * values are {@link Set}s of all the MorphIT tag {@link String}s. */ private HashMap<String, HashSet<String>> getTanlMorphITMap() { if (tanlMorphITMap == null) { InputStream mapStream = MorphITLemmatizer.class.getClassLoader().getResourceAsStream("tanl-morphit"); tanlMorphITMap = new HashMap<>(); try { List<String> mapLines = IOUtils.readLines(mapStream, Charset.forName("UTF-8")); mapLines.forEach(s -> { // for each line, split using spaces String[] values = spacePattern.split(s); if (values.length > 0) { // the first token is the key String key = values[0]; // all subsequent tokens are possible values HashSet<String> valueSet = new HashSet<>(); valueSet.addAll(Arrays.asList(values).subList(1, values.length)); tanlMorphITMap.put(key, valueSet); } }); } catch (IOException e) { e.printStackTrace(); } } return tanlMorphITMap; }
From source file:com.smartitengineering.cms.ws.common.providers.TextURIListProvider.java
@Override public Collection<URI> readFrom(Class<Collection<URI>> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException { if (isReadable(type, genericType, annotations, mediaType)) { List<String> asLines = IOUtils.readLines(entityStream, null); if (asLines == null || asLines.isEmpty()) { return Collections.emptyList(); }/*from w w w.j av a2s. c om*/ List<URI> uris = new ArrayList<URI>(); for (String line : asLines) { try { if (logger.isDebugEnabled()) { logger.debug(new StringBuilder("Trying add ").append(line).append(" as an URI").toString()); } uris.add(new URI(line)); } catch (URISyntaxException ex) { logger.error("URI exception while trying to form an URI", ex); throw new IOException(ex); } } return Collections.unmodifiableCollection(uris); } else { return Collections.emptyList(); } }