List of usage examples for com.google.common.io Resources getResource
public static URL getResource(String resourceName)
From source file:com.axelor.meta.loader.XMLViews.java
private static void init() throws JAXBException, SAXException { if (unmarshaller != null) { return;//from w ww . j av a2s . co m } JAXBContext context = JAXBContext.newInstance(ObjectViews.class); unmarshaller = context.createUnmarshaller(); marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, ObjectViews.NAMESPACE + " " + ObjectViews.NAMESPACE + "/" + REMOTE_SCHEMA); for (String name : INDENT_PROPERTIES) { try { marshaller.setProperty(name, INDENT_STRING); break; } catch (Exception e) { log.info("JAXB marshaller doesn't support property: " + name); } } SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = schemaFactory.newSchema(Resources.getResource(LOCAL_SCHEMA)); unmarshaller.setSchema(schema); marshaller.setSchema(schema); // find supported views JsonSubTypes types = AbstractView.class.getAnnotation(JsonSubTypes.class); for (JsonSubTypes.Type type : types.value()) { JsonTypeName name = type.value().getAnnotation(JsonTypeName.class); if (name != null) { VIEW_TYPES.add(name.value()); } } }
From source file:org.cloudifysource.cosmo.orchestrator.workflow.RuoteRuntime.java
private static void updateLibraryPath(ScriptingContainer container, String resourcesRoot, ClassLoader loader) { URL gemsResource;/*from w w w .j a v a2 s.com*/ if (loader == null) { gemsResource = Resources.getResource(resourcesRoot); } else { gemsResource = loader.getResource(resourcesRoot); } Preconditions.checkNotNull(gemsResource); final String resourcePath = gemsResource.getPath(); container.runScriptlet("Dir['" + resourcePath + "/**/*'].each { |dir| $: << dir }"); }
From source file:com.axemblr.provisionr.test.ProvisionrLiveTestSupport.java
public String getResourceAsString(String resource) throws IOException { return Resources.toString(Resources.getResource(resource), Charsets.UTF_8); }
From source file:com.zxy.commons.web.utils.URLPropertiesUtils.java
@SuppressWarnings("deprecation") @Override//from w w w .j ava2s . co m protected URL getPath() throws IOException { String path = getWebInfPath(); if (StringUtils.isNotBlank(path)) { String webInf = "/" + path; String urlPath = "WEB-INF/view/config/url.properties"; if (new File(webInf + "src/main/webapp/" + urlPath).exists()) { return new File(webInf + "src/main/webapp/" + urlPath).toURL(); } else if (new File(webInf + "/" + urlPath).exists()) { return new File(webInf + "/" + urlPath).toURL(); } else { return Resources.getResource("url.properties"); } } return Resources.getResource("url.properties"); }
From source file:eu.excitementproject.eop.distsim.redisinjar.EmbeddedRedisServerRunner.java
private File extractExecutableFromJar(String scriptName) throws IOException { File tmpDir = Files.createTempDir(); tmpDir.deleteOnExit();/*w ww . jav a 2 s .com*/ File command = new File(tmpDir, scriptName); FileUtils.copyURLToFile(Resources.getResource(scriptName), command); command.deleteOnExit(); command.setExecutable(true); return command; }
From source file:org.apache.drill.exec.store.kafka.KafkaMessageGenerator.java
public void populateAvroMsgIntoKafka(String topic, int numMsg) throws IOException { KafkaProducer<String, GenericRecord> producer = new KafkaProducer<String, GenericRecord>( producerProperties);//from w w w .j a v a 2 s . com Schema.Parser parser = new Schema.Parser(); Schema schema = parser.parse(Resources.getResource("drill-avro-test.avsc").openStream()); GenericRecordBuilder builder = new GenericRecordBuilder(schema); Random rand = new Random(); for (int i = 0; i < numMsg; ++i) { builder.set("key1", UUID.randomUUID().toString()); builder.set("key2", rand.nextInt()); builder.set("key3", rand.nextBoolean()); List<Integer> list = Lists.newArrayList(); list.add(rand.nextInt(100)); list.add(rand.nextInt(100)); list.add(rand.nextInt(100)); builder.set("key5", list); Map<String, Double> map = Maps.newHashMap(); map.put("key61", rand.nextDouble()); map.put("key62", rand.nextDouble()); builder.set("key6", map); Record producerRecord = builder.build(); ProducerRecord<String, GenericRecord> record = new ProducerRecord<String, GenericRecord>(topic, producerRecord); producer.send(record); } producer.close(); }
From source file:it.smartcommunitylab.aac.apimanager.wso2.WSO2APIManager.java
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override// w w w. ja v a2s .co m public void publishAPI(String jsonModel, String name, String description, String context, String token) throws Exception { Map apis = pub.findAPI(name, token); List list = (List) apis.get("list"); log.info("Checking publish API {} ...", name); // System.err.println(apis); if (list.isEmpty() || !list.stream().anyMatch(x -> name.equals(((Map) x).get("name")))) { String swagger = Resources.toString(Resources.getResource(jsonModel), Charsets.UTF_8); swagger = env.resolvePlaceholders(swagger); log.info("Publishing API {}", name); API api = new API(); api.setName(name); api.setDescription(description); api.setContext(context); api.setVersion("1.0.0"); api.setProvider("admin"); api.setApiDefinition(swagger); api.setStatus("CREATED"); api.setVisibility("PUBLIC"); api.setSubscriptionAvailability("all_tenants"); api.setIsDefaultVersion(true); api.setEndpointConfig(env.resolvePlaceholders(ENDPOINT_CONFIG)); CorsConfiguration cors = new CorsConfiguration(); cors.setCorsConfigurationEnabled(true); cors.setAccessControlAllowOrigins(Lists.newArrayList("*")); cors.setAccessControlAllowHeaders(Lists.newArrayList("authorization", "Access-Control-Allow-Origin", "Content-Type", "SOAPAction")); cors.setAccessControlAllowMethods( Lists.newArrayList("GET", "PUT", "POST", "DELETE", "PATCH", "OPTIONS")); api.setCorsConfiguration(cors); API result = pub.publishAPI(api, token); pub.changeAPIStatus(result.getId(), "Publish", token); // System.err.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(result)); } }
From source file:org.n52.youngs.transform.impl.CswToBuilderMapper.java
public CswToBuilderMapper(MappingConfiguration mapper) { this.mapper = mapper; try (InputStream is = Resources.getResource("xslt/stripspace.xslt").openStream();) { Source xslt = new StreamSource(is); stripspaceTransformer = Optional.of(tFactory.newTransformer(xslt)); log.trace("Will apply stripspace XSLT."); } catch (TransformerConfigurationException | IOException e) { log.error("Problem loading strip-space XSLT file.", e); }/*from w ww .ja va 2 s .com*/ }
From source file:org.wso2.msf4j.example.SampleClient.java
private static HttpEntity createMessageForComplexForm() { HttpEntity reqEntity = null;/*from ww w. jav a 2 s . c om*/ try { StringBody companyText = new StringBody("{\"type\": \"Open Source\"}", ContentType.APPLICATION_JSON); StringBody personList = new StringBody( "[{\"name\":\"Richard Stallman\",\"age\":63}, {\"name\":\"Linus Torvalds\",\"age\":46}]", ContentType.APPLICATION_JSON); reqEntity = MultipartEntityBuilder.create().addTextBody("id", "1").addPart("company", companyText) .addPart("people", personList) .addBinaryBody("file", new File(Resources.getResource("sample.txt").toURI()), ContentType.DEFAULT_BINARY, "sample.txt") .build(); } catch (URISyntaxException e) { log.error("Error while getting the file from resource." + e.getMessage(), e); } return reqEntity; }
From source file:org.kitesdk.maven.plugins.UpdateDatasetMojo.java
@Override public void execute() throws MojoExecutionException, MojoFailureException { if (avroSchemaFile == null && avroSchemaReflectClass == null) { throw new IllegalArgumentException( "One of kite.avroSchemaFile or " + "kite.avroSchemaReflectClass must be specified"); }/* w ww.j av a2 s. c om*/ DatasetRepository repo = getDatasetRepository(); DatasetDescriptor descriptor = repo.load(datasetName).getDescriptor(); DatasetDescriptor.Builder descriptorBuilder = new DatasetDescriptor.Builder(descriptor); configureSchema(descriptorBuilder, avroSchemaFile, avroSchemaReflectClass); if (columnDescriptorFile != null) { File columnDescriptor = new File(columnDescriptorFile); try { if (columnDescriptor.exists()) { descriptorBuilder.columnMapping(columnDescriptor); } else { descriptorBuilder.columnMapping(Resources.getResource(columnDescriptorFile).openStream()); } } catch (IOException e) { throw new MojoExecutionException("Problem while reading file " + columnDescriptorFile, e); } } repo.update(datasetName, descriptorBuilder.build()); }