List of usage examples for com.google.common.io CharStreams toString
public static String toString(Readable r) throws IOException
From source file:ai.grakn.migration.json.JsonMigrator.java
/** * Convert a reader to a string/*from ww w . j a v a 2 s . c o m*/ * @param reader reader to be converted * @return Json object representing the file, empty if problem reading file */ private String asString(Reader reader) { try { return CharStreams.toString(reader); } catch (IOException e) { throw new RuntimeException("Problem reading input"); } }
From source file:com.google.javascript.jscomp.ZipEntryReader.java
public String read(Charset charset) throws IOException { CachedZipFile zipFile = zipFileCache.getUnchecked(zipPath); return CharStreams.toString(zipFile.getReader(entryName, charset)); }
From source file:eu.operando.PolicyEvaluationService.java
/** * The Policy Evaluation Component depends upon multiple entries to different * components. Hence, testing and unit testing is impossible without * full integration testing. Hence, this component contains a set of * demo user preferences.// ww w . j a va 2 s . c o m * * This method loads these demo UPPs into local memory * * @param name The name of the user id to load into memory. * @param fileLoc The filename in the resources directory. */ private void loadDemoUPP(String name, String fileLoc) { InputStream fis = null; try { fis = this.getClass().getClassLoader().getResourceAsStream(fileLoc); String content = CharStreams.toString(new InputStreamReader(fis, Charsets.UTF_8)); Closeables.closeQuietly(fis); UppDB.put(name, content); } catch (IOException e) { // Display to console for debugging purposes. System.err.println("Error reading Configuration properties file"); // Add logging code to log an error configuring the API on startup } }
From source file:com.sonatype.nexus.repository.nuget.internal.proxy.NugetFeedFetcher.java
/** * Pass a count-style Nuget query to a remote repository. *//*from w w w . java 2 s . com*/ @Nullable public Integer getCount(final Repository proxy, URI nugetQuery) throws IOException { final Payload item = getPayload(proxy, absoluteURI(proxy, nugetQuery), 1); if (item == null) { return 0; } try (InputStream is = item.openInputStream()) { final String s = CharStreams.toString(new InputStreamReader(is, Charsets.UTF_8)).trim(); return Integer.parseInt(s); } }
From source file:com.google.publicalerts.cap.validator.PshbServlet.java
/** * Handle POSTs from PSHB for new alerts to validate. * * See http://pubsubhubbub.googlecode.com/svn/trunk/pubsubhubbub-core-0.3.html#contentdistribution */// ww w .jav a2s. c o m @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String input = CharStreams.toString(new InputStreamReader(req.getInputStream(), Charsets.UTF_8)); String pshbSig = req.getHeader(PshbAuthenticator.SIGNATURE_HEADER); String topic = req.getParameter("topic"); String email = req.getParameter("email"); String profileStr = req.getParameter("profiles"); PshbAuthenticator.AuthResult authResult = authenticator.authenticate(input, pshbSig, System.getProperty(ValidatorUtil.ALERT_HUB_SECRET)); if (authResult != PshbAuthenticator.AuthResult.OK) { resp.setStatus(HttpServletResponse.SC_OK); return; } // Reply to PSHB so the connection doesn't time out resp.setStatus(HttpServletResponse.SC_OK); resp.flushBuffer(); // The PSHB POST is valid, validate the input Set<CapProfile> profiles = ValidatorUtil.parseProfiles(profileStr); ValidationResult result = capValidator.validate(input, profiles); // If there are errors, send email if (result.containsErrors()) { String msg = renderMessage(req, resp, email, topic, profiles, result); sendMail(email, topic, msg, profiles, result); } // TODO(shakusa) Optionally send email if there are recommendations // TODO(shakusa) Maintain a dashboard by topic and update that here }
From source file:org.renjin.cran.PackageDescription.java
public static PackageDescription fromInputStream(InputStream in) throws IOException { return fromString(CharStreams.toString(new InputStreamReader(in))); }
From source file:com.github.sdbg.debug.core.util.ResourceServer.java
protected String getAvailableAppsContent() throws IOException { InputStream in = ResourceServer.class.getResourceAsStream("template.html"); String template = CharStreams.toString(new InputStreamReader(in)); List<IFile> files = getAllExecutableFiles(); // Sort by project name, then html file name Collections.sort(files, new Comparator<IFile>() { @Override/*from w ww . jav a2 s . co m*/ public int compare(IFile o1, IFile o2) { String str1 = o1.getFullPath().toString(); String str2 = o2.getFullPath().toString(); return str1.compareToIgnoreCase(str2); } }); if (files.size() == 0) { template = replaceTemplate(template, "count", "No"); template = replaceTemplate(template, "apps", ""); } else { template = replaceTemplate(template, "count", Integer.toString(files.size())); StringBuilder builder = new StringBuilder(); for (IFile file : files) { String hrefStart = "<a href=\"" + getPathFor(file) + "\">"; builder.append("<div class=\"app\"><table><tr>"); builder.append( "<td rowspan=2>" + hrefStart + "<img src=\"dart_16_16.gif\" width=16 height=16></a></td>"); builder.append("<td class=\"title\">" + hrefStart + webSafe(file.getFullPath().toString()) + "</a></td</tr>"); builder.append("</table></div>"); } template = replaceTemplate(template, "apps", builder.toString()); } return template; }
From source file:com.google.devtools.build.xcode.zippingoutput.Wrappers.java
private static String streamToString(InputStream stream) throws IOException { return CharStreams.toString(new InputStreamReader(stream, StandardCharsets.UTF_8)); }
From source file:org.jclouds.util.Strings2.java
public static String toStringAndClose(InputStream input) throws IOException { checkNotNull(input, "input"); try {/* w w w . ja va 2 s .c o m*/ return CharStreams.toString(new InputStreamReader(input, Charsets.UTF_8)); } finally { closeQuietly(input); } }
From source file:elasticsearch.EmbeddedElasticsearch.java
/** * Delete index and apply settings/*from w w w.j a va 2 s.c o m*/ * * @param index name of the index */ protected void init(String index) { try (InputStream settingsIn = play.Environment.simple().resourceAsStream(indexSettings)) { getClient().admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet(); if (getClient().admin().indices().prepareExists(index).execute().actionGet().isExists()) { getClient().admin().indices().delete(new DeleteIndexRequest(index)).actionGet(); } CreateIndexRequestBuilder cirb = getClient().admin().indices().prepareCreate(index); if (indexSettings != null) { String settingsMappings = CharStreams.toString(new InputStreamReader(settingsIn, "UTF-8")); cirb.setSource(settingsMappings); } cirb.execute().actionGet(); getClient().admin().indices().refresh(new RefreshRequest()).actionGet(); } catch (Exception e) { throw new RuntimeException(e); } }