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.apache.hive.ptest.execution.Templates.java

public static String readResource(String resource) throws IOException {
    return Resources.toString(Resources.getResource(resource), Charsets.UTF_8);
}

From source file:org.jclouds.openstack.nova.live.PropertyHelper.java

public static Map<String, String> setupKeyPair(Properties properties)
        throws FileNotFoundException, IOException {
    return ImmutableMap.<String, String>of("private",
            Resources.toString(Resources.getResource(properties.getProperty("test.ssh.keyfile.private")),
                    Charsets.UTF_8),//from w ww . j  a va  2 s  .  c  om
            "public", Resources.toString(
                    Resources.getResource(properties.getProperty("test.ssh.keyfile.public")), Charsets.UTF_8));
}

From source file:se.kth.karamel.client.api.CookbookCacheImplIT.java

@Ignore
public void testLoadCookbooks() throws IOException, KaramelException {
    CookbookCacheIml cache = new CookbookCacheIml();
    String ymlString = Resources.toString(
            Resources.getResource("se/kth/karamel/client/model/test-definitions/hopsworks_compact.yml"),
            Charsets.UTF_8);//w  w w . jav  a 2 s . co m
    YamlCluster cluster = ClusterDefinitionService.yamlToYamlObject(ymlString);
    List<KaramelizedCookbook> all = cache.loadAllKaramelizedCookbooks(cluster);
    for (KaramelizedCookbook kc : all) {
        System.out.println(kc.getUrls().id);
    }
}

From source file:foo.domaintest.landing.LandingAction.java

private static String loadTemplate() {
    try {/*from  w w  w  .  ja  v  a2  s.c  o m*/
        return Resources.toString(getResource(LandingAction.class, "template.html"), UTF_8);
    } catch (IOException e) {
        throw new ExceptionInInitializerError(e);
    }
}

From source file:org.apache.samza.sql.samples.system.OrdersStreamSystemFactory.java

private static String loadOrdersSchema() throws IOException {
    return Resources.toString(OrdersStreamSystemFactory.class.getResource("/orders_avro.avsc"),
            Charset.defaultCharset());
}

From source file:hmi.animation.RenamingMap.java

public static BiMap<String, String> renamingMapFromFileOnClasspath(String filename) throws IOException {
    return renamingMap(Resources.toString(Resources.getResource(filename), Charsets.UTF_8));
}

From source file:org.apache.provisionr.core.Mustache.java

/**
 * Render a Mustache template as a String
 *
 * @param resource url to resource/*from w w w .j a va 2 s .  c  o  m*/
 * @param scopes
 * @return
 * @throws IOException
 */
public static String toString(URL resource, Map<String, ?> scopes) throws IOException {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    Writer writer = new OutputStreamWriter(outputStream, Charsets.UTF_8);

    String content = Resources.toString(resource, Charsets.UTF_8);

    MustacheFactory factory = new DefaultMustacheFactory();
    factory.compile(new StringReader(content), resource.toString()).execute(writer, scopes);

    writer.close();
    return outputStream.toString("UTF-8");
}

From source file:org.apache.isis.viewer.wicket.ui.components.about.AboutPanelFactory.java

private static String versionFromManifest() {
    try {//from  www  .  java2 s .  co  m
        return Resources.toString(Resources.getResource(META_INF_POM_PROPERTIES), Charset.defaultCharset());
    } catch (final Exception ex) {
        return "UNKNOWN";
    }
}

From source file:org.sonarsource.sonarlint.core.util.VersionUtils.java

@VisibleForTesting
static String getLibraryVersionFallback() {
    String version = "unknown";
    URL resource = VersionUtils.class.getResource("/sl_core_version.txt");
    if (resource != null) {
        try {/*  www  .jav  a2  s.c  o  m*/
            version = Resources.toString(resource, StandardCharsets.UTF_8);
        } catch (IOException e) {
            return version;
        }
    }

    return version;
}

From source file:com.jdom.mediadownloader.services.UrlDownload.java

@Override
public String downloadUrlContents(String path) throws IOException {
    return Resources.toString(new URL(path), Charset.defaultCharset());
}