List of usage examples for com.google.common.io Resources getResource
public static URL getResource(String resourceName)
From source file:eu.redzoo.reactive.kafka.rest.Environment.java
private static ImmutableMap<String, String> load(String appname) { // get the location url Optional<URL> optionalUrl = Optional.empty(); try {/*from w w w .j a va 2 s. c om*/ String location = System.getProperty("reactive-kafka-rest"); optionalUrl = Optional .of((location == null) ? Resources.getResource(appname + ".properties") : new URL(location)); } catch (MalformedURLException mue) { LOG.warning("error occured by loading config " + appname + " " + mue.toString()); } // load the config return optionalUrl.map(url -> loadProperties(url)).orElseGet(ImmutableMap::of); }
From source file:com.dgraf.nashornplayground.AddingJava.java
public AddingJava() { super();//from w w w .j av a2 s . co m runner = new nashornScriptRunner(); scriptset = new nashornScriptset(); try { scriptset.setName("Adding Java"); URL url = Resources.getResource("com/dgraf/nashornplayground/examples/addingjava.js"); String script = Resources.toString(url, Charsets.UTF_8); scriptset.setScript(script); } catch (IOException ex) { Logger.getLogger(HelloWorld.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.dgraf.nashornplayground.Performance.java
public Performance() { super();/*w w w.ja v a2s .co m*/ runner = new nashornScriptRunner(); scriptset = new nashornScriptset(); try { scriptset.setName("Performance"); URL url = Resources.getResource("com/dgraf/nashornplayground/examples/performance.js"); String script = Resources.toString(url, Charsets.UTF_8); scriptset.setScript(script); } catch (IOException ex) { Logger.getLogger(HelloWorld.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:org.n52.youngs.control.Main.java
public static Report dabGmd() throws Exception { Source source = new KvpCswSource("http://api.eurogeoss-broker.eu/dab/services/cswiso", Collections.singleton("http://www.isotc211.org/2005/gmd"), NamespaceContextImpl.create(), "gmd:MD_Metadata", "http://www.isotc211.org/2005/gmd"); MappingConfiguration configuration = new YamlMappingConfiguration( Resources.asByteSource(Resources.getResource("mappings/gmd-metadata.yml")).openStream(), new XPathHelper()); Mapper mapper = new CswToBuilderMapper(configuration); String host = "localhost"; String cluster = "ConnectinGEO"; String index = "geodab"; String type = "isorecord"; int port = 9301; Sink sink = new ElasticsearchRemoteHttpSink(host, port, cluster, index, type); Runner runner = new SingleThreadBulkRunner().setBulkSize(10).setRecordsLimit(10000).setStartPosition(10000) .harvest(source).transform(mapper); Report report = runner.load(sink);//from w w w .ja va 2 s . co m return report; }
From source file:org.mayocat.shop.shipping.rest.resource.DestinationsResource.java
@GET public Response getDestinations() { try {// ww w.ja va 2 s . c o m return Response.ok(Resources.toString( Resources.getResource("org/mayocat/shop/shipping/destinations/earth.json"), Charsets.UTF_8)) .build(); } catch (IOException e) { this.logger.error("Failed to get location file", e); return Response.serverError().build(); } }
From source file:com.hortonworks.registries.schemaregistry.avro.conf.SchemaRegistryTestConfiguration.java
public static SchemaRegistryTestConfiguration forProfileType(SchemaRegistryTestProfileType testProfileType) throws URISyntaxException { String serverYAMLFileName;//from ww w .ja va 2 s. com String clientYAMLFileName; switch (testProfileType) { case DEFAULT: serverYAMLFileName = "schema-registry-test.yaml"; clientYAMLFileName = "schema-registry-client.yaml"; break; case SSL: serverYAMLFileName = "ssl-schema-registry-test.yaml"; clientYAMLFileName = "ssl-schema-registry-client.yaml"; break; case DEFAULT_HA: serverYAMLFileName = "schema-registry-test-ha.yaml"; clientYAMLFileName = null; break; case SSL_HA: serverYAMLFileName = "ssl-schema-registry-test-ha.yaml"; clientYAMLFileName = "ssl-schema-registry-client.yaml"; break; default: throw new IllegalArgumentException("Unrecognized SchemaRegistryTestProfileType : " + testProfileType); } String serverYAMLPath = new File(Resources.getResource(serverYAMLFileName).toURI()).getAbsolutePath(); String clientYAMLPath = clientYAMLFileName == null ? null : new File(Resources.getResource(clientYAMLFileName).toURI()).getAbsolutePath(); return new SchemaRegistryTestConfiguration(serverYAMLPath, clientYAMLPath); }
From source file:com.dgraf.nashornplayground.HelloWorld.java
public HelloWorld() { super();/* w w w. j a va 2s .co m*/ runner = new nashornScriptRunner(); scriptset = new nashornScriptset(); try { scriptset.setName("Hello World"); URL url = Resources.getResource("com/dgraf/nashornplayground/examples/helloworld.js"); String script = Resources.toString(url, Charsets.UTF_8); scriptset.setScript(script); } catch (IOException ex) { Logger.getLogger(HelloWorld.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:iterator.util.Version.java
private Version() { URL resource = Resources.getResource(VERSION_RESOURCE_FILE); this.version = readVersion(resource); }
From source file:com.xebialabs.overcast.PropertiesLoader.java
/** Load {@link Config} from 'file' but do not resolve it. */ static Config loadOvercastConfigFromClasspath(String path) { try {/*w w w. j a va2s . c o m*/ // resource.toURI().getPath() so path gets URL decoded so spaces are no issue // using resource.getPath() runs into a bug with guava return loadOvercastConfigFromFile(Resources.getResource(path).toURI().getPath()); } catch (IllegalArgumentException e) { logger.warn("File '{}' not found on classpath.", path); } catch (URISyntaxException e) { logger.warn("File '{}' not found on classpath.", path); } return ConfigFactory.empty(); }
From source file:keywhiz.KeywhizTestRunner.java
static Injector createInjector() { KeywhizService service = new KeywhizService(); Bootstrap<KeywhizConfig> bootstrap = new Bootstrap<>(service); service.initialize(bootstrap);/* w w w . j a va2s .c o m*/ File yamlFile = new File(Resources.getResource("keywhiz-test.yaml").getFile()); Validator validator = Validation.buildDefaultValidatorFactory().getValidator(); ObjectMapper objectMapper = bootstrap.getObjectMapper().copy(); KeywhizConfig config; try { config = new ConfigurationFactory<>(KeywhizConfig.class, validator, objectMapper, "dw").build(yamlFile); } catch (IOException | ConfigurationException e) { throw Throwables.propagate(e); } Environment environment = new Environment(service.getName(), objectMapper, validator, bootstrap.getMetricRegistry(), bootstrap.getClassLoader()); Injector injector = Guice.createInjector(new ServiceModule(config, environment)); service.setInjector(injector); return injector; }