List of usage examples for com.google.common.io Resources getResource
public static URL getResource(String resourceName)
From source file:com.streamsets.datacollector.flume.standalone.FlumeDestinationPipelineRunIT.java
@Override protected String getPipelineJson() throws Exception { URI uri = Resources.getResource("flume_destination_pipeline_run.json").toURI(); String pipelineJson = new String(Files.readAllBytes(Paths.get(uri)), StandardCharsets.UTF_8); return pipelineJson; }
From source file:org.rpmcomparator.service.MimeLookUp.java
public static Multimap<String, String> populateMimeMap(Multimap<String, String> mimeFileMap) { MimeLineProcessor mimeLineProcessor = new MimeLineProcessor(mimeFileMap); try {//from ww w . j a va2 s . c o m return Resources.readLines(Resources.getResource(MIME_TYPE_FILE_PATH), Charset.defaultCharset(), mimeLineProcessor); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.facebook.buck.python.PythonInPlaceBinary.java
private static String getRunInplaceResource() { try {//from w w w . ja va 2 s .c o m return Resources.toString(Resources.getResource(RUN_INPLACE_RESOURCE), Charsets.UTF_8); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:ninja.logging.LogbackConfigurator.java
/** * Looks up a potential file from/*from w w w.ja va2s .c o m*/ * 1) The classpahth * 2) From the filesystem * 3) From an URL * * @param logbackConfigurationFile * @return null if not found or a valid url created from the logbackConfigurationFile */ protected static URL getUrlForStringFromClasspathAsFileOrUrl(String logbackConfigurationFile) { URL url = null; try { url = Resources.getResource(logbackConfigurationFile); } catch (IllegalArgumentException ex) { // doing nothing intentionally.. } if (url == null) { // configuring from file: try { File file = new File(logbackConfigurationFile); if (file.exists()) { url = new File(logbackConfigurationFile).toURI().toURL(); } } catch (MalformedURLException ex) { // doing nothing intentionally.. } } if (url == null) { try { // we assume we got a real http://... url here... url = new URL(logbackConfigurationFile); } catch (MalformedURLException ex) { // doing nothing intentionally.. } } return url; }
From source file:org.obm.provisioning.H2Initializer.java
private String getInitialDBScript() throws IOException { URL initialDbScriptUrl = Resources.getResource(INITIAL_DB_SCRIPT); return Resources.toString(initialDbScriptUrl, Charsets.UTF_8); }
From source file:org.apache.isis.viewer.restfulobjects.server.resources.VersionReprRenderer.java
private static String versionFromManifest() { try {/* ww w . j a va 2 s .c o m*/ URL resource = Resources.getResource(META_INF_POM_PROPERTIES); Properties p = new Properties(); p.load(Resources.asCharSource(resource, Charset.defaultCharset()).openStream()); return p.getProperty("version"); } catch (final Exception ex) { return "UNKNOWN"; } }
From source file:com.buildria.mocking.serializer.ObjectSerializerContext.java
protected boolean isGsonEnabled() { return Resources.getResource(GSON_CLASS) != null; }
From source file:com.eucalyptus.portal.awsusage.CassandraSessionManager.java
private static synchronized void initCluster(String contactPoint) { if (session != null) { session.close();/* ww w. j a v a 2s .c o m*/ session = null; } if (cluster != null) { cluster.close(); cluster = null; } LOG.info("Trying to connect to the cluster " + contactPoint); List<String> contactPoints = Lists.newArrayList(); for (String s : Splitter.on(",").omitEmptyStrings().split(contactPoint)) { contactPoints.add(s); } cluster = Cluster.builder().addContactPoints(contactPoints.toArray(new String[0])).build(); session = cluster.connect(); // create new keyspace/tables (should not do here) TODO: move session.execute("CREATE KEYSPACE IF NOT EXISTS eucalyptus_billing " + "WITH replication = {'class':'SimpleStrategy', 'replication_factor':1}; "); session.execute("USE eucalyptus_billing;"); try { final String cql = Resources.toString(Resources.getResource("2017-03-28-eucalyptus-billing-base.cql"), StandardCharsets.UTF_8); CqlUtil.splitCql(cql).forEach(session::execute); } catch (final IOException | ParseException e) { throw Exceptions.toUndeclared(e); } }
From source file:org.jsfr.json.BenchmarkCollectObject.java
@Setup public void setup() throws Exception { gsonSurfer = JsonSurfer.gson();//www .ja v a 2s. c o m jacksonSurfer = JsonSurfer.jackson(); simpleSurfer = JsonSurfer.simple(); TypedJsonPathListener collectOneListener = new TypedJsonPathListener() { private Blackhole blackhole = new Blackhole(); @Override public void onTypedValue(Object value, ParsingContext context) throws Exception { blackhole.consume(value); } }; surfingConfiguration = SurfingConfiguration.builder().bind("$.store.book[*]", Map.class, collectOneListener) .build(); json = Resources.toString(Resources.getResource("sample.json"), StandardCharsets.UTF_8); }
From source file:ro.cosu.vampires.server.resources.ec2.EC2Resource.java
@Override public void onStart() throws Exception { RunInstancesRequest runInstancesRequest = new RunInstancesRequest(); amazonEC2Client.setEndpoint(String.format("ec2.%1s.amazonaws.com", parameters.region())); URL cloudInitResource = Resources.getResource("cloud_init.yaml"); String cloudInit = Resources.toString(cloudInitResource, Charsets.UTF_8); String command = parameters.command() + " " + parameters.serverId() + " " + parameters().id(); cloudInit = cloudInit.replace("$command", command); LOG.debug("EC2command: {}", command); RunInstancesRequest request = runInstancesRequest.withImageId(parameters.imageId()) .withInstanceType(parameters.instanceType()).withMinCount(1).withMaxCount(1) .withKeyName(parameters.keyName()).withSecurityGroups(parameters.securityGroup()) .withUserData(Base64.encodeBase64String(cloudInit.getBytes(Charsets.UTF_8))); instanceId = amazonEC2Client.runInstances(request).getReservation().getInstances().get(0).getInstanceId(); LOG.debug("Started amazon instance {}", instanceId); CreateTagsRequest createTagsRequest = new CreateTagsRequest(); createTagsRequest.withResources(instanceId).withTags(new Tag("providerType", "vampires")); amazonEC2Client.createTags(createTagsRequest); DescribeInstancesRequest describeRequest = new DescribeInstancesRequest(); describeRequest.withInstanceIds(instanceId); String publicDnsName = getPublicDnsName(describeRequest); LOG.info("instance {} : {}", instanceId, publicDnsName); }