List of usage examples for com.google.common.io Resources readLines
public static List<String> readLines(URL url, Charset charset) throws IOException
From source file:com.madvay.tools.android.perf.apat.Main.java
private static void printLicense() { try {//from w w w . j av a2 s.c o m List<String> lines = Resources.readLines(Resources.getResource("LICENSE"), Charsets.UTF_8); for (String l : lines) { outln(l); } } catch (IOException err) { err(err); } }
From source file:edu.cmu.lti.oaqa.baseqa.answer.score.scorers.StopwordCountAnswerScorer.java
@Override public boolean initialize(ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams) throws ResourceInitializationException { boolean ret = super.initialize(aSpecifier, aAdditionalParams); String stoplistFile = (String) getParameterValue("stoplist"); try {/* www . j a v a 2 s. com*/ stoplist = Resources.readLines(getClass().getResource(stoplistFile), Charsets.UTF_8).stream() .collect(toSet()); } catch (IOException e) { throw new ResourceInitializationException(e); } return ret; }
From source file:org.opendaylight.controller.config.manager.impl.osgi.ModuleFactoryBundleTracker.java
@Override public Boolean addingBundle(Bundle bundle, BundleEvent event) { URL resource = bundle.getEntry("META-INF/services/" + ModuleFactory.class.getName()); LOG.trace("Got addingBundle event of bundle {}, resource {}, event {}", bundle, resource, event); if (resource != null) { try {/* ww w . j a v a 2 s.c o m*/ for (String factoryClassName : Resources.readLines(resource, StandardCharsets.UTF_8)) { registerFactory(factoryClassName, bundle); } return Boolean.TRUE; } catch (IOException e) { LOG.error("Error while reading {}", resource, e); throw new RuntimeException(e); } } return Boolean.FALSE; }
From source file:com.rhythm.louie.info.InfoServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods. * @param request servlet request/*ww w .j a va 2 s . c o m*/ * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Map<String, Object> properties = new HashMap<>(); String config = request.getParameter("config"); if (config != null) { if ("services".equals(config)) { properties.put("serviceconfig", ServiceProperties.getAllServiceProperties()); } else { properties.put("config", "<xmp>" + LouieProperties.getDocument() + "</xmp>"); } } List<String> extras = Collections.emptyList(); try { extras = Resources.readLines(request.getServletContext().getClassLoader().getResource(LOUIE_EXTRA_INFO), Charset.defaultCharset()); } catch (Exception ex) { LoggerFactory.getLogger(InfoServlet.class).error("Failed to get URL for louie-info.html file: {}", ex.toString()); } properties.put("extras", extras); properties.put("fails", ServiceManager.getFailedServiceProviders()); properties.put("errors", ServiceManager.getErrors()); InfoUtils.writeTemplateResponse(request, response, "info.vm", properties); }
From source file:edu.cmu.lti.oaqa.baseqa.answer.yesno.scorers.NegationYesNoScorer.java
@Override public boolean initialize(ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams) throws ResourceInitializationException { super.initialize(aSpecifier, aAdditionalParams); String negationCuesPath = (String) getParameterValue("negation-cues-path"); try {//ww w.j a va2s .c o m negationCues = Resources.readLines(getClass().getResource(negationCuesPath), Charsets.UTF_8).stream() .collect(toSet()); } catch (IOException e) { throw new ResourceInitializationException(e); } viewNamePrefix = String.class.cast(getParameterValue("view-name-prefix")); return true; }
From source file:edu.cmu.lti.oaqa.baseqa.answer_type.AnswerTypeCVPredictLoader.java
@Override public void initialize(UimaContext context) throws ResourceInitializationException { super.initialize(context); String cvPredictFile = UimaContextHelper.getConfigParameterStringValue(context, "cv-predict-file"); List<String> lines; try {//from w w w . jav a2 s . c o m lines = Resources.readLines(getClass().getResource(cvPredictFile), Charsets.UTF_8); } catch (IOException e) { throw new ResourceInitializationException(e); } qid2lats = lines.stream().map(line -> line.split("\t")).collect( toMap(segs -> segs[0], segs -> Arrays.stream(segs[1].split(";")).collect(toList()), (x, y) -> x)); }
From source file:edu.cmu.lti.oaqa.baseqa.providers.ml.classifiers.FeatureConstructorProviderImpl.java
@Override public boolean initialize(ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams) throws ResourceInitializationException { boolean ret = super.initialize(aSpecifier, aAdditionalParams); String quantityQuestionWordsPath = (String) getParameterValue("quantity-question-words-path"); try {/*from w ww . j a va 2s . c o m*/ quantityQuestionPhrases = Resources.readLines(getClass().getResource(quantityQuestionWordsPath), UTF_8) .stream().map(String::trim).map(line -> Arrays.asList(line.split(" "))).collect(toList()); } catch (IOException e) { throw new ResourceInitializationException(e); } return ret; }
From source file:com.mapr.synth.samplers.ZipSampler.java
public ZipSampler() { try {// w ww . j a va 2s . c o m List<String> names = null; for (String line : Resources.readLines(Resources.getResource("zip.csv"), Charsets.UTF_8)) { CsvSplitter onComma = new CsvSplitter(); if (line.startsWith("#")) { // last comment line contains actual field names names = Lists.newArrayList(onComma.split(line.substring(1))); } else { Preconditions.checkState(names != null); assert names != null; Iterable<String> fields = onComma.split(line); Iterator<String> nx = names.iterator(); for (String value : fields) { Preconditions.checkState(nx.hasNext()); String fieldName = nx.next(); List<String> dataList = values.get(fieldName); if (dataList == null) { dataList = Lists.newArrayList(); values.put(fieldName, dataList); } dataList.add(value); } if (!names.iterator().next().equals("V1")) { Preconditions.checkState(!nx.hasNext()); } zipCount++; } } } catch (IOException e) { throw new RuntimeException("Couldn't read built-in zip code data file", e); } }
From source file:org.apache.ctakes.temporal.ae.feature.CheckSpecialWordRelationExtractor.java
public CheckSpecialWordRelationExtractor() { this.specialWd = ArrayListMultimap.create(); URL url = TimeWordsExtractor.class.getResource(LOOKUP_PATH); try {/*w w w . j a va2s .c o m*/ for (String line : Resources.readLines(url, Charsets.US_ASCII)) { String[] WordAndType = line.split(","); if (WordAndType.length != 2) { throw new IllegalArgumentException("Expected '<word>,<type>', found: " + line); } this.specialWd.put(WordAndType[0], WordAndType[1]); } } catch (IOException e) { System.err.println("TimeLexicon resource initialization error."); } }
From source file:io.hops.hopsworks.common.util.IoUtils.java
public static List<String> readLinesFromClasspath(String url) throws IOException { return Resources.readLines(Resources.getResource(url), Charsets.UTF_8); }