Example usage for com.google.common.io Resources toString

List of usage examples for com.google.common.io Resources toString

Introduction

In this page you can find the example usage for com.google.common.io Resources toString.

Prototype

public static String toString(URL url, Charset charset) throws IOException 

Source Link

Document

Reads all characters from a URL into a String , using the given character set.

Usage

From source file:org.openhab.binding.netatmo.internal.messages.MeasurementRequestStub.java

private MeasurementRequestStub(final String response) throws Exception {
    super(ACCESS_TOKEN, DEVICE_ID, MODULE_ID);

    final URL resource = getClass().getResource(response);

    if (resource == null) {
        throw new IOException("Resource '" + response + "' not found!");
    }/*from w ww.  j a va  2s .c  o m*/

    this.response = Resources.toString(resource, UTF_8);

}

From source file:org.openhab.binding.netatmo.internal.messages.RefreshTokenRequestStub.java

private RefreshTokenRequestStub(final String response) throws Exception {
    super(CLIENT_ID, CLIENT_SECRET, REFRESH_TOKEN);

    final URL resource = getClass().getResource(response);

    if (resource == null) {
        throw new IOException("Resource '" + response + "' not found!");
    }/*from ww w  . ja v a 2 s  . c  o  m*/

    this.response = Resources.toString(resource, UTF_8);
}

From source file:zipkin.storage.elasticsearch.LazyClient.java

LazyClient(ElasticsearchStorage.Builder builder) {
    this.clientFactory = builder.clientBuilder.buildFactory();
    this.indexTemplateName = builder.index + "_template"; // should be 1:1 with indices
    this.allIndices = new IndexNameFormatter(builder.index).catchAll();
    try {//from   w  w  w  . ja v  a 2 s  .  co  m
        this.indexTemplate = Resources
                .toString(Resources.getResource("zipkin/storage/elasticsearch/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))
                .replace("${__TRACE_ID_MAPPING__}", builder.strictTraceId ? "{ KEYWORD }"
                        : "{ \"type\": \"string\", \"analyzer\": \"traceId_analyzer\" }");
    } catch (IOException e) {
        throw new AssertionError("Error reading jar resource, shouldn't happen.", e);
    }
}

From source file:org.apache.isis.schema.utils.ChangesDtoUtils.java

public static ChangesDto fromXml(final Class<?> contextClass, final String resourceName, final Charset charset)
        throws IOException {
    final URL url = Resources.getResource(contextClass, resourceName);
    final String s = Resources.toString(url, charset);
    return fromXml(new StringReader(s));
}

From source file:com.google.api.tools.framework.model.testing.ClassPathTestDataLocator.java

@Override
public String fetchTestData(URL url) {
    try {//from  ww w  .ja  v  a 2s . c o  m
        return Resources.toString(url, StandardCharsets.UTF_8);
    } catch (IOException e) {
        throw new IllegalArgumentException(String.format("Cannot read resource '%s': %s", url, e.getMessage()));
    }
}

From source file:org.eclipse.rcptt.ui.editors.ecl.EclInformationContol.java

private static String loadStyles() {
    if (styles != null)
        return styles;

    try {//w w  w  .  j  a v a  2 s . c  o m
        URL url = Q7UIPlugin.getDefault().getBundle().getResource("/docs.css");
        // Check for missing styles resource.
        if (url == null) {
            return styles = "";
        }
        return styles = Resources.toString(url, Charsets.UTF_8);
    } catch (IOException e) {
        Q7UIPlugin.log(e);
        return styles = "";
    }
}

From source file:org.openhab.binding.netatmo.internal.authentication.RefreshTokenRequestStub.java

private RefreshTokenRequestStub(final String response) throws Exception {
    super(CLIENT_ID, CLIENT_SECRET, REFRESH_TOKEN, true, true);

    final URL resource = getClass().getResource(response);

    if (resource == null) {
        throw new IOException("Resource '" + response + "' not found!");
    }/*from  ww  w .  j  a v a  2s .co  m*/

    this.response = Resources.toString(resource, UTF_8);
}

From source file:org.apache.aurora.scheduler.TierModule.java

static String readTierFile() {
    try {//from w ww .  ja  va2  s  .  c o  m
        return TIER_CONFIG_FILE.hasAppliedValue()
                ? Files.toString(TIER_CONFIG_FILE.get(), StandardCharsets.UTF_8)
                : Resources.toString(TierModule.class.getClassLoader().getResource(TIER_CONFIG_PATH),
                        StandardCharsets.UTF_8);
    } catch (IOException e) {
        LOG.error("Error loading tier configuration file.");
        throw new RuntimeException(e);
    }
}

From source file:org.devacfr.testing.util.Approvals.java

private static String readFile(final Path path) {
    try {/* w w w  . j av a  2  s  . c  o  m*/
        return Resources.toString(Resources.getResource(path.toString()), Charsets.UTF_8);
    } catch (final IOException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}

From source file:org.graylog2.web.IndexHtmlGenerator.java

@Inject
public IndexHtmlGenerator(PluginAssets pluginAssets, Configuration configuration) throws IOException {
    this.configuration = configuration;
    final URL templateUrl = this.getClass().getResource("/web-interface/index.html.template");
    final String template = Resources.toString(templateUrl, StandardCharsets.UTF_8);
    final Map<String, Object> model = new HashMap<String, Object>() {
        {//from   w ww .  jav  a  2s . c  o m
            put("title", title);
            put("cssFiles", pluginAssets.cssFiles());
            put("jsFiles", pluginAssets.sortedJsFiles());
            put("appPrefix", configuration.getWebPrefix());
        }
    };

    this.content = engine.transform(template, model);
}