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.tinyhttp.ssl.HttpsTrustManagerFactory.java

@Nonnull
private static KeyStore loadKeystore(@Nonnull String location, @Nonnull String keystoreType,
        @Nonnull String keystorePassword) throws GeneralSecurityException, IOException {
    final KeyStore keystore = KeyStore.getInstance(keystoreType);
    URL keystoreUrl;//from w w w.  j a va 2 s  . c  o  m
    if (StringUtils.startsWithIgnoreCase(location, "classpath:")) {
        keystoreUrl = Resources.getResource(HttpsTrustManagerFactory.class, location.substring(10));
    } else {
        keystoreUrl = new URL(location);
    }
    keystore.load(keystoreUrl.openStream(), keystorePassword.toCharArray());
    return keystore;
}

From source file:de.ii.ldproxy.rest.SwaggerApiResource.java

@GET
public Response getApi() {
    StreamingOutput stream = new StreamingOutput() {
        @Override/*from w  w w .  j  a  v  a  2s.c  om*/
        public void write(OutputStream output) throws IOException, WebApplicationException {
            Resources.asByteSource(Resources.getResource(SwaggerApiResource.class, "/swagger/swagger.json"))
                    .copyTo(output);
        }
    };

    return Response.ok(stream).build();
}

From source file:com.twitter.common.webassets.bootstrap.BootstrapModule.java

private void register(String mountPath, String resourcePath, String contentType) {
    Registration.registerHttpAsset(binder(), "/" + mountPath,
            Resources.getResource(BootstrapModule.class, resourcePath), contentType, true);
}

From source file:org.sonar.server.rule.ws.RepositoriesAction.java

@Override
public void define(WebService.NewController controller) {
    NewAction action = controller.createAction("repositories")
            .setDescription("List available rule repositories").setSince("4.5").setHandler(this)
            .setResponseExample(Resources.getResource(getClass(), "example-repositories.json"));

    action.createParam(Param.TEXT_QUERY).setDescription("A pattern to match repository keys/names against")
            .setExampleValue("squid");
    action.createParam(LANGUAGE)// ww  w.j a v  a  2  s.  c o m
            .setDescription(
                    "A language key; if provided, only repositories for the given language will be returned")
            .setExampleValue("java");
}

From source file:br.com.objectos.way.io.WayIOFakes.java

private static URL getUrl(Class<?> contextClass, String fileName) {
    URL url = Resources.getResource(contextClass, fileName);
    return url;
}

From source file:com.nesscomputing.httpclient.internal.HttpClientTrustManagerFactory.java

@Nonnull
private static KeyStore loadKeystore(@Nonnull String location, @Nonnull String keystoreType,
        @Nonnull String keystorePassword) throws GeneralSecurityException, IOException {
    final KeyStore keystore = KeyStore.getInstance(keystoreType);
    URL keystoreUrl;/*  w w w  . j  av  a 2 s .  c  o  m*/
    if (StringUtils.startsWithIgnoreCase(location, "classpath:")) {
        keystoreUrl = Resources.getResource(HttpClientTrustManagerFactory.class, location.substring(10));
    } else {
        keystoreUrl = new URL(location);
    }
    keystore.load(keystoreUrl.openStream(), keystorePassword.toCharArray());
    return keystore;
}

From source file:org.isisaddons.module.fakedata.dom.IsisClobs.java

private static Clob asClob(final String fileName) {
    final URL resource = Resources.getResource(IsisBlobs.class, "clobs/" + fileName);
    final CharSource charSource = Resources.asCharSource(resource, Charsets.US_ASCII);
    final String chars;
    try {/* w  w w .j  a  v a 2  s .co  m*/
        chars = charSource.read();
        return new Clob(fileName, mimeTypeFor(fileName), chars);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.sonar.server.project.ws.ProjectsWs.java

private void defineIndexAction(NewController controller) {
    WebService.NewAction action = controller.createAction("index").setDescription("Search for projects")
            .setSince("2.10").setHandler(RailsHandler.INSTANCE)
            .setResponseExample(Resources.getResource(this.getClass(), "projects-example-index.json"));

    action.createParam("key").setDescription("id or key of the project")
            .setExampleValue(KEY_PROJECT_EXAMPLE_001);

    action.createParam("search").setDescription("Substring of project name, case insensitive")
            .setExampleValue("Sonar");

    action.createParam("desc").setDescription("Load project description").setDefaultValue(TRUE)
            .setBooleanPossibleValues();

    action.createParam("subprojects").setDescription("Load sub-projects. Ignored if the parameter key is set")
            .setDefaultValue(FALSE).setBooleanPossibleValues();

    action.createParam("views").setDescription("Load views and sub-views. Ignored if the parameter key is set")
            .setDefaultValue(FALSE).setBooleanPossibleValues();

    action.createParam("libs").setDescription("Load libraries. Ignored if the parameter key is set")
            .setDefaultValue(FALSE).setBooleanPossibleValues();

    action.createParam("versions").setDescription("Load version").setDefaultValue(FALSE).setPossibleValues(TRUE,
            FALSE, "last");

    RailsHandler.addFormatParam(action);
}

From source file:com.greensopinion.finance.services.web.EulaWebService.java

@Path(CURRENT_EULA)
@GET/*  w w w  .ja v a 2 s .  co m*/
public Eula current() {
    try {
        return new Eula(Resources.toString(Resources.getResource(EulaWebService.class, "model/eula.html"),
                StandardCharsets.UTF_8));
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
}

From source file:services.docx.NotaServiceDocx.java

@PostConstruct
public void init() throws IOException, LoadTemplateException {
    final byte[] bytes = Resources.toByteArray(Resources.getResource(this.getClass(), "nota.docx"));
    wordprocessingMLPackage = docxService.loadPackage(new ByteArrayInputStream(bytes));
}