List of usage examples for com.google.common.io CharStreams toString
public static String toString(Readable r) throws IOException
From source file:org.caleydo.view.bicluster.PackageGenerator.java
protected static void dump(ProjectDescription project, String output) { List<ATableBasedDataDomain> dataDomains = new ArrayList<>(); // Iterate over data type sets and trigger processing for (DataSetDescription dataSetDescription : project.getDataSetDescriptionCollection()) { ATableBasedDataDomain dataDomain = DataLoader.loadData(dataSetDescription, new NullProgressMonitor()); if (dataDomain == null) continue; dataDomains.add(dataDomain);// w ww . jav a 2 s . c om dataDomain.getDefaultTablePerspective(); } try { ProjectManager.save(output + ".tmp", true, dataDomains, ProjectMetaData.createDefault()) .run(new NullProgressMonitor()); } catch (InvocationTargetException | InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); return; } // patch in the workbench.xmi String template = ""; try { template = CharStreams.toString(new InputStreamReader( PackageGenerator.class.getResourceAsStream("/resources/workbench.in.xmi"))); for (int i = 0; i < dataDomains.size(); ++i) { template = template.replace("@DATADOMAIN" + (i + 1) + "@", dataDomains.get(i).getDataDomainID()); template = template.replace("@PERSPECTIVE" + (i + 1) + "@", dataDomains.get(i).getDefaultTablePerspective().getTablePerspectiveKey()); } } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try (ZipFile in = new ZipFile(output + ".tmp"); ZipOutputStream out = new ZipOutputStream(new FileOutputStream(output))) { // first, copy contents from existing war Enumeration<? extends ZipEntry> entries = in.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); out.putNextEntry(entry); InputStream iin = in.getInputStream(entry); if (!entry.isDirectory()) { ByteStreams.copy(iin, out); } iin.close(); out.closeEntry(); } ZipEntry entry = new ZipEntry("workbench.xmi"); out.putNextEntry(entry); ByteStreams.copy(new ByteArrayInputStream(template.getBytes()), out); out.closeEntry(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } new File(output + ".tmp").delete(); }
From source file:org.eclipse.osee.orcs.core.internal.script.impl.OrcsScriptCompilerImpl.java
private String read(Reader reader) throws IOException { String script = CharStreams.toString(reader); if (Strings.isValid(script)) { script = script.trim();//w ww . j a v a 2 s .c o m if (!script.endsWith(";")) { script = script + ';'; } } return script; }
From source file:org.jclouds.util.Strings2.java
public static String toString(InputSupplier<? extends InputStream> supplier) throws IOException { return CharStreams.toString(CharStreams.newReaderSupplier(supplier, Charsets.UTF_8)); }
From source file:com.torodb.backend.meta.AbstractSchemaUpdater.java
@SuppressFBWarnings(value = "UI_INHERITANCE_UNSAFE_GETRESOURCE", justification = "We want to read resources from the subclass") protected void executeSql(DSLContext dsl, String resourcePath, SqlHelper sqlHelper) { try (InputStream resourceAsStream = getClass().getResourceAsStream(resourcePath)) { if (resourceAsStream == null) { throw new SystemException("Resource '" + resourcePath + "' does not exist"); }/*from w ww . j a v a 2 s . co m*/ String statementAsString = CharStreams.toString( new BufferedReader(new InputStreamReader(resourceAsStream, Charset.forName("UTF-8")))); sqlHelper.executeStatement(dsl, statementAsString, Context.UNKNOWN); } catch (IOException ex) { throw new ToroRuntimeException(ex); } }
From source file:org.apache.helix.rest.server.filters.AuditLogFilter.java
private String getEntity(InputStream entityStream) { if (entityStream != null) { try {/*from www.j a va2s. com*/ return CharStreams.toString(new InputStreamReader(entityStream, StandardCharsets.UTF_8)); } catch (IOException e) { _logger.warn("Failed to parse input entity stream " + e); } } return null; }
From source file:org.icgc.dcc.submission.sftp.Sftp.java
private static String read(InputStream inputStream) throws IOException { return CharStreams.toString(new InputStreamReader(inputStream, UTF_8)); }
From source file:com.ritesh.idea.plugin.diff.RbToolsDiffProvider.java
private String generateDiff(VcsRevision revision, String rootPath, List<String> additionalOptions) throws IOException { List<String> commands = new ArrayList<>(); String processPath = (rbtPath == null ? "rbt" : rbtPath); commands.addAll(Arrays.asList(processPath, "diff", "--server", url, "--username", userName, "--password", password));//from ww w. j a va2 s. c o m commands.addAll(additionalOptions); if (revision != null) { if (revision.fromRevision() != null) commands.add(revision.fromRevision()); if (revision.toRevision() != null && !revision.toRevision().equals(revision.fromRevision())) commands.add(revision.toRevision()); } LOG.info("Running command : " + commands); ProcessBuilder builder = new ProcessBuilder(commands); builder.directory(new File(rootPath)); builder.redirectErrorStream(true); Process process = builder.start(); String stdInput = CharStreams.toString(new InputStreamReader(process.getInputStream())); String stdErrorInput = CharStreams.toString(new InputStreamReader(process.getErrorStream())); if (stdErrorInput.trim().isEmpty()) { return stdInput; } else { throw new RuntimeException("Error : " + stdErrorInput); } }
From source file:org.renjin.parser.RParser.java
/** * Parses the source and adds a terminator of the stream if it does not exist. * @param reader/*from w w w .j a v a 2 s . c o m*/ * @return * @throws IOException */ public static ExpressionVector parseAllSource(Reader reader) throws IOException { String source = CharStreams.toString(reader); if (!source.endsWith("\n")) { source = source + "\n"; } return parseSource(source); }
From source file:co.cask.cdap.test.AudiTestBase.java
private RESTClient createRestClient() { RESTClient restClient = new RESTClient(getClientConfig()); restClient.addListener(new RESTClient.Listener() { @Override// w w w . j a v a 2 s. c o m public void onRequest(HttpRequest httpRequest, int i) { try { InputSupplier<? extends InputStream> inputSupplier = httpRequest.getBody(); String body = null; if (inputSupplier != null) { body = CharStreams.toString(CharStreams.newReaderSupplier(inputSupplier, Charsets.UTF_8)); } if (logBodyLimit > 0) { if (body != null && body.length() >= logBodyLimit) { body = body.substring(0, logBodyLimit) + " ... [TRIMMED]"; } LOG.info("Making request: {} {} - body: {}", httpRequest.getMethod(), httpRequest.getURL(), body); } else { // omit the body from being logged, if user doesn't explicitly request it LOG.info("Making request: {} {}", httpRequest.getMethod(), httpRequest.getURL()); } } catch (IOException e) { LOG.error("Failed to get body from http request: {} {}", httpRequest.getMethod(), httpRequest.getURL(), e); } } @Override public void onResponse(HttpRequest httpRequest, HttpResponse httpResponse, int i) { LOG.info("Received response: [{}] Response Body: {}", httpResponse.getResponseCode(), httpResponse.getResponseBodyAsString()); } }); return restClient; }
From source file:de.dentrassi.pm.sec.web.captcha.internal.RecaptchaService.java
@Override public CaptchaResult checkCaptcha(final HttpServletRequest request) { final String key = getRecaptcheSecretKey(); if (key == null) { return CaptchaResult.OK; }/*from ww w . j ava 2 s .co m*/ final String value = request.getParameter("g-recaptcha-response"); if (value == null || value.isEmpty()) { return CaptchaResult.errorResult("No captcha response"); } final HttpPost post = new HttpPost(); post.setURI(SITE_VERIFY_URI); try { final List<NameValuePair> params = new ArrayList<NameValuePair>(2); params.add(new BasicNameValuePair("secret", key)); params.add(new BasicNameValuePair("response", value)); post.setEntity(new UrlEncodedFormEntity(params, "UTF-8")); try (final CloseableHttpResponse result = this.client.execute(post)) { final HttpEntity ent = result.getEntity(); if (ent == null) { return CaptchaResult.errorResult("No response from captcha service"); } try (Reader r = new InputStreamReader(ent.getContent(), StandardCharsets.UTF_8)) { final String str = CharStreams.toString(r); final Gson g = makeGson(); final Response response = g.fromJson(str, Response.class); if (response.isSuccess()) { return CaptchaResult.OK; } else { return CaptchaResult.errorResult(response.getErrorCodes()); } } } } catch (final Exception e) { logger.warn("Failed to check captcha", e); return CaptchaResult.exceptionResult(e); } }