List of usage examples for com.google.common.io CharStreams toString
public static String toString(Readable r) throws IOException
From source file:tech.tablesaw.io.csv.CsvReader.java
/** * Determines column types if not provided by the user * Reads all input into memory unless File was provided *///from w ww. j a va 2s . co m private Pair<Reader, ColumnType[]> getReaderAndColumnTypes(Source source, CsvReadOptions options) throws IOException { ColumnType[] types = options.columnTypes(); byte[] bytesCache = null; if (types == null) { Reader reader = source.createReader(bytesCache); if (source.file() == null) { bytesCache = CharStreams.toString(reader).getBytes(); // create a new reader since we just exhausted the existing one reader = source.createReader(bytesCache); } types = detectColumnTypes(reader, options); } return Pair.create(source.createReader(bytesCache), types); }
From source file:com.google.enterprise.connector.db.InputStreamFactories.java
/** Fully reads an input stream from the factory and Base64 encodes it. */ public static final String toBase64String(InputStreamFactory factory) throws IOException { return CharStreams.toString( new InputStreamReader(new Base64FilterInputStream(factory.getInputStream()), Charsets.UTF_8)); }
From source file:com.codemarvels.boshservlet.BoshXmppServlet.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try {// w ww. j a va 2s .co m DocumentBuilderFactory fac = DocumentBuilderFactory.newInstance(); DocumentBuilder db = fac.newDocumentBuilder(); InputSource inStream = new InputSource(); String requestXML = CharStreams.toString(request.getReader()); inStream.setCharacterStream(new StringReader(requestXML)); Document doc = db.parse(inStream); connectionManager.handleRequest(doc, response, request); } catch (SAXException e) { response.sendError(HttpServletResponse.SC_BAD_REQUEST); } catch (Exception e) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); } }
From source file:com.mstiles92.plugins.bookrules.localization.LocalizationHandler.java
/** * Load the selected language from the language file stored within the jar. * * @param language the language to load/*from ww w . j a va 2s. c o m*/ * @return true if loading succeeded, false if it failed */ public boolean loadLocalization(Language language) { String contents; InputStream in = LocalizationHandler.class.getResourceAsStream(language.getPath()); try { contents = CharStreams.toString(new InputStreamReader(in, "UTF-8")); } catch (IOException e) { return false; } JSONParser parser = new JSONParser(); Object obj = null; try { obj = parser.parse(contents); } catch (ParseException e) { e.printStackTrace(); } if (obj == null) { return false; } else { this.jsonObject = (JSONObject) obj; return true; } }
From source file:com.android.builder.internal.TemplateProcessor.java
/** * Reads and returns the content of a text file embedded in the jar file. * @param templateStream the stream to read the template file from * @return null if the file could not be read * @throws java.io.IOException/*from w ww . j a v a2 s . com*/ */ private String readEmbeddedTextFile(InputStream templateStream) throws IOException { InputStreamReader reader = new InputStreamReader(templateStream, Charsets.UTF_8); try { return CharStreams.toString(reader); } finally { reader.close(); } }
From source file:biz.turnonline.ecosystem.origin.frontend.page.Home.java
public Home() { add(new ExternalLink("link-gcloud", "") { @Override//from w w w . jav a 2s . c o m protected void onInitialize() { super.onInitialize(); String gcloudUrl = "https://console.cloud.google.com/home/dashboard?project=" + projectId; setDefaultModelObject(gcloudUrl); setBody(Model.of(gcloudUrl)); } }); add(new ExternalLink("link-firebase", "") { @Override protected void onInitialize() { super.onInitialize(); String gcloudUrl = "https://console.firebase.google.com/u/0/project/" + projectId + "/authentication/users"; setDefaultModelObject(gcloudUrl); setBody(Model.of(gcloudUrl)); } }); InputStream identityPropertiesContentStream = Home.class .getResourceAsStream(API_CREDENTIAL_LOADER.getConfigurationFilePath()); String identityPropertiesContent; try { identityPropertiesContent = CharStreams .toString(new InputStreamReader(identityPropertiesContentStream, Charsets.UTF_8)); } catch (IOException e) { e.printStackTrace(); identityPropertiesContent = "Error unable to load /api.properties"; } add(new Label("identity-properties", identityPropertiesContent)); }
From source file:net.oneandone.maven.plugins.billofmaterials.AbstractGetReleaseMojo.java
String getLatestVersion(final String repositories) throws MojoExecutionException { final String repositoryString = getRepositoryString(repositories); final URI resolveURI = searchBase .resolve("?g=" + project.getGroupId() + "&a=" + project.getArtifactId() + repositoryString); getLog().info("resolveURI=" + resolveURI); final String latestVersion; try {//www. j a va2 s . c om final URL url = resolveURI.toURL(); InputStream in = getInputStream(url); try { latestVersion = CharStreams.toString(new InputStreamReader(in, Charset.forName("UTF-8"))); } finally { in.close(); } } catch (IOException e) { throw new MojoExecutionException("Can not get " + resolveURI, e); } getLog().info("latestVersion=" + latestVersion + " from repositories='" + repositories + "'"); return latestVersion; }
From source file:net.kebernet.skillz.format.ConstantBundle.java
private static String readFromResource(String resourceBaseName, String languageCode, String fileType) { URL url = null;/*from ww w. ja va 2s . c o m*/ try { url = ConstantBundle.class.getResource(resourceBaseName + "." + languageCode + "." + fileType); url = url == null ? ConstantBundle.class.getResource(resourceBaseName + "." + fileType) : url; if (url != null) { return CharStreams.toString(new InputStreamReader(url.openStream(), "utf-8")); } } catch (IOException e) { LOGGER.log(Level.WARNING, "Failed to parse " + url.toExternalForm(), e); } return null; }
From source file:io.kubernetes.client.util.WebSocketStreamHandler.java
@Override public void textMessage(Reader in) { try {//from w ww . j a va2 s. c o m OutputStream out = getSocketInputOutputStream(in.read()); InputStream inStream = new ByteArrayInputStream(CharStreams.toString(in).getBytes(Charsets.UTF_8)); ByteStreams.copy(inStream, out); } catch (IOException ex) { log.error("Error writing message", ex); } }
From source file:com.spotify.heroic.metric.datastax.schema.AbstractCassandraSchema.java
private String loadTemplate(final String path, final Map<String, String> values) throws IOException { final String string; final ClassLoader loader = ManagedSetupConnection.class.getClassLoader(); try (final InputStream is = loader.getResourceAsStream(path)) { if (is == null) { throw new IOException("No such resource: " + path); }/*ww w. j ava 2 s. c o m*/ string = CharStreams.toString(new InputStreamReader(is, Charsets.UTF_8)); } return new StrSubstitutor(values, "{{", "}}").replace(string); }