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.utils.Helper.java
protected static void createFile(final File file, final InputStream resource, final Map<String, String> replacements, final IProgressMonitor monitor, final Pattern pattern) throws Exception { try {/*from w w w .j av a2 s . co m*/ String str = CharStreams.toString(new InputStreamReader(resource, StandardCharsets.UTF_8)); str = StringReplacer.replace(str, StringReplacer.newSource(replacements), pattern); createFile(file, str, monitor); } finally { resource.close(); } }
From source file:co.freeside.betamax.encoding.AbstractEncoder.java
public final String decode(InputStream input, String charset) { try {/*from w w w .jav a2s . c o m*/ return CharStreams.toString(new InputStreamReader(getDecodingInputStream(input), charset)); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.spotify.heroic.suggest.elasticsearch.ElasticsearchSuggestUtils.java
public static Map<String, Object> loadJsonResource(String path, Function<String, String> replace) { final String fullPath = ElasticsearchSuggestModule.class.getPackage().getName() + "/" + path; try (final InputStream input = ElasticsearchSuggestModule.class.getClassLoader() .getResourceAsStream(fullPath)) { if (input == null) { throw new IllegalArgumentException("No such resource: " + fullPath); }/*from ww w. j a v a 2s . co m*/ final String content = replace .apply(CharStreams.toString(new InputStreamReader(input, Charsets.UTF_8))); return JsonXContent.jsonXContent.createParser(NamedXContentRegistry.EMPTY, content).map(); } catch (final IOException e) { throw new RuntimeException("Failed to load json resource: " + path); } }
From source file:com.google.gxp.compiler.codegen.BaseCodeGenerator.java
/** * Loads a .format resource relative to /com/google/gxp/compiler/ and * returns the contents as a {@code String}. */// w ww.j ava 2 s . c o m protected static String loadFormat(String name) { String resourceName = "/com/google/gxp/compiler/" + name + ".format"; InputStream stream = BaseCodeGenerator.class.getResourceAsStream(resourceName); try { if (stream == null) { throw new FileNotFoundException("Can't load resource " + resourceName); } return CharStreams.toString(new InputStreamReader(stream, Charsets.US_ASCII)).trim(); } catch (IOException e) { // If this happens then something is seriously broken. throw new RuntimeException(e); } }
From source file:de.dentrassi.pm.jenkins.AbstractUploader.java
protected static String makeString(final HttpEntity entity) throws IOException { final InputStreamReader reader = new InputStreamReader(entity.getContent(), UTF_8); try {//w w w . j a va2 s .c o m return CharStreams.toString(reader).trim(); } finally { reader.close(); } }
From source file:org.apache.gearpump.cluster.utils.SystemOperation.java
public static String exec(String cmd) throws IOException { LOG.debug("Shell cmd: " + cmd); Process process = new ProcessBuilder(new String[] { "/bin/bash", "-c", cmd }).start(); try {//from w w w. j a v a 2 s .co m process.waitFor(); String output = CharStreams.toString(new InputStreamReader(process.getInputStream())); String errorOutput = CharStreams.toString(new InputStreamReader(process.getErrorStream())); LOG.debug("Shell Output: " + output); if (errorOutput.length() != 0) { LOG.error("Shell Error Output: " + errorOutput); throw new IOException(errorOutput); } return output; } catch (InterruptedException ie) { throw new IOException(ie.toString()); } }
From source file:org.seedstack.io.fixture.CustomParser.java
@Override public List<T> parse(InputStream inputStream, Class<T> clazz) { String data = null;//from www . j av a 2 s.c o m try { InputStreamReader r = new InputStreamReader(inputStream, "UTF-8"); data = CharStreams.toString(r); r.close(); } catch (IOException e) { e.printStackTrace(); } finally { try { inputStream.close(); } catch (IOException e) { e.printStackTrace(); } } String[] split = data.split("-"); List<T> result = new ArrayList<T>(); result.add((T) new BeanDTO(split[0], split[1])); return result; }
From source file:com.twitter.hbc.twitter4j.ResourceReader.java
final String readFile(String filename) throws IOException { InputStream stream = getClass().getClassLoader().getResourceAsStream(filename); try {/*from w w w . ja v a 2 s . c om*/ return CharStreams.toString(new InputStreamReader(stream)); } finally { stream.close(); } }
From source file:org.opendaylight.protocol.bgp.util.HexDumpBGPFileParser.java
public static List<byte[]> parseMessages(final InputStream is) throws IOException { Preconditions.checkNotNull(is);// www . j av a2 s. c o m try (InputStreamReader isr = new InputStreamReader(is, "UTF-8")) { return parseMessages(CharStreams.toString(isr)); } finally { is.close(); } }
From source file:edu.cmu.lti.oaqa.ecd.config.ConfigurationLoader.java
public static String getString(String resource) throws IOException { String resourceLocation = ConfigurationLoader.getResourceLocation(resource, true); InputStream in = ConfigurationLoader.class.getResourceAsStream(resourceLocation); try {/*from w ww . j a v a2 s .c o m*/ Reader reader = new InputStreamReader(in); return CharStreams.toString(reader); } finally { in.close(); } }