List of usage examples for org.springframework.util ResourceUtils getFile
public static File getFile(URI resourceUri) throws FileNotFoundException
From source file:org.apache.rya.jena.jenasesame.example.JenaSesameExample.java
public static void main(final String args[]) throws Exception { Repository repo = null;/*from www . java 2 s. c o m*/ RepositoryConnection addConnection = null; RepositoryConnection queryConnection = null; QueryExecution queryExecution = null; try { repo = new SailRepository(new MemoryStore()); repo.initialize(); // Load some data. addConnection = repo.getConnection(); // Reads files relative from target/test-classes which should have been copied from src/test/resources final URL url = ClassLoader.getSystemResource("rdf_format_files/turtle_files/turtle_data.ttl"); final File file = ResourceUtils.getFile(url); final String fileName = file.getAbsolutePath(); final RDFFormat rdfFormat = RDFFormat.forFileName(fileName); log.info("Added RDF file with " + rdfFormat.getName() + " format: " + fileName); addConnection.add(file, "http://base/", rdfFormat); addConnection.close(); queryConnection = repo.getConnection(); final Dataset dataset = JenaSesame.createDataset(queryConnection); final Model model = dataset.getDefaultModel(); log.info(model.getNsPrefixMap()); final String object = "susandillon@gmail.com"; final String queryString = "prefix : <http://example/> SELECT * { ?s ?p '" + object + "' }"; final Query query = QueryFactory.create(queryString); queryExecution = QueryExecutionFactory.create(query, dataset); QueryExecUtils.executeQuery(query, queryExecution); } catch (final Exception e) { log.error("Encountered an exception while performing query.", e); } finally { if (queryExecution != null) { queryExecution.close(); } if (addConnection != null) { addConnection.close(); } if (queryConnection != null) { queryConnection.close(); } if (repo != null) { repo.shutDown(); } } }
From source file:org.apache.rya.jena.jenasesame.example.JenaReasoningWithRulesExample.java
public static void main(final String args[]) throws Exception { Repository repo = null;//from w ww .j a va2s . co m RepositoryConnection addConnection = null; RepositoryConnection queryConnection = null; try { repo = new SailRepository(new MemoryStore()); repo.initialize(); // Load some data. addConnection = repo.getConnection(); // Reads files relative from target/test-classes which should have been copied from src/test/resources final URL url = ClassLoader.getSystemResource("rdf_format_files/notation3_files/n3_data.n3"); final File file = ResourceUtils.getFile(url); final String fileName = file.getAbsolutePath(); final RDFFormat rdfFormat = RDFFormat.forFileName(fileName); log.info("Added RDF file with " + rdfFormat.getName() + " format: " + fileName); addConnection.add(file, "http://base/", rdfFormat); addConnection.close(); queryConnection = repo.getConnection(); final Dataset dataset = JenaSesame.createDataset(queryConnection); final Model model = dataset.getDefaultModel(); log.info(model.getNsPrefixMap()); final URL rulesUrl = ClassLoader .getSystemResource("rdf_format_files/notation3_files/rule_files/rules.txt"); final File rulesFile = ResourceUtils.getFile(rulesUrl); final String rulesFileName = rulesFile.getAbsolutePath(); final Reasoner reasoner = new GenericRuleReasoner(Rule.rulesFromURL(rulesFileName)); final InfModel infModel = ModelFactory.createInfModel(reasoner, model); final StmtIterator iterator = infModel.listStatements(); while (iterator.hasNext()) { final Statement stmt = iterator.nextStatement(); final Resource subject = stmt.getSubject(); final Property predicate = stmt.getPredicate(); final RDFNode object = stmt.getObject(); log.info(subject.toString() + " " + predicate.toString() + " " + object.toString()); } } catch (final Exception e) { log.error("Encountered an exception while running reasoner.", e); } finally { if (addConnection != null) { addConnection.close(); } if (queryConnection != null) { queryConnection.close(); } if (repo != null) { repo.shutDown(); } } }
From source file:org.slc.sli.ingestion.IngestionTest.java
public static File getFile(String fileResourcePath) throws FileNotFoundException { if (!fileResourcePath.startsWith("classpath:")) { fileResourcePath = "classpath:" + fileResourcePath; }/*ww w .j av a2 s . com*/ File file = ResourceUtils.getFile(fileResourcePath); return file; }
From source file:org.elasticsoftware.elasticactors.runtime.DefaultConfigurationTest.java
@Test public void testLoadDefaultConfig() throws IOException { File configFile = ResourceUtils.getFile("classpath:ea-default.yaml"); // get the yaml resource // yaml mapper ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory()); DefaultConfiguration configuration = objectMapper.readValue(new FileInputStream(configFile), DefaultConfiguration.class); assertEquals(configuration.getName(), "default"); assertEquals(configuration.getNumberOfShards(), 8); assertNotNull(configuration.getRemoteConfigurations()); assertFalse(configuration.getRemoteConfigurations().isEmpty()); assertEquals(configuration.getRemoteConfigurations().size(), 2); assertEquals(configuration.getRemoteConfigurations().get(0).getClusterName(), "test2.elasticsoftware.org"); assertEquals(configuration.getRemoteConfigurations().get(1).getClusterName(), "test3.elasticsoftware.org"); //assertEquals(configuration.getProperty(HttpService.class, "listenPort", Integer.class, 9090),new Integer(8080)); }
From source file:com.us.data.ContentTypeProcesser.java
@Override public void doProcess(Object data) { log.info("?HttpResponse?"); String fileLocation = data.toString(); try {//from ww w .j a va 2s . c om ALL_TYPES = JSONHelper.readJSON(ResourceUtils.getFile(fileLocation)); } catch (FileNotFoundException e) { throw UsMsgException.newInstance(String.format("?[%s]", fileLocation), e); } }
From source file:com.idtmatter.insta4j.client.config.DefaultInstaClientConfig.java
private void init() { final Properties PROPERTIES = new Properties(); FileInputStream st = null;//from w w w.j a va2s . c om try { //TODO: Avoid using ResourceUtils. st = new FileInputStream(ResourceUtils.getFile("classpath:" + PROPERTY_JINSTAPAPER_PROPERTY_NAME)); PROPERTIES.load(st); } catch (IOException e) { // ignore } finally { if (st != null) { try { st.close(); } catch (IOException ex) { // ignore } } } for (final String name : new String[] { PROPERTY_CONSUMER_KEY, PROPERTY_CONSUMER_SECRET }) { final String value = System.getProperty(name); if (value != null) { PROPERTIES.setProperty(name, value); } } if (PROPERTIES.getProperty(PROPERTY_CONSUMER_KEY) == null || PROPERTIES.getProperty(PROPERTY_CONSUMER_SECRET) == null) { throw new IllegalArgumentException(String.format( "No consumerKey and/or consumerSecret found in %s file. " + "You have to provide these as system properties.", PROPERTY_JINSTAPAPER_PROPERTY_NAME)); } for (final Map.Entry<Object, Object> entry : PROPERTIES.entrySet()) { properties.put((String) entry.getKey(), entry.getValue()); } }
From source file:com.gzj.tulip.load.vfs.SimpleFileObject.java
SimpleFileObject(FileSystemManager fs, URL url) throws FileNotFoundException, MalformedURLException { this.fs = fs; File file = ResourceUtils.getFile(url); String urlString = url.toString(); this.url = url; this.file = file; this.urlString = urlString; this.fileName = new FileNameImpl(this, file.getName()); }
From source file:org.paxml.bean.UnzipTag.java
@Override protected Object doInvoke(Context context) throws Exception { unzip(ResourceUtils.getFile(file), ResourceUtils.getFile(dir)); return null; }
From source file:com.us.bo.UserBo.java
public void sendMail(User user) { try {// w ww .ja v a 2 s. com Map<String, Object> data = MapHelper.hashMap(); data.put("userName", user.getLoginID()); data.put("usermail", user.getMail()); String path = "http://127.0.0.1:10000/img/app/AddProfile.do?name=%s&mail=%s&active=%s"; data.put("url", String.format(path, user.getLoginID(), user.getMail(), HashUtil.hashAll(user.getLoginID(), user.getMail()))); String reader = FileUtils.readFileToString(ResourceUtils.getFile("classpath:/ftls/mails/newUser.html")); String mailContent = FtlUtil.render2Str(data, reader); Email email = Email.newMail(user.getMail(), "chongqinghxh@163.com", "?", mailContent); mailBo.send(email); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.slc.sli.ingestion.IngestionTest.java
public static InputStream getFileInputStream(String fileResourcePath) throws FileNotFoundException { if (!fileResourcePath.startsWith("classpath:")) { fileResourcePath = "classpath:" + fileResourcePath; }// w w w . jav a 2s . c o m File file = ResourceUtils.getFile(fileResourcePath); return new BufferedInputStream(new FileInputStream(file)); }