List of usage examples for com.google.common.io CharStreams toString
public static String toString(Readable r) throws IOException
From source file:org.apache.calcite.chinook.CalciteConnectionProvider.java
private String provideSchema() throws IOException { final InputStream stream = getClass().getResourceAsStream("/chinook/chinook.json"); return CharStreams.toString(new InputStreamReader(stream, Charsets.UTF_8)); }
From source file:org.n52.shetland.util.StringHelper.java
public static String convertStreamToString(InputStream is, String charset) throws IOException { try (InputStreamReader reader = new InputStreamReader(is, Strings.emptyToNull(charset))) { return CharStreams.toString(reader); } catch (IOException ex) { throw new IOException("Error while reading content of HTTP request", ex); }//from ww w . ja v a 2 s . c o m }
From source file:com.devbliss.doctest.items.ReportFileDocItem.java
public ReportFileDocItem(String css, String name, String introduction, String items) { this.css = css; this.name = name; this.items = items; this.introduction = introduction; this.date = new Date().toString(); try {//from www . j a va 2 s.c om StringBuffer stringBuffer = new StringBuffer(); InputStream jsStream = HtmlItems.class.getResourceAsStream(SCRIPT_JS_CLASSPATH_LOCATION); stringBuffer.append(CharStreams.toString(new InputStreamReader(jsStream))); jsStream = HtmlItems.class.getResourceAsStream(JQUERY_CLASSPATH_LOCATION); stringBuffer.append(CharStreams.toString(new InputStreamReader(jsStream))); this.jsCode = stringBuffer.toString(); } catch (IOException e) { this.jsCode = "no js"; } }
From source file:org.eclipse.mylyn.internal.bugzilla.rest.core.BugzillaRestValidateRequest.java
@Override protected ErrorResponse parseFromJson(InputStreamReader in) throws BugzillaRestException { String jsonString;//ww w . j a v a 2 s .c o m try { jsonString = CharStreams.toString(in); } catch (IOException e) { throw new BugzillaRestException(e); } if (jsonString.startsWith("{\"result\":{")) { //$NON-NLS-1$ jsonString = jsonString.substring(10, jsonString.length() - 1); } TypeToken<ErrorResponse> a = new TypeToken<ErrorResponse>() { }; return new Gson().fromJson(jsonString, a.getType()); }
From source file:io.jexiletools.es.modsmapping.ModsMapping.java
@SuppressWarnings("unchecked") private ModsMapping() { Gson gson = new Gson(); Map<String, Object> m = null; try (InputStreamReader isr = new InputStreamReader(ModsMapping.class.getResourceAsStream("/mods.json")) { }) {// w w w . j a va2s. c o m String s = CharStreams.toString(isr); s = s.replace("\\", "\\\\"); m = gson.fromJson(s, Map.class); } catch (IOException e) { throw new RuntimeException(e); } m = (Map<String, Object>) m.get("poe"); m = (Map<String, Object>) m.get("mappings"); m = (Map<String, Object>) m.get("item"); modMappings = m.entrySet().stream().map(e -> toMapping(e)).collect(Collectors.toList()); // the json mod mapping represents ranged mods as two, one for min and one for max // we only want one of the two, so let's clean // Remove DOUBLE_MAX mods modMappings = modMappings.stream().filter(mm -> mm.type != Type.DOUBLE_MAX).collect(Collectors.toList()); // Change DOUBLE_MIN mods to DOUBLE_MIN_MAX modMappings.stream().filter(mm -> mm.type == Type.DOUBLE_MIN).forEach(mm -> mm.type = Type.DOUBLE_MIN_MAX); // also add pseudo mods modMappings.add(new ModMapping("modsPseudo.eleResistSumChaos", "modsPseudo.eleResistSumChaos", "+#% to Lightning Chaos", Type.DOUBLE, ModType.PSEUDO, null)); modMappings.add(new ModMapping("modsPseudo.eleResistSumCold", "modsPseudo.eleResistSumCold", "+#% to Cold Resistance", Type.DOUBLE, ModType.PSEUDO, null)); modMappings.add(new ModMapping("modsPseudo.eleResistSumFire", "modsPseudo.eleResistSumFire", "+#% to Fire Resistance", Type.DOUBLE, ModType.PSEUDO, null)); modMappings.add(new ModMapping("modsPseudo.eleResistSumLightning", "modsPseudo.eleResistSumLightning", "+#% to Lightning Resistance", Type.DOUBLE, ModType.PSEUDO, null)); modMappings.add(new ModMapping("modsPseudo.eleResistTotal", "modsPseudo.eleResistTotal", "+#% total Elemental Resistance", Type.DOUBLE, ModType.PSEUDO, null)); modMappings.add(new ModMapping("modsPseudo.flatAttributesTotal", "modsPseudo.flatAttributesTotal", "+# to all Attributes", Type.DOUBLE, ModType.PSEUDO, null)); modMappings.add(new ModMapping("modsPseudo.flatSumDex", "modsPseudo.flatSumDex", "+# to Dexterity", Type.DOUBLE, ModType.PSEUDO, null)); modMappings.add(new ModMapping("modsPseudo.flatSumInt", "modsPseudo.flatSumInt", "+# to Intelligence", Type.DOUBLE, ModType.PSEUDO, null)); modMappings.add(new ModMapping("modsPseudo.flatSumStr", "modsPseudo.flatSumStr", "+# to Strength", Type.DOUBLE, ModType.PSEUDO, null)); modMappings.add(new ModMapping("modsPseudo.maxLife", "modsPseudo.maxLife", "+# to Maximum Life", Type.DOUBLE, ModType.PSEUDO, null)); }
From source file:com.google.dart.tools.core.html.Tokenizer.java
public Tokenizer(Reader reader) throws IOException { this(CharStreams.toString(reader)); reader.close(); }
From source file:jp.tomorrowkey.irkit4j.http.HttpResponse.java
public String getContent() throws IOException { int contentLength = httpURLConnection.getContentLength(); if (contentLength == 0) { return ""; }//from w w w .j ava2 s. c o m if (Strings.isNullOrEmpty(content)) { content = CharStreams.toString(new InputStreamReader(getInputStream())); } return content; }
From source file:org.deephacks.graphene.Http.java
private String request(String method, String path) { HttpURLConnection conn = null; try {// w w w. jav a 2 s. c om URL url = new URL(address + path); conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod(method); conn.setRequestProperty(CONTENT_TYPE, APPLICATION_JSON); conn.setDoOutput(true); try (OutputStream os = conn.getOutputStream()) { os.flush(); } if (conn.getResponseCode() >= BAD_REQUEST) { String body = CharStreams.toString(new InputStreamReader(conn.getErrorStream())); throw new RuntimeException("HTTP error code " + conn.getResponseCode() + ". " + conn.getResponseMessage() + ". " + body); } return CharStreams.toString(new InputStreamReader(conn.getInputStream())); } catch (IOException e) { throw new RuntimeException(e); } finally { if (conn != null) { conn.disconnect(); } } }
From source file:com.ning.billing.osgi.bundles.analytics.AnalyticsTestSuiteWithEmbeddedDB.java
public static String toString(final InputStream stream) throws IOException { final InputSupplier<InputStream> inputSupplier = new InputSupplier<InputStream>() { @Override/* w ww.j av a2s . c om*/ public InputStream getInput() throws IOException { return stream; } }; return CharStreams.toString(CharStreams.newReaderSupplier(inputSupplier, Charsets.UTF_8)); }
From source file:org.eclipse.scada.configuration.script.JSScriptParser.java
protected EObject parseContent(final InputStreamReader stream) throws IOException { final String value = CharStreams.toString(stream); final JavaScript script = ScriptFactory.eINSTANCE.createJavaScript(); script.setSource(value);/*from www . j av a2s. co m*/ return script; }