List of usage examples for com.google.common.io CharStreams toString
public static String toString(Readable r) throws IOException
From source file:org.onosproject.cordvtn.RemoteIpCommandUtil.java
/** * Executes a given command. It opens exec channel for the command and closes * the channel when it's done./*from ww w . j a v a 2 s.c o m*/ * * @param session ssh connection to a remote server * @param command command to execute * @return command output string if the command succeeds, or null */ private static String executeCommand(Session session, String command) { if (session == null || !session.isConnected()) { return null; } log.trace("Execute command {} to {}", command, session.getHost()); try { Channel channel = session.openChannel("exec"); ((ChannelExec) channel).setCommand(command); channel.setInputStream(null); InputStream output = channel.getInputStream(); channel.connect(); String result = CharStreams.toString(new InputStreamReader(output)); channel.disconnect(); return result; } catch (JSchException | IOException e) { log.debug("Failed to execute command {} due to {}", command, e.toString()); return null; } }
From source file:org.obm.push.mail.ReplyEmail.java
@VisibleForTesting String getBodyValue(MSEmailBodyType bodyType, Map<MSEmailBodyType, EmailView> originMails) throws UnsupportedEncodingException, IOException { EmailView originalPlainTextEmail = originMails.get(bodyType); if (originalPlainTextEmail != null && originalPlainTextEmail.getBodyMimePartData().isPresent()) { String charset = Objects.firstNonNull(originalPlainTextEmail.getCharset(), DEFAULT_CHARSET.name()); return CharStreams .toString(new InputStreamReader(originalPlainTextEmail.getBodyMimePartData().get(), charset)); }/*from w w w. ja va 2 s . c om*/ return null; }
From source file:org.icgc.dcc.portal.resource.ui.UISearchResource.java
@Path("/file") @Consumes(MULTIPART_FORM_DATA)//from w w w . jav a 2 s .c o m @POST public Map<String, String> uploadIds(@FormDataParam("filepath") InputStream inputStream, @FormDataParam("filepath") FormDataContentDisposition fileDetail) throws Exception { log.info("Input stream {}", inputStream); log.info("Content disposition {}", fileDetail); val content = CharStreams.toString(new InputStreamReader(inputStream, UTF_8)); return ImmutableMap.of("data", content); }
From source file:org.fenixedu.idcards.ui.ManageSantanderCardGenerationDA.java
private String readFile(OpenFileBean dchpFileBean) throws IOException { return CharStreams.toString(new InputStreamReader(dchpFileBean.getInputStream(), Charsets.UTF_8)); }
From source file:org.kuali.ole.web.LicenseRestServlet.java
private String updateLicenses(HttpServletRequest req) throws IOException { DocstoreService ds = BeanLocator.getDocstoreService(); String requestBody = CharStreams.toString(req.getReader()); Licenses licenses = (Licenses) Licenses.deserialize(requestBody); ds.updateLicenses(licenses);// w w w . j a v a 2 s. c o m return ""; }
From source file:org.itcollege.valge.licenseaudit.LicenseAuditMojo.java
String getHtmlContent(ReportData reportData, ConfigData configData) throws IOException, JsonProcessingException { InputStream in = getClass().getResourceAsStream("/report.html"); String templateContent = CharStreams.toString(new InputStreamReader(in)); ObjectMapper mapper = new ObjectMapper(); return templateContent.replace("<REPORT_DATA>", mapper.writeValueAsString(reportData)) .replace("<CONFIG_DATA>", mapper.writeValueAsString(configData)); }
From source file:org.wahlzeit.servlets.MainServlet.java
/** * Searches for files in the request and puts them in the resulting map with the key "fileName". When a file is * found, you can access its path by searching for elements with the key "fileName". *///from www . ja v a2s . c o m protected Map getMultiPartRequestArgs(HttpServletRequest request, UserSession us) throws IOException, ServletException { Map<String, String> result = new HashMap<String, String>(); result.putAll(request.getParameterMap()); try { ServletFileUpload upload = new ServletFileUpload(); FileItemIterator iterator = upload.getItemIterator(request); while (iterator.hasNext()) { FileItemStream fileItemStream = iterator.next(); String filename = fileItemStream.getName(); if (!fileItemStream.isFormField()) { InputStream inputStream = fileItemStream.openStream(); Image image = getImage(inputStream); User user = (User) us.getClient(); user.setUploadedImage(image); result.put("fileName", filename); log.config( LogBuilder.createSystemMessage().addParameter("Uploaded image", filename).toString()); } else { String key = fileItemStream.getFieldName(); InputStream is = fileItemStream.openStream(); String value = CharStreams.toString(new InputStreamReader(is, Charsets.UTF_8)); result.put(key, value); log.config(LogBuilder.createSystemMessage().addParameter("Key of uploaded parameter", key) .addParameter("value", value).toString()); } } } catch (Exception ex) { throw new ServletException(ex); } return result; }
From source file:co.cask.hydrator.plugin.dataset.SnapshotFileSet.java
private Long getLatestSnapshot() throws IOException { Location stateFile = files.getEmbeddedFileSet().getBaseLocation().append(STATE_FILE_NAME); if (!stateFile.exists()) { return null; }/*from w w w .j a v a2 s.c o m*/ try (InputStreamReader reader = new InputStreamReader(stateFile.getInputStream(), Charsets.UTF_8)) { String val = CharStreams.toString(reader); return Long.valueOf(val); } }
From source file:com.github.sdbg.debug.ui.internal.chromeapp.ChromeAppLaunchShortcut.java
/** * Do a best effort to extract the "name" field out of a manifest.json file. On any failure, * return null.// w w w. j a v a2 s . co m */ private String parseNameFromJson(IResource resource) { if (!(resource instanceof IFile)) { return null; } try { IFile file = (IFile) resource; String text = CharStreams.toString(new InputStreamReader(file.getContents(), Charsets.UTF_8)); JSONObject obj = new JSONObject(text); return obj.optString("name", null); } catch (IOException ioe) { } catch (CoreException e) { } catch (JSONException e) { } return null; }
From source file:eu.cloudwave.wp5.feedback.eclipse.tests.fixtures.base.JavaProjectFixture.java
private String getResourceAsString(final String path) throws UnsupportedEncodingException, IOException { final InputStream is = getClass().getResourceAsStream(path); return CharStreams.toString(new InputStreamReader(is, UTF_8)); }