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:webapp.ToDoApplication.java
private static String readLines(final Class<?> contextClass, final String resourceName) { try {//from ww w . ja v a 2s . c o m final List<String> readLines = Resources.readLines( Resources.getResource(contextClass, resourceName), Charset.defaultCharset()); final String aboutText = Joiner.on("${symbol_escape}n").join(readLines); return aboutText; } catch (final IOException e) { return "This is a Todo app"; } }
From source file:todoapp.webapp.LLBaseApplication.java
private static String readLines(final Class<?> contextClass, final String resourceName) { try {//from w w w . j a v a 2 s. c o m final List<String> readLines = Resources.readLines(Resources.getResource(contextClass, resourceName), Charset.defaultCharset()); final String aboutText = Joiner.on("\n").join(readLines); return aboutText; } catch (final IOException e) { return "This is a Todo app"; } }
From source file:todoapp.webapp.ToDoApplication.java
private static String readLines(final Class<?> contextClass, final String resourceName) { try {/* w w w . ja v a 2 s. co m*/ final List<String> readLines = Resources.readLines(Resources.getResource(contextClass, resourceName), Charset.defaultCharset()); return Joiner.on("\n").join(readLines); } catch (final IOException e) { return "This is a Todo app"; } }
From source file:org.incode.eurocommercial.ecpcrm.webapp.EcpCrmApplication.java
private static String readLines(final Class<?> contextClass, final String resourceName) { try {//w w w . j av a 2 s . co m final List<String> readLines = Resources.readLines(Resources.getResource(contextClass, resourceName), Charset.defaultCharset()); final String aboutText = Joiner.on("\n").join(readLines); return aboutText; } catch (final IOException e) { return "This is an Apache Isis Quickstart app"; } }
From source file:org.geoserver.jdbcconfig.internal.JdbcConfigTestSupport.java
private String[] readDbScript(final String scriptName) throws IOException { URL url = JDBCGeoServerLoader.class.getResource(scriptName); if (url == null) { throw new IllegalArgumentException("Script not found: " + getClass().getName() + "/" + scriptName); }// www . j ava2 s . c o m List<String> lines = Lists.newArrayList(Resources.readLines(url, Charset.forName("UTF-8"))); for (Iterator<String> it = lines.iterator(); it.hasNext();) { if (it.next().trim().length() == 0) { it.remove(); } } return lines.toArray(new String[lines.size()]); }
From source file:com.xemantic.tadedon.configuration.Configurations.java
public static List<String> getLines(URL url) { try {/* ww w . j ava 2s . c o m*/ return Resources.readLines(url, Charsets.UTF_8); } catch (IOException e) { throw new RuntimeException("Cannot read lines from url: " + url, e); } }
From source file:edu.cmu.lti.oaqa.baseqa.concept.rerank.scorers.LuceneConceptScorer.java
@Override public boolean initialize(ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams) throws ResourceInitializationException { super.initialize(aSpecifier, aAdditionalParams); hits = Integer.class.cast(getParameterValue("hits")); // query constructor String stoplistPath = String.class.cast(getParameterValue("stoplist-path")); try {//from ww w . j a va 2 s .c o m stoplist = Resources.readLines(getClass().getResource(stoplistPath), UTF_8).stream().map(String::trim) .collect(toSet()); } catch (IOException e) { throw new ResourceInitializationException(e); } // load index parameters idFieldName = String.class.cast(getParameterValue("id-field")); sourceFieldName = String.class.cast(getParameterValue("source-field")); //noinspection unchecked fields = Iterables.toArray((Iterable<String>) getParameterValue("fields"), String.class); String uriPrefixPath = String.class.cast(getParameterValue("uri-prefix")); try { uriPrefix = Resources.readLines(getClass().getResource(uriPrefixPath), UTF_8).stream() .map(line -> line.split("\t")).collect(toMap(segs -> segs[0], segs -> segs[1])); } catch (IOException e) { throw new ResourceInitializationException(e); } String index = String.class.cast(getParameterValue("index")); // create lucene Analyzer analyzer = new StandardAnalyzer(); parser = new MultiFieldQueryParser(fields, analyzer); try { reader = DirectoryReader.open(FSDirectory.open(Paths.get(index))); } catch (IOException e) { throw new ResourceInitializationException(e); } searcher = new IndexSearcher(reader); return true; }
From source file:org.opendaylight.controller.blueprint.ext.SpecificReferenceListMetadata.java
private void bundleAdded(Bundle bundle) { URL resource = bundle.getEntry(serviceResourcePath); if (resource == null) { return;/*from ww w . ja va 2 s . c om*/ } LOG.debug("{}: Found {} resource in bundle {}", logName(), resource, bundle.getSymbolicName()); try { for (String line : Resources.readLines(resource, StandardCharsets.UTF_8)) { int ci = line.indexOf('#'); if (ci >= 0) { line = line.substring(0, ci); } line = line.trim(); if (line.isEmpty()) { continue; } String serviceType = line; LOG.debug("{}: Retrieved service type {}", logName(), serviceType); expectedServiceTypes.add(serviceType); } } catch (IOException e) { setFailure(String.format("%s: Error reading resource %s from bundle %s", logName(), resource, bundle.getSymbolicName()), e); } }
From source file:edu.cmu.lti.oaqa.baseqa.concept.retrieval.LuceneConceptRetrievalExecutor.java
@Override public void initialize(UimaContext context) throws ResourceInitializationException { super.initialize(context); hits = UimaContextHelper.getConfigParameterIntValue(context, "hits", 100); // query constructor constructor = UimaContextHelper.createObjectFromConfigParameter(context, "query-string-constructor", "query-string-constructor-params", BooleanBagOfPhraseQueryStringConstructor.class, QueryStringConstructor.class); // lucene// ww w .j av a 2s. com Analyzer analyzer = UimaContextHelper.createObjectFromConfigParameter(context, "query-analyzer", "query-analyzer-params", StandardAnalyzer.class, Analyzer.class); String[] fields = UimaContextHelper.getConfigParameterStringArrayValue(context, "fields"); parser = new MultiFieldQueryParser(fields, analyzer); String index = UimaContextHelper.getConfigParameterStringValue(context, "index"); try { reader = DirectoryReader.open(FSDirectory.open(Paths.get(index))); } catch (IOException e) { throw new ResourceInitializationException(e); } searcher = new IndexSearcher(reader); idFieldName = UimaContextHelper.getConfigParameterStringValue(context, "id-field", null); nameFieldName = UimaContextHelper.getConfigParameterStringValue(context, "name-field", null); sourceFieldName = UimaContextHelper.getConfigParameterStringValue(context, "source-field", null); String uriPrefixPath = UimaContextHelper.getConfigParameterStringValue(context, "uri-prefix"); try { uriPrefix = Resources.readLines(getClass().getResource(uriPrefixPath), UTF_8).stream() .map(line -> line.split("\t")).collect(toMap(segs -> segs[0], segs -> segs[1])); } catch (IOException e) { throw new ResourceInitializationException(e); } }
From source file:com.streamsets.pipeline.lib.parser.udp.collectd.CollectdParser.java
private void loadTypesDb(String typesDbLocation) { typesDb = new HashMap<>(); try {// www .jav a 2 s . c o m List<String> lines; if (typesDbLocation == null || typesDbLocation.isEmpty()) { lines = Resources.readLines(Resources.getResource("types.db"), Charset.defaultCharset()); } else { Path typesDbFile = FileSystems.getDefault().getPath(typesDbLocation); // NOSONAR lines = Files.readAllLines(typesDbFile, charset); } for (String line : lines) { String trimmed = line.trim(); if (trimmed.isEmpty() || trimmed.startsWith("#")) { continue; } String[] parts = trimmed.split("\\s+", 2); String dataSetName = parts[0]; String[] typeSpecs = parts[1].split(","); List<String> typeParams = new ArrayList<>(); for (String typeSpec : typeSpecs) { typeParams.add(typeSpec.trim().split(":")[0]); } typesDb.put(dataSetName, typeParams); } } catch (IOException e) { LOG.error("Failed to parse type db.", e); } }