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:fr.da2i.lup1.util.DaoProvider.java

private DaoProvider() {
    try {//w  ww.j ava  2 s. c om
        URL url = Resources.getResource("config.properties");
        Properties props = IO.loadProperties(Paths.get(url.toURI()));
        Class.forName(props.getProperty("db.driver"));
        conSource = new JdbcPooledConnectionSource(props.getProperty("db.uri"),
                props.getProperty("db.username"), props.getProperty("db.password"));
    } catch (IllegalArgumentException | ClassNotFoundException | URISyntaxException | SQLException e) {
        throw new DaoException(e);
    }
}

From source file:iterator.About.java

public About(EventBus bus, Explorer controller) {
    super();/*from   w  w w. j  av a 2 s  .  c o m*/

    splash = Explorer.loadImage(Resources.getResource("splash.png"));
    setSize(splash.getWidth(), splash.getHeight());

    about = new JDialog(controller, "About IFS Explorer", ModalityType.APPLICATION_MODAL);
    about.setLayout(new BorderLayout());
    about.add(this, BorderLayout.CENTER);
    about.pack();

    Dimension size = new Dimension(splash.getWidth(), splash.getHeight() + about.getInsets().top);

    about.setSize(size);
    about.setPreferredSize(size);
    about.setMinimumSize(size);
    about.setResizable(false);

    about.addMouseListener(this);
}

From source file:com.github.tomakehurst.wiremock.admin.tasks.AbstractGetDocTask.java

@Override
public ResponseDefinition execute(Admin admin, Request request, PathParams pathParams) {
    try {/*from   w  w  w  .j  a v a 2  s. co  m*/
        byte[] content = toByteArray(Resources.getResource(getFilePath()).openStream());
        return responseDefinition().withStatus(200).withBody(content).withHeader(CONTENT_TYPE, getMimeType())
                .build();
    } catch (IOException e) {
        return responseDefinition().withStatus(500).build();
    }
}

From source file:org.cloudifysource.cosmo.fileserver.config.JettyFileServerTestConfig.java

@PostConstruct
public void setResourceBase() {
    final URL resource = Resources.getResource(resourceLocation);
    this.resourceBase = new File(resource.getPath()).getParentFile().getAbsolutePath();
}

From source file:org.graylog2.rest.GraylogErrorPageGenerator.java

@Inject
public GraylogErrorPageGenerator(Engine templateEngine) throws IOException {
    this(Resources.toString(Resources.getResource("error.html.template"), StandardCharsets.UTF_8),
            templateEngine);//from   w w w. jav  a  2 s  .  c o m
}

From source file:com.cloudera.kitten.util.LocalDataHelper.java

public static InputStream getFileOrResource(String name) {
    File f = new File(name);
    if (f.exists()) {
        try {/*  ww  w  . j  a v  a2  s.c o m*/
            return new FileInputStream(f);
        } catch (FileNotFoundException e) {
            LOG.error("A file suddenly disappeared", e);
        }
    } else {
        try {
            return Resources.newInputStreamSupplier(Resources.getResource(name)).getInput();
        } catch (IOException e) {
            LOG.error("Error loading resource: " + name, e);
        }
    }
    return null;
}

From source file:org.dswarm.graph.test.Neo4jRunningDBWrapper.java

public Neo4jRunningDBWrapper() {

    final URL resource = Resources.getResource("dmpgraph.properties");
    final Properties properties = new Properties();

    try {// w w  w .j  a  v  a  2 s  .c o  m

        properties.load(resource.openStream());
    } catch (final IOException e) {

        LOG.error("Could not load dmpgraph.properties", e);
    }

    graphEndpoint = properties.getProperty("dmp_graph_endpoint", "http://localhost:7474/graph");

    Neo4jRunningDBWrapper.LOG.info("DMP graph endpoint URI is = '{}'", graphEndpoint);
}

From source file:zipkin.storage.elasticsearch.LazyClient.java

LazyClient(ElasticsearchStorage.Builder builder) {
    this.clientFactory = builder.clientBuilder.buildFactory();
    this.indexTemplateName = builder.index + "_template"; // should be 1:1 with indices
    this.allIndices = new IndexNameFormatter(builder.index).catchAll();
    try {/* ww  w.  ja  va  2 s. com*/
        this.indexTemplate = Resources
                .toString(Resources.getResource("zipkin/storage/elasticsearch/zipkin_template.json"),
                        StandardCharsets.UTF_8)
                .replace("${__INDEX__}", builder.index)
                .replace("${__NUMBER_OF_SHARDS__}", String.valueOf(builder.indexShards))
                .replace("${__NUMBER_OF_REPLICAS__}", String.valueOf(builder.indexReplicas))
                .replace("${__TRACE_ID_MAPPING__}", builder.strictTraceId ? "{ KEYWORD }"
                        : "{ \"type\": \"string\", \"analyzer\": \"traceId_analyzer\" }");
    } catch (IOException e) {
        throw new AssertionError("Error reading jar resource, shouldn't happen.", e);
    }
}

From source file:keywhiz.MigrationsRule.java

@Override
public Statement apply(final Statement base, Description description) {
    return new Statement() {
        @Override/*w  ww .  j  a v  a 2 s.  c o  m*/
        public void evaluate() throws Throwable {
            File yamlFile = new File(Resources.getResource("keywhiz-test.yaml").getFile());
            Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
            ObjectMapper objectMapper = KeywhizService.customizeObjectMapper(Jackson.newObjectMapper());
            KeywhizConfig config = new ConfigurationFactory<>(KeywhizConfig.class, validator, objectMapper,
                    "dw").build(yamlFile);

            DataSource dataSource = config.getDataSourceFactory().build(new MetricRegistry(), "db-migrations");

            Flyway flyway = new Flyway();
            flyway.setDataSource(dataSource);
            flyway.setLocations(config.getMigrationsDir());
            flyway.clean();
            flyway.migrate();

            DSLContext dslContext = DSLContexts.databaseAgnostic(dataSource);
            DbSeedCommand.doImport(dslContext);

            base.evaluate();
        }
    };
}

From source file:org.devacfr.testing.util.Approvals.java

private static String readFile(final Path path) {
    try {//  w ww. ja v  a2s.c  o m
        return Resources.toString(Resources.getResource(path.toString()), Charsets.UTF_8);
    } catch (final IOException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}