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

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

Introduction

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

Prototype

public static URL getResource(String resourceName) 

Source Link

Document

Returns a URL pointing to resourceName if the resource is found using the Thread#getContextClassLoader() context class loader .

Usage

From source file:common.InitialData.java

static TakepublishedRecord take(DSLContext dsl, Time time, int user, String title, String factTitleSlug)
        throws IOException {
    TakepublishedRecord record = takeInternal(dsl, time, user, title);
    String jsonData = Resources.toString(
            Resources.getResource("initialdata/" + record.getTitleSlug() + ".json"), StandardCharsets.UTF_8);
    record.setBlocks(jsonData);// w w w  .jav a2s  .  c  o  m
    record.setImageUrl(factTitleSlug);
    record.insert();
    return record;
}

From source file:org.obm.sync.H2GuiceServletContextListener.java

private List<String> getAdditionalDBScripts() throws Exception {
    try {/*from w  w  w  . ja  v  a 2 s.c o m*/
        return Resources.asCharSource(Resources.getResource(ADDITIONAL_DB_SCRIPTS_FILE), Charsets.UTF_8)
                .readLines();
    } catch (IllegalArgumentException e) {
        return ImmutableList.of();
    }
}

From source file:org.apache.crunch.test.TemporaryPath.java

private static void copy(String resourceName, File dest) throws IOException {
    Resources.asByteSource(Resources.getResource(resourceName)).copyTo(Files.asByteSink(dest));
}

From source file:com.sangupta.andruil.Andruil.java

/**
 * /*  w  w w .j  a v a2 s  .c  om*/
 * @return
 */
private static JavaPackage[] loadExternalJavaPackages() {
    URL url = Resources.getResource("javapack.json");
    if (url == null) {
        return null;
    }

    String json;
    try {
        json = Resources.toString(url, Charset.defaultCharset());
    } catch (IOException e) {
        // TODO: log this
        return null;
    }

    if (AssertUtils.isEmpty(json)) {
        return null;
    }

    return GsonUtils.getGson().fromJson(json, JavaPackage[].class);
}