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:org.sonar.server.qualitygate.ws.ListAction.java

@Override
public void define(WebService.NewController controller) {
    controller.createAction("list").setDescription("Get a list of quality gates").setSince("4.3")
            .setResponseExample(Resources.getResource(this.getClass(), "example-list.json")).setHandler(this);
}

From source file:org.apache.wicket.examples.base.MarkdownArticleModel.java

@Override
protected String load() {
    String text;//from   ww  w .j ava2 s  . co  m
    try {
        text = Resources.toString(Resources.getResource(parent, path), Charset.forName("utf-8"));
    } catch (IOException e) {
        throw new WicketRuntimeException("Unable to load " + path + " relative to " + parent.getName(), e);
    }
    return text;
}

From source file:li.klass.fhem.service.deviceConfiguration.DeviceDescMapping.java

@Inject
public DeviceDescMapping() {
    try {//from  ww  w.j a  va 2  s.  com
        mapping = new JSONObject(Resources.toString(
                Resources.getResource(DeviceConfigurationProvider.class, "deviceDescMapping.json"),
                Charsets.UTF_8));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:org.sonar.server.ws.RemovedWebServiceHandler.java

public URL getResponseExample() {
    return Resources.getResource(RemovedWebServiceHandler.class, "removed-ws-example.json");
}

From source file:org.ow2.petals.cloud.manager.core.puppet.ClasspathScriptBuilder.java

public String build(Node node, Context context) throws CloudManagerException {
    try {//from  w ww.ja  va 2 s  .c  o m
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        Writer writer = new OutputStreamWriter(outputStream);
        URL resource = Resources.getResource(DownloadFilesScriptBuilder.class, getTemplate());
        String content = Resources.toString(resource, Charsets.UTF_8);
        MustacheFactory factory = new DefaultMustacheFactory();
        factory.compile(new StringReader(content), resource.toString()).execute(writer,
                getScope(node, context));
        writer.close();
        return outputStream.toString();
    } catch (IOException e) {
        throw new CloudManagerException("Can not load resource", e);
    } finally {

    }
}

From source file:com.google.api.codegen.discovery.config.ruby.RubyTypeNameGenerator.java

@SuppressWarnings("unchecked")
private ImmutableMap<String, String> getMethodNameMap() throws IOException {
    String data = Resources.toString(Resources.getResource(RubyApiaryNameMap.class, "apiary_names.yaml"),
            StandardCharsets.UTF_8);
    // Unchecked cast here.
    return ImmutableMap.copyOf((Map<String, String>) (new Yaml().load(data)));
}

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:org.sonar.server.qualitygate.ws.QGatesListAction.java

void define(WebService.NewController controller) {
    controller.createAction("list").setDescription("Get a list of quality gates").setSince("4.3")
            .setResponseExample(Resources.getResource(this.getClass(), "example-list.json")).setHandler(this);
}

From source file:org.sonar.server.authentication.ws.AuthenticationWs.java

private void defineValidateAction(NewController controller) {
    NewAction action = controller.createAction("validate").setDescription("Check credentials.").setSince("3.3")
            .setHandler(ServletFilterHandler.INSTANCE)
            .setResponseExample(Resources.getResource(this.getClass(), "example-validate.json"));

    RailsHandler.addFormatParam(action);
}

From source file:org.sonar.server.platform.ws.ServerWs.java

@Override
public void define(Context context) {
    NewController controller = context.createController("api/server");

    controller.createAction("version").setDescription("Version of SonarQube in plain text").setSince("2.10")
            .setResponseExample(Resources.getResource(this.getClass(), "example-server-version.txt"))
            .setHandler(this);

    controller.done();//from w  w  w.  ja v a 2 s  .c o m
}