List of usage examples for com.google.common.io Resources asCharSource
public static CharSource asCharSource(URL url, Charset charset)
From source file:org.dishevelled.bio.alignment.sam.SamReader.java
/** * Read the SAM header from the specified URL. * * @param url URL to read from, must not be null * @return the SAM header read from the specified URL * @throws IOException if an I/O error occurs *///from w w w .j av a 2 s . com public static SamHeader header(final URL url) throws IOException { checkNotNull(url); try (BufferedReader reader = Resources.asCharSource(url, Charsets.UTF_8).openBufferedStream()) { return header(reader); } }
From source file:net.osten.watermap.convert.AZTReport.java
/** * Converts the AT PDF datafile to water reports. * * @return set of water reports/*from ww w . j a v a2s . com*/ */ public Set<WaterReport> convert() { Set<WaterReport> results = new HashSet<WaterReport>(); boolean inData = false; int lineNumber = 1; 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) { // find start of data line section if (RegexUtils.matchFirstOccurance(line, dataLinePattern) != null) { WaterReport wr = null; log.fine("parsing line[" + lineNumber + "]=" + line); wr = parseDataLine(line); //log.fine("wr=" + wr); /* * 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()); } */ 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); /* if (RegexUtils.matchFirstOccurance(line, passsageLinePattern) != null) { // some data sections have a passage section header log.fine("found passage section header at line " + lineNumber); } else { // end of data section // TODO how to detect the end of a section? //inData = false; log.fine("end of data at line " + lineNumber); }*/ } } else { log.finest("skipping line " + lineNumber); } lineNumber++; } } catch (IOException e) { log.severe(e.getLocalizedMessage()); } return results; }
From source file:org.asoem.greyfish.impl.io.GreyfishH2ConnectionManager.java
public static String defaultInitSql() { final String resourceName = "/h2/DefaultExperimentDatabase.init.sql"; final URL resource = Resources.getResource(GreyfishH2ConnectionManager.class, resourceName); try {/* w ww.j av a 2 s .c o m*/ return Resources.asCharSource(resource, Charsets.UTF_8).read(); } catch (IOException e) { throw Throwables.propagate(e); } }
From source file:to.lean.tools.gmail.importer.gmail.Authorizer.java
private GoogleClientSecrets loadGoogleClientSecrets(JsonFactory jsonFactory) throws IOException { URL url = Resources.getResource("client_secret.json"); CharSource inputSupplier = Resources.asCharSource(url, Charsets.UTF_8); return GoogleClientSecrets.load(jsonFactory, inputSupplier.openStream()); }
From source file:org.asoem.greyfish.impl.io.GreyfishH2ConnectionManager.java
public static String defaultFinalizeSql() { final String resourceName = "/h2/DefaultExperimentDatabase.finalize.sql"; final URL resource = Resources.getResource(GreyfishH2ConnectionManager.class, resourceName); try {//from w ww . j av a 2 s. c o m return Resources.asCharSource(resource, Charsets.UTF_8).read(); } catch (IOException e) { throw Throwables.propagate(e); } }
From source file:uk.co.thinkofdeath.prismarine.server.network.LoginHandler.java
private LoginResponse tryAuth(EncryptionResponse encryptionResponse) throws IOException { MessageDigest digest;//from w w w.j a v a2s. co m try { digest = MessageDigest.getInstance("sha1"); byte[] testKey = decrypt(encryptionResponse.getVerifyToken()); byte[] secretKeyBytes = decrypt(encryptionResponse.getSecretKey()); if (!Arrays.equals(testKey, verifyToken)) { handler.disconnect(new TextComponent("Verify token incorrect")); } SecretKey secretKey = new SecretKeySpec(secretKeyBytes, "AES"); digest.update(serverId.getBytes(StandardCharsets.UTF_8)); digest.update(secretKeyBytes); digest.update(handler.getManager().getNetworkKeyPair().getPublic().getEncoded()); handler.enableEncryption(secretKey); URL url = new URL("https://sessionserver.mojang.com/session/minecraft/hasJoined?" + "username=" + username + "&serverId=" + new BigInteger(digest.digest()).toString(16)); return gson.fromJson(Resources.asCharSource(url, StandardCharsets.UTF_8).openBufferedStream(), LoginResponse.class); } catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | IllegalBlockSizeException | BadPaddingException e) { throw new RuntimeException(e); } }
From source file:nl.vumc.biomedbridges.galaxy.GalaxyWorkflow.java
/** * Get the content of the GA-file./* w w w. jav a2 s . c o m*/ * * todo: use an absolute file path instead of the classpath. * * @return the json design of the workflow. */ private String getJsonContent() { try { final URL resourceUrl = GalaxyWorkflow.class.getResource(getJsonFilename()); return resourceUrl != null ? Resources.asCharSource(resourceUrl, Charsets.UTF_8).read() : null; } catch (final IOException e) { logger.error("Exception while retrieving json design in workflow file {}.", getJsonFilename(), e); throw new RuntimeException(e); } }
From source file:org.nmdp.ngs.variant.vcf.VcfReader.java
/** * Read zero or more VCF samples from the specified URL. * * @param url URL to read from, must not be null * @return zero or more VCF samples read from the specified URL * @throws IOException if an I/O error occurs *//* ww w. j a v a 2 s. c o m*/ public static Iterable<VcfSample> samples(final URL url) throws IOException { checkNotNull(url); try (BufferedReader reader = Resources.asCharSource(url, Charsets.UTF_8).openBufferedStream()) { return samples(reader); } }
From source file:org.dishevelled.bio.alignment.sam.SamReader.java
/** * Read zero or more SAM records from the specified URL. * * @param url URL to read from, must not be null * @return zero or more SAM records read from the specified URL * @throws IOException if an I/O error occurs *///w w w . j a v a 2 s . c om public static Iterable<SamRecord> records(final URL url) throws IOException { checkNotNull(url); try (BufferedReader reader = Resources.asCharSource(url, Charsets.UTF_8).openBufferedStream()) { return records(reader); } }
From source file:org.sosy_lab.cpachecker.core.counterexample.ReportGenerator.java
private void fillOutTemplate(@Nullable CounterexampleInfo counterExample, Path reportPath, CFA cfa, DOTBuilder2 dotBuilder, String statistics) { try (BufferedReader template = Resources .asCharSource(Resources.getResource(getClass(), HTML_TEMPLATE), Charsets.UTF_8) .openBufferedStream(); Writer report = MoreFiles.openOutputFile(reportPath, Charsets.UTF_8)) { String line;//www . j a v a2 s. com while (null != (line = template.readLine())) { if (line.contains("CONFIGURATION")) { insertConfiguration(report); } else if (line.contains("STATISTICS")) { insertStatistics(report, statistics); } else if (line.contains("SOURCE_CONTENT")) { insertSources(report); } else if (line.contains("LOG")) { insertLog(report); } else if (line.contains("ERRORPATH") && counterExample != null) { insertErrorPathData(counterExample, report); } else if (line.contains("FUNCTIONS")) { insertFunctionNames(report, cfa); } else if (line.contains("SOURCE_FILE_NAMES")) { insertSourceFileNames(report); } else if (line.contains("COMBINEDNODES")) { insertCombinedNodesData(report, dotBuilder); } else if (line.contains("CFAINFO")) { insertCfaInfoData(report, dotBuilder); } else if (line.contains("FCALLEDGES")) { insertFCallEdges(report, dotBuilder); } else if (line.contains("REPORT_NAME")) { insertReportName(counterExample, report); } else if (line.contains("METATAGS")) { insertMetaTags(report); } else if (line.contains("GENERATED")) { insertDateAndVersion(report); } else { report.write(line + "\n"); } } } catch (IOException e) { logger.logUserException(WARNING, e, "Could not create report: Processing of HTML template failed."); } }