Java Code Examples for org.springframework.core.io.support.PathMatchingResourcePatternResolver#getResource()
The following examples show how to use
org.springframework.core.io.support.PathMatchingResourcePatternResolver#getResource() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WeEventFileClientTest.java From WeEvent with Apache License 2.0 | 6 votes |
@Test @Ignore public void testPublishFileWithVerify() throws Exception { PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); Resource resource = resolver.getResource("classpath:" + "0x2809a9902e47d6fcaabe6d0183855d9201c93af1.public.pem"); WeEventFileClient weEventFileClient = new WeEventFileClient(this.groupId, this.localReceivePath, this.fileChunkSize, this.fiscoConfig); weEventFileClient.openTransport4Sender(this.topicName, resource.getInputStream()); // handshake time delay for web3sdk Thread.sleep(1000*10); FileChunksMeta fileChunksMeta = weEventFileClient.publishFile(this.topicName, new File("src/main/resources/ca.crt").getAbsolutePath(), true); Assert.assertNotNull(fileChunksMeta); }
Example 2
Source File: WeEventFileClientTest.java From WeEvent with Apache License 2.0 | 6 votes |
@Test public void testSubscribeFileWithVerify() throws Exception { PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); Resource resource = resolver.getResource("classpath:" + "0x2809a9902e47d6fcaabe6d0183855d9201c93af1.pem"); IWeEventFileClient.FileListener fileListener = new IWeEventFileClient.FileListener() { @Override public void onFile(String topicName, String fileName) { log.info("+++++++topic name: {}, file name: {}", topicName, fileName); System.out.println(new File(localReceivePath + "/" + fileName).getPath()); } @Override public void onException(Throwable e) { e.printStackTrace(); } }; WeEventFileClient weEventFileClient = new WeEventFileClient(this.groupId, this.localReceivePath, this.fileChunkSize, this.fiscoConfig); weEventFileClient.openTransport4Receiver(this.topicName, fileListener, resource.getInputStream()); Thread.sleep(1000); Assert.assertTrue(true); }
Example 3
Source File: BeanConfig.java From WeBASE-Codegen-Monkey with Apache License 2.0 | 6 votes |
@Bean public Map<String, Web3jTypeVO> getCustomDefineWeb3jMap() throws IOException { PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); Resource def = resolver.getResource("file:config/web3j.def"); File defFile = def.getFile(); Map<String, Web3jTypeVO> map = new HashMap<String, Web3jTypeVO>(); if (defFile.exists()) { log.info("defFile detect."); List<String> lines = FileUtils.readLines(defFile, "utf8"); if (!CollectionUtils.isEmpty(lines)) { for (String line : lines) { line = line.replaceAll("\"", ""); String[] tokens = StringUtils.split(line, ","); if (tokens.length < 4) { continue; } Web3jTypeVO vo = new Web3jTypeVO(); vo.setSolidityType(tokens[0]).setSqlType(tokens[1]).setJavaType(tokens[2]).setTypeMethod(tokens[3]); map.put(tokens[0], vo); log.info("Find Web3j type definetion : {}", JacksonUtils.toJson(vo)); } } } return map; }
Example 4
Source File: PathUtil.java From n2o-framework with Apache License 2.0 | 6 votes |
public static Resource getContentByPathPattern(String path) { PathMatchingResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver(); Resource resource = null; if (path.contains("*")) { try { Resource[] resources = resourcePatternResolver.getResources(path); if (resources.length != 0 && resources[0].exists()) resource = resources[0]; } catch (IOException e) { throw new RuntimeException(e); } } else { resource = resourcePatternResolver.getResource(path); } return resource; }
Example 5
Source File: SelfRestCaller.java From entando-core with GNU Lesser General Public License v3.0 | 6 votes |
private String getContentBody(SelfRestCallPostProcess selfRestCall) throws Throwable { String contentBody = selfRestCall.getContentBody(); if ((null == contentBody || contentBody.trim().length() == 0) && null != selfRestCall.getContentBodyPath()) { String path = selfRestCall.getContentBodyPath(); InputStream is = null; PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); Resource resource = resolver.getResource(path); try { is = resource.getInputStream(); contentBody = FileTextReader.getText(is); } catch (Throwable t) { _logger.error("Error loading contentBody from file '{}'", path, t); //ApsSystemUtils.logThrowable(t, this, "getContentBody", "Error loading contentBody from file '" + path + "'"); throw t; } finally { if (null != is) { is.close(); } } } return contentBody; }
Example 6
Source File: Web3jV2BeanConfig.java From WeBASE-Collect-Bee with Apache License 2.0 | 5 votes |
@Bean public GroupChannelConnectionsConfig getGroupChannelConnections() { GroupChannelConnectionsConfig groupChannelConnectionsConfig = new GroupChannelConnectionsConfig(); ChannelConnections con = new ChannelConnections(); PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); Resource ca = resolver.getResource("file:./config/ca.crt"); Resource nodeCrt = resolver.getResource("file:./config/node.crt"); Resource nodeKey = resolver.getResource("file:./config/node.key"); groupChannelConnectionsConfig.setCaCert(ca); groupChannelConnectionsConfig.setSslCert(nodeCrt); groupChannelConnectionsConfig.setSslKey(nodeKey); ArrayList<String> list = new ArrayList<>(); List<ChannelConnections> allChannelConnections = new ArrayList<>(); String[] nodes = StringUtils.split(systemEnvironmentConfig.getNodeStr(), ";"); for (int i = 0; i < nodes.length; i++) { if (nodes[i].contains("@")) { nodes[i] = StringUtils.substringAfter(nodes[i], "@"); } } List<String> nodesList = Lists.newArrayList(nodes); list.addAll(nodesList); list.stream().forEach(s -> { log.info("connect address: {}", s); }); con.setConnectionsStr(list); con.setGroupId(systemEnvironmentConfig.getGroupId()); allChannelConnections.add(con); groupChannelConnectionsConfig.setAllChannelConnections(allChannelConnections); return groupChannelConnectionsConfig; }
Example 7
Source File: Web3SDKConnector.java From WeEvent with Apache License 2.0 | 5 votes |
public static Credentials getCredentials(FiscoConfig fiscoConfig) { log.debug("begin init Credentials"); // read OSSCA account String privateKey; if (fiscoConfig.getWeb3sdkEncryptType().equals("SM2_TYPE")) { log.info("SM2_TYPE"); try { PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); Resource resource = resolver.getResource("classpath:" + fiscoConfig.getPemKeyPath()); PEMManager pemManager = new PEMManager(); pemManager.load(resource.getInputStream()); ECKeyPair pemKeyPair = pemManager.getECKeyPair(); privateKey = pemKeyPair.getPrivateKey().toString(16); } catch (UnrecoverableKeyException | KeyStoreException | NoSuchAlgorithmException | InvalidKeySpecException | NoSuchProviderException | CertificateException | IOException e) { log.error("Init OSSCA Credentials failed", e); return null; } } else { privateKey = fiscoConfig.getAccount(); } Credentials credentials = GenCredential.create(privateKey); if (null == credentials) { log.error("init Credentials failed"); return null; } log.info("init Credentials success"); return credentials; }
Example 8
Source File: Brand.java From celerio with Apache License 2.0 | 5 votes |
public Brand() { brandingPath = System.getProperty("user.home") + "/.celerio/branding.properties"; logoPath = System.getProperty("user.home") + "/.celerio/" + logoFilename; try { Properties p = new Properties(); File f = new File(brandingPath); if (f.exists()) { p.load(new FileInputStream(f)); companyName = p.getProperty("company_name", companyName); companyUrl = p.getProperty("company_url", companyUrl); footer = p.getProperty("footer", footer); rootPackage = p.getProperty("root_package", rootPackage); } else { p.setProperty("root_package", rootPackage); p.setProperty("company_name", companyName); p.setProperty("company_url", companyUrl); p.setProperty("footer", footer); if (!f.getParentFile().exists()) { f.getParentFile().mkdirs(); } p.store(new FileOutputStream(f), "CELERIO BRANDING"); } // copy logo if not present File logo = new File(logoPath); if (!logo.exists()) { PathMatchingResourcePatternResolver o = new PathMatchingResourcePatternResolver(); Resource defaultBrandLogo = o.getResource("classpath:/brand-logo.png"); new FileOutputStream(logo).write(IOUtils.toByteArray(defaultBrandLogo.getInputStream())); } } catch (Exception e) { throw new RuntimeException(e); } }
Example 9
Source File: AbstractComponentModule.java From entando-core with GNU Lesser General Public License v3.0 | 5 votes |
@Override public Resource getSqlResources(String datasourceName) { String path = this.getSqlResourcesPaths().get(datasourceName); if (null == path || path.isEmpty()) { return null; } PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); return resolver.getResource(path); }