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(Class<?> contextClass, String resourceName) 

Source Link

Document

Given a resourceName that is relative to contextClass , returns a URL pointing to the named resource.

Usage

From source file:com.nesscomputing.migratory.loader.ClasspathLoader.java

/**
 * This method loads a file from a classpath:/... URI.
 *///from  w  ww.j a va2 s  .c  o m
@Override
public String loadFile(final URI fileUri) {
    try {
        final URL urlLocation = Resources.getResource(this.getClass(), fileUri.getPath());
        return Resources.toString(urlLocation, Charsets.UTF_8);
    } catch (IOException e) {
        throw new MigratoryException(Reason.INTERNAL, e);
    }
}

From source file:com.eucalyptus.auth.util.ClassPathSystemAccountProvider.java

private static String loadResource(final Class<?> resourceClass, final String resourceName) {
    try {//w ww .j  a  v a  2s  .  c om
        return Resources.toString(Resources.getResource(resourceClass, resourceName), Charsets.UTF_8);
    } catch (final IOException e) {
        throw Throwables.propagate(e);
    }
}

From source file:com.facebook.buck.features.project.intellij.StringTemplateFile.java

/**
 * Not thread safe, see discussion in: https://github.com/antlr/stringtemplate4/issues/61 could be
 * made faster by sharing STGroup across threads using a supplier, see {@link
 * com.facebook.buck.parser.function.BuckPyFunction}. May be fixed in ST4.1
 *///from  w w  w .  j a  v  a 2 s. c om
public synchronized ST getST() throws IOException {
    URL templateUrl = Resources.getResource(StringTemplateFile.class, "templates/" + fileName);
    String template = Resources.toString(templateUrl, StandardCharsets.UTF_8);
    return new ST(template, DELIMITER, DELIMITER);
}

From source file:org.openqa.selenium.firefox.ClasspathExtension.java

@Override
public void writeTo(File extensionsDir) throws IOException {
    if (!FileHandler.isZipped(loadFrom)) {
        throw new WebDriverException("Will only install zipped extensions for now");
    }// w  w w.  jav a2 s  .c  o  m

    File holdingPen = new File(extensionsDir, "webdriver-staging");
    FileHandler.createDir(holdingPen);

    File extractedXpi = new File(holdingPen, loadFrom);
    File parentDir = extractedXpi.getParentFile();
    if (!parentDir.exists()) {
        parentDir.mkdirs();
    }

    URL resourceUrl = Resources.getResource(loadResourcesUsing, loadFrom);

    try (OutputStream stream = new FileOutputStream(extractedXpi)) {
        Resources.copy(resourceUrl, stream);
    }
    new FileExtension(extractedXpi).writeTo(extensionsDir);
}

From source file:org.sonar.server.updatecenter.ws.UpdateCenterWs.java

private void defineInstalledPluginsAction(NewController controller) {
    NewAction action = controller.createAction("installed_plugins")
            .setDescription("Get the list of all the plugins installed on the SonarQube instance")
            .setSince("2.10").setHandler(RailsHandler.INSTANCE).setInternal(true)
            .setResponseExample(Resources.getResource(this.getClass(), "example-installed_plugins.json"));
    RailsHandler.addFormatParam(action);
}

From source file:org.sonar.server.qualityprofile.ws.ProfilesWs.java

private static void defineListAction(NewController controller) {
    WebService.NewAction action = controller.createAction("list").setDescription("Get a list of profiles.")
            .setSince("3.3").setDeprecatedSince("5.2").setHandler(RailsHandler.INSTANCE)
            .setResponseExample(Resources.getResource(ProfilesWs.class, "example-list.json"));

    action.createParam("language").setDescription("Profile language").setExampleValue("java");
    action.createParam("project").setDescription("Project key or id").setExampleValue(KEY_PROJECT_EXAMPLE_001);
    RailsHandler.addJsonOnlyFormatParam(action);
}

From source file:org.openqa.selenium.firefox.internal.ClasspathExtension.java

public void writeTo(File extensionsDir) throws IOException {
    if (!FileHandler.isZipped(loadFrom)) {
        throw new WebDriverException("Will only install zipped extensions for now");
    }//from  w  w w . j a v a  2s  . com

    File holdingPen = new File(extensionsDir, "webdriver-staging");
    FileHandler.createDir(holdingPen);

    File extractedXpi = new File(holdingPen, loadFrom);
    File parentDir = extractedXpi.getParentFile();
    if (!parentDir.exists()) {
        parentDir.mkdirs();
    }

    URL resourceUrl = Resources.getResource(loadResourcesUsing, loadFrom);
    OutputStream stream = null;

    try {
        stream = new FileOutputStream(extractedXpi);
        Resources.copy(resourceUrl, stream);
    } finally {
        Closeables.close(stream, false);
    }
    new FileExtension(extractedXpi).writeTo(extensionsDir);
}

From source file:org.sonar.server.qualitygate.ws.SearchAction.java

@Override
public void define(WebService.NewController controller) {
    WebService.NewAction action = controller.createAction("search")
            .setDescription("Search for projects associated (or not) to a quality gate.<br/>"
                    + "Only authorized projects for current user will be returned.")
            .setSince("4.3").setResponseExample(Resources.getResource(this.getClass(), "example-search.json"))
            .setHandler(this);

    action.createParam(QualityGatesWsParameters.PARAM_GATE_ID).setDescription("Quality Gate ID")
            .setRequired(true).setExampleValue("1");

    action.createParam(QualityGatesWsParameters.PARAM_QUERY).setDescription(
            "To search for projects containing this string. If this parameter is set, \"selected\" is set to \"all\".")
            .setExampleValue("abc");

    action.addSelectionModeParam();/*from   w w  w. ja v  a2 s . c  o m*/

    action.createParam(QualityGatesWsParameters.PARAM_PAGE).setDescription("Page number").setDefaultValue("1")
            .setExampleValue("2");

    action.createParam(QualityGatesWsParameters.PARAM_PAGE_SIZE).setDescription("Page size")
            .setExampleValue("10");
}

From source file:org.apache.isis.core.unittestsupport.jaxb.JaxbMatchers.java

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

From source file:com.eucalyptus.auth.util.ClassPathSystemRoleProvider.java

private String loadPolicy(final String resourceName) {
    try {/*from  ww  w .  j  a  v a  2 s  .c o  m*/
        return Resources.toString(Resources.getResource(getClass(), resourceName), Charsets.UTF_8);
    } catch (final IOException e) {
        throw Exceptions.toUndeclared(e);
    }
}