List of usage examples for com.google.common.io Resources asCharSource
public static CharSource asCharSource(URL url, Charset charset)
From source file:org.nmdp.ngs.hml.HmlReader.java
/** * Read HML from the specified URL./* w w w. ja v a 2s .c o m*/ * * @param url URL to read from, must not be null * @return the HML read from the specified URL * @throws IOException if an I/O error occurs */ public static Hml read(final URL url) throws IOException { checkNotNull(url); try (BufferedReader reader = Resources.asCharSource(url, Charsets.UTF_8).openBufferedStream()) { return read(reader); } }
From source file:org.apache.isis.viewer.wicket.viewer.services.TranslationsResolverWicket.java
private static List<String> readLines(final URL url) throws IOException { if (url == null) { return null; }/*w w w . j ava2 s.c o m*/ final CharSource charSource = Resources.asCharSource(url, Charsets.UTF_8); final ImmutableList<String> strings = charSource.readLines(); return Collections.unmodifiableList(Lists.newArrayList(Iterables.filter(strings, new Predicate<String>() { @Override public boolean apply(final String input) { return input != null && nonEmpty.matcher(input).matches(); } }))); }
From source file:org.nmdp.ngs.gtr.GtrReader.java
/** * Read GTR public data from the specified URL. * * @param url URL to read from, must not be null * @return the GTR public data read from the specified URL * @throws IOException if an I/O error occurs *//* ww w.j ava2s. co m*/ public static GTRPublicData read(final URL url) throws IOException { checkNotNull(url); try (BufferedReader reader = Resources.asCharSource(url, Charsets.UTF_8).openBufferedStream()) { return read(reader); } }
From source file:com.opengamma.strata.collect.io.CharSources.java
/** * Obtains an instance of {@link CharSource} from a URL, specified as a {@link URL} object. * * @param url the url to create a {@link CharSource} from * @return a new instance of {@link CharSource} with UTF-8 for charset. *//* w w w. j av a 2s.c o m*/ public static CharSource ofUrl(URL url) { return Resources.asCharSource(url, Charsets.UTF_8); }
From source file:org.apache.isis.viewer.restfulobjects.server.resources.VersionReprRenderer.java
private static String versionFromManifest() { try {//from ww w.ja v a 2s .c o m URL resource = Resources.getResource(META_INF_POM_PROPERTIES); Properties p = new Properties(); p.load(Resources.asCharSource(resource, Charset.defaultCharset()).openStream()); return p.getProperty("version"); } catch (final Exception ex) { return "UNKNOWN"; } }
From source file:net.osten.watermap.convert.SanMateoWildernessReport.java
/** * Returns water reports from text file. * Text file format: name, description, state, last report, reported by, lat, lon. * * @return set of water reports/*from w w w. ja v a 2 s . c o m*/ */ public Set<WaterReport> convert() { Set<WaterReport> results = new HashSet<WaterReport>(); int lineNumber = 1; try { log.info("opening filePath=" + filePath); ImmutableList<String> lines = filePath != null ? Files.asCharSource(new File(filePath), Charsets.UTF_8).readLines() : Resources.asCharSource(fileURL, Charsets.UTF_8).readLines(); log.fine("found " + lines.size() + " lines"); for (String line : lines) { // find start of data line section WaterReport wr = null; log.fine("parsing line[" + lineNumber + "]=" + line); wr = parseDataLine(line); if (wr != null && wr.getName() != null) { log.fine("adding wr=" + wr); boolean added = results.add(wr); if (!added) { results.remove(wr); results.add(wr); } } else { log.finer("did not add wr for line " + lineNumber); } lineNumber++; } } catch (IOException e) { log.severe(e.getLocalizedMessage()); } return results; }
From source file:org.nmdp.ngs.sra.SraReader.java
/** * Read an analysis from the specified URL. * * @param url URL, must not be null//from w ww.j a v a 2 s . c o m * @return an analysis read from the specified URL * @throws IOException if an I/O error occurs */ public static Analysis readAnalysis(final URL url) throws IOException { checkNotNull(url); try (BufferedReader reader = Resources.asCharSource(url, Charsets.UTF_8).openBufferedStream()) { return readAnalysis(reader); } }
From source file:com.opengamma.strata.collect.io.CharSources.java
/** * Obtains an instance of {@link CharSource} from an URL, specified as a {@link URL} object. * This also takes in a specific character set, as a {@link Charset}. * * @param url the url to create a {@link CharSource} from * @param charset the charset to build the new CharSource based on * @return a new instance of {@link CharSource}. *//*from ww w.j a v a2 s . co m*/ public static CharSource ofUrl(URL url, Charset charset) { return Resources.asCharSource(url, charset); }
From source file:org.lenskit.data.dao.file.TextEntitySource.java
/** * Set the URL of the input data.//from ww w .java 2 s. c o m * @param url The URL of the input data. */ public void setURI(URL url) { sourceURL = url; source = Resources.asCharSource(url, Charsets.UTF_8); }
From source file:net.osten.watermap.convert.SanGorgonioReport.java
/** * Converts the SanG datafile to water reports. * * @return set of water reports// w w w. j a v a2s .c om */ public Set<WaterReport> convert() { Set<WaterReport> results = new HashSet<WaterReport>(); /* Multiset<String> liness = HashMultiset.create( Splitter.on('\t') .trimResults() .omitEmptyStrings() .split( (filePath != null ? Files.asCharSource(new File(filePath), Charsets.UTF_8).read() : Resources.asCharSource(fileURL, Charsets.UTF_8).read()))); System.out.println("found " + liness.size() + " lines"); */ try { ImmutableList<String> lines = filePath != null ? Files.asCharSource(new File(filePath), Charsets.UTF_8).readLines() : Resources.asCharSource(fileURL, Charsets.UTF_8).readLines(); log.fine("found " + lines.size() + " lines"); for (String line : lines) { List<String> fields = Splitter.on('\t').trimResults().splitToList(line); /* Layout of datafile.txt - * String postDate = nextLine[0]; * String location = nextLine[1]; * String comment = nextLine[2]; * String logDate = nextLine[3]; * String user = nextLine[4]; */ WaterReport wr = new WaterReport(); try { wr.setLastReport(dateFormatter.parse(fields.get(3))); wr.setLocation("San Gorgonio"); wr.setDescription(fields.get(2)); wr.setName(fields.get(1)); wr.setSource(SOURCE_TITLE); wr.setUrl(SOURCE_URL); if (locationCoords.containsKey(wr.getName())) { List<String> coords = Splitter.on(',').splitToList(locationCoords.get(wr.getName())); wr.setLon(new BigDecimal(coords.get(0))); wr.setLat(new BigDecimal(coords.get(1))); } else { log.fine("==> cannot find coords for " + wr.getName()); } wr.setState(WaterStateParser.parseState(wr.getDescription())); boolean added = results.add(wr); if (!added) { results.remove(wr); results.add(wr); } } catch (java.text.ParseException e) { log.severe(e.getLocalizedMessage()); } } } catch (IOException e) { log.severe(e.getLocalizedMessage()); } return results; }