List of usage examples for com.google.common.io CharStreams toString
public static String toString(Readable r) throws IOException
From source file:org.eclipse.scada.configuration.world.lib.deployment.Contents.java
public static ContentProvider createContent(final InputStream resource, final Map<String, String> replacements, final Pattern pattern) throws IOException { try {/*from w ww . j a v a2s.c o m*/ String str = CharStreams.toString(new InputStreamReader(resource, StandardCharsets.UTF_8)); str = StringReplacer.replace(str, StringReplacer.newSource(replacements), pattern); return new StaticContentProvider(str); } finally { resource.close(); } }
From source file:org.eclipse.packagedrone.repo.aspect.PropertiesHelper.java
public static String loadUrl(final Bundle bundle, final String descUrl) { if (descUrl == null) { return null; }//from w ww .jav a 2s . co m final URL url = bundle.getEntry(descUrl); if (url == null) { return null; } try (Reader reader = new InputStreamReader(url.openStream(), StandardCharsets.UTF_8)) { return CharStreams.toString(reader); } catch (final Exception e) { logger.info("Failed to load url", e); } return null; }
From source file:co.marcin.novaguilds.util.IOUtils.java
public static String inputStreamToString(InputStream inputStream) throws IOException { return CharStreams.toString(new InputStreamReader(inputStream, "UTF-8")); }
From source file:com.google.cloud.tools.gradle.appengine.AssertConnection.java
/** Connect and assert response is as expected. */ public static void assertResponse(String url, int expectedCode, String expectedText) { try {/* www.j ava 2 s .c om*/ HttpURLConnection urlConnection = (HttpURLConnection) new URL(url).openConnection(); int responseCode = urlConnection.getResponseCode(); Assert.assertEquals(expectedCode, responseCode); String response = CharStreams.toString(new InputStreamReader(urlConnection.getInputStream())); Assert.assertThat(response, CoreMatchers.equalTo(expectedText)); } catch (IOException e) { Assert.fail("IOException while running test"); } }
From source file:bwfla.modules.pdp.client.Helper.java
/** * Load a file from a local folder/*from ww w. j a v a 2s . co m*/ * * @param path * The file's path e.g. "example/example-policy.xml" * @return the file's content in a string */ public static String loadContentFromFile(@NonNull String path) { try (InputStream requestIn = Helper.class.getClassLoader().getResourceAsStream(path)) { if (requestIn == null) throw new IOException(); return CharStreams.toString(new InputStreamReader(requestIn, "UTF-8")); } catch (IOException e) { log.error("Could not file from path: " + path, e); return null; } }
From source file:dollar.plugins.pipe.GitUtil.java
public static void check() throws IOException, InterruptedException { ProcessBuilder pb = new ProcessBuilder("git", "--version"); Process p = pb.start();/* w ww . ja v a2 s . c o m*/ p.waitFor(); String version = CharStreams.toString(new InputStreamReader(p.getInputStream())); if (!version.split("\n")[0].matches("^git version [2|3]\\.\\d\\d.*")) { throw new DollarException( "Git is not installed, please install git version 2.x or later, result from check was " + version); } }
From source file:org.roda.wui.common.HTMLUtils.java
public static String descriptiveMetadataToHtml(Binary binary, String metadataType, String metadataVersion, final Locale locale) throws GenericException { Map<String, String> translations = getTranslations(metadataType, metadataVersion, locale); Reader reader = RodaUtils.applyMetadataStylesheet(binary, RodaConstants.CROSSWALKS_DISSEMINATION_HTML_PATH, metadataType, metadataVersion, translations); try {//from w w w .j a va 2 s . com return CharStreams.toString(reader); } catch (IOException e) { throw new GenericException("Could not transform PREMIS to HTML", e); } }
From source file:com.freiheit.fuava.simplebatch.util.IOStreamUtils.java
/** * Read and close the given stream, returning the string. Note that the * stream is assumed to be UTF-8 encoded. * //from ww w . ja v a2 s .c om */ public static String consumeAsString(final InputStream istream) throws FetchFailedException { try { try (InputStream stream = istream) { return CharStreams.toString(new InputStreamReader(stream, Charsets.UTF_8)); } } catch (final IOException e) { throw new FetchFailedException(e); } }
From source file:cd.go.contrib.elasticagents.docker.utils.Util.java
public static String readResource(String resourceFile) { try (InputStreamReader reader = new InputStreamReader( GetViewRequestExecutor.class.getResourceAsStream(resourceFile), StandardCharsets.UTF_8)) { return CharStreams.toString(reader); } catch (IOException e) { throw new RuntimeException("Could not find resource " + resourceFile, e); }/*from w ww . java 2s . c o m*/ }
From source file:org.apache.beam.runners.core.construction.UrnUtils.java
private static Set<String> extractUrnsFromPath(String path) { String contents;/*from ww w . j a v a2 s . c o m*/ try { contents = CharStreams .toString(new InputStreamReader(UrnUtils.class.getClassLoader().getResourceAsStream(path))); } catch (IOException exn) { throw new RuntimeException(exn); } Set<String> urns = new HashSet<>(); Matcher m = URN_REGEX.matcher(contents); while (m.find()) { urns.add(m.group()); } return urns; }