List of usage examples for com.google.common.io Resources toString
public static String toString(URL url, Charset charset) throws IOException
From source file:com.facebook.buck.ide.intellij.StringTemplateFile.java
public ST getST() throws IOException { URL templateUrl = Resources.getResource(StringTemplateFile.class, fileName); String template = Resources.toString(templateUrl, StandardCharsets.UTF_8); return new ST(template, DELIMITER, DELIMITER); }
From source file:at.ac.tuwien.auto.sewoa.xslt.XsltTransformer.java
public XsltTransformer(String xsltFile) { try {// ww w .j a v a2 s . c o m String xslt = Resources.toString(this.getClass().getResource("/" + xsltFile), Charset.defaultCharset()); this.xsltSource = new StreamSource(new StringReader(xslt)); } catch (IOException e) { e.printStackTrace(); } }
From source file:org.gbif.registry2.utils.JsonBackedData.java
private String getJson(String file) { try {/*from ww w .ja va 2s. c o m*/ return Resources.toString(Resources.getResource(file), Charsets.UTF_8); } catch (IOException e) { throw Throwables.propagate(e); } }
From source file:uk.co.baconi.substeps.restdriver.builders.impl.JsonFromUriRequestBodyBuilder.java
@Override public void build(final RequestSpecification request, final List<RequestBodyEntry> data) throws IOException { final FromUrlRequestBodyEntry fromUrl = verifyDataIs(data, FromUrlRequestBodyEntry.class).findFirst() .orElseThrow(() -> new AssertionError("Missing RequestBodyEntry of type FromUrlRequestBodyEntry.")); final String body = Resources.toString(fromUrl.getUrl(), Charset.forName("UTF-8")); request.contentType(ContentType.JSON).body(body); }
From source file:org.sonar.plugins.javascript.JavaScriptProfile.java
public static Set<String> activatedRuleKeys() { URL profileUrl = JavaScriptProfile.class .getResource("/org/sonar/l10n/javascript/rules/javascript/Sonar_way_profile.json"); try {/*from w w w . j ava 2s .com*/ Gson gson = new Gson(); return gson.fromJson(Resources.toString(profileUrl, Charsets.UTF_8), Profile.class).ruleKeys; } catch (IOException e) { throw new IllegalStateException("Failed to read: " + profileUrl, e); } }
From source file:org.graylog2.web.resources.AppConfigResource.java
@GET @Produces(MoreMediaTypes.APPLICATION_JAVASCRIPT) public String get(@Context HttpHeaders headers) { final URL templateUrl = this.getClass().getResource("/web-interface/config.js.template"); final String template; try {// w w w . j ava2 s. c o m template = Resources.toString(templateUrl, StandardCharsets.UTF_8); } catch (IOException e) { throw new RuntimeException( "Unable to read AppConfig template while generating web interface configuration: ", e); } final Map<String, Object> model = ImmutableMap.of("rootTimeZone", configuration.getRootTimeZone(), "serverUri", RestTools.buildEndpointUri(headers, configuration.getWebEndpointUri()), "appPathPrefix", configuration.getWebPrefix()); return engine.transform(template, model); }
From source file:li.klass.fhem.service.room.xmllist.Sanitiser.java
@Inject public Sanitiser() { try {/*from www .j ava 2s.c om*/ options = new JSONObject(Resources .toString(Resources.getResource(Sanitiser.class, "deviceSanitiser.json"), Charsets.UTF_8)); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:me.j360.trace.storage.elasticsearch.LazyClient.java
LazyClient(ElasticsearchStorage.Builder builder) { this.clusterName = builder.cluster; this.hosts = builder.hosts; try {/*from w w w. j a v a 2 s . c o m*/ this.indexTemplate = Resources .toString(Resources.getResource("zipkin_template.json"), StandardCharsets.UTF_8) .replace("${__INDEX__}", builder.index) .replace("${__NUMBER_OF_SHARDS__}", String.valueOf(builder.indexShards)) .replace("${__NUMBER_OF_REPLICAS__}", String.valueOf(builder.indexReplicas)); } catch (IOException e) { throw new AssertionError("Error reading jar resource, shouldn't happen.", e); } }
From source file:ratpack.groovy.internal.GroovyVersionCheck.java
@Nullable public static String maybeLoadMinimumGroovyVersion() { URL resource = GroovyVersionCheck.class.getClassLoader().getResource("ratpack/minimum-groovy-version.txt"); try {// w w w .ja va2 s . co m return resource == null ? null : Resources.toString(resource, Charsets.UTF_8); } catch (IOException e) { return null; } }
From source file:org.jclouds.scriptbuilder.functionloader.BasicFunctionLoader.java
/** * Loads a function from the classpath using the current or the Thread Context Class Loader. * /*from www . j a va 2s .c o m*/ * @param function * The function name to load. * @param family * This operating system family of the function. * @return The function as {@link String} * @throws FunctionNotFoundException */ @Override public String loadFunction(String function, OsFamily family) throws FunctionNotFoundException { try { return Resources.toString( getResource(BasicFunctionLoader.class, format("/functions/%s.%s", function, SH.to(family))), UTF_8); } catch (IOException e) { throw new FunctionNotFoundException(function, family, e); } }