List of usage examples for org.springframework.core.io Resource getInputStream
InputStream getInputStream() throws IOException;
From source file:cherry.foundation.sql.SqlExecutorImpl.java
/** * SQL?//from w w w .ja va 2 s . co m * * @param dataSource * @param resource SQL?? * @param paramMap SQL??? * @param continueOnError SQL????? * @throws IOException SQL??? */ @Override public void execute(DataSource dataSource, Resource resource, Map<String, ?> paramMap, boolean continueOnError) throws IOException { try (InputStream in = resource.getInputStream()) { execute(dataSource, in, paramMap, continueOnError); } }
From source file:org.jasig.portlet.widget.service.GoogleGadgetServiceTest.java
@Test public void testListGadgets() throws IOException { Resource mainPage = context.getResource("org/jasig/portlet/widget/service/gadgetListingMainPage.html"); doReturn(mainPage.getInputStream()).when(service).getStreamFromUrl(anyString()); GadgetList list = service.getGadgets(null, null, 0); assertEquals(24, list.getGadgets().size()); assertEquals(213028, list.getTotal()); GadgetEntry first = list.getGadgets().get(0); assertEquals("Google Calendar Viewer", first.getName()); assertEquals("http://ralph.feedback.googlepages.com/googlecalendarviewer_thumbnail.png", first.getImageUrl());/*from w w w .j a va 2 s . c o m*/ assertEquals("http://ralph.feedback.googlepages.com/googlecalendarviewer.xml", first.getConfigUrl()); }
From source file:com.fns.grivet.service.NamedQueryServiceSprocTest.java
@Test public void testNamedQueryNotExecutedBecauseItDidNotContainRequiredParamForExecution() throws IOException { Assertions.assertThrows(IllegalArgumentException.class, () -> { Resource r = resolver.getResource("classpath:TestSprocQuery.json"); String json = IOUtils.toString(r.getInputStream(), Charset.defaultCharset()); NamedQuery namedQuery = objectMapper.readValue(json, NamedQuery.class); namedQueryService.create(namedQuery); namedQueryService.get("sproc.getAttributesCreatedBefore", null); });//from w ww. j a v a2 s . com }
From source file:com.imudges.utils.PropertiesLoader.java
/** * , Spring Resource?. // w w w . j a v a 2 s. c om */ private Properties loadProperties(String... resourcesPaths) { Properties props = new Properties(); for (String location : resourcesPaths) { // logger.debug("Loading properties file from:" + location); InputStream is = null; try { Resource resource = resourceLoader.getResource(location); is = resource.getInputStream(); props.load(is); } catch (IOException ex) { logger.info("Could not load properties from path:" + location + ", " + ex.getMessage()); } finally { IOUtils.closeQuietly(is); } } return props; }
From source file:com.wxwall.common.utils.PropertiesLoader.java
/** * , Spring Resource?.//from w w w . ja v a 2 s. c om */ private Properties loadProperties(String... resourcesPaths) { Properties props = new Properties(); for (String location : resourcesPaths) { InputStream is = null; try { Resource resource = resourceLoader.getResource(location); is = resource.getInputStream(); props.load(is); } catch (IOException ex) { LOG.info("Could not load properties from path:" + location + ", " + ex.getMessage()); } finally { IOUtils.closeQuietly(is); } } return props; }
From source file:org.apache.uima.ruta.resource.CSVTable.java
/** * @param table/*from w ww.j a va 2 s. c o m*/ * A CSV table. * @throws IOException * When there is a problem opening, reading or closing the table. */ public CSVTable(Resource table) throws IOException { InputStream stream = null; try { stream = table.getInputStream(); buildTable(stream); } finally { if (stream != null) { stream.close(); } } }
From source file:com.fns.grivet.service.NamedQueryServiceSprocTest.java
@Test public void testSuccessfulNamedQueryExecution() throws IOException { Resource r = resolver.getResource("classpath:TestSprocQuery.json"); String json = IOUtils.toString(r.getInputStream(), Charset.defaultCharset()); NamedQuery namedQuery = objectMapper.readValue(json, NamedQuery.class); namedQueryService.create(namedQuery); MultiValueMap<String, Object> params = new LinkedMultiValueMap<>(); Timestamp tomorrow = Timestamp.valueOf(LocalDateTime.now().plusDays(1)); params.add("createdTime", tomorrow); String result = namedQueryService.get("sproc.getAttributesCreatedBefore", params); String[] expected = { "bigint", "varchar", "decimal", "datetime", "int", "text", "json", "boolean" }; List<String> actual = JsonPath.given(result).getList("NAME"); Assertions.assertTrue(actual.size() == 8, "Result should contain 8 attributes"); Assertions.assertTrue(actual.containsAll(Arrays.asList(expected))); }
From source file:cn.org.citycloud.srdz.utils.PropertiesLoader.java
/** * , Spring Resource?./*from w w w . ja va 2 s. c om*/ */ private Properties loadProperties(String... resourcesPaths) { Properties props = new Properties(); for (String location : resourcesPaths) { // logger.debug("Loading properties file from:" + location); InputStream is = null; try { Resource resource = resourceLoader.getResource(location); is = resource.getInputStream(); props.load(is); } catch (IOException ex) { logger.info("Could not load properties from path:" + location + ", " + ex.getMessage()); } finally { IOUtils.closeQuietly(is); } } return props; }
From source file:com.ddubyat.develop.jhawtcode.util.PropertyUtil.java
private boolean validLicense(String email, String licenseCode) throws Exception { Resource res = applicationContext.getResource("classpath:jhc-public.der"); InputStream is = res.getInputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[4096]; byte[] pkey;//w ww. j a va 2s .c o m int stream; while ((stream = is.read(buffer, 0, buffer.length)) != -1) { baos.write(buffer, 0, stream); } pkey = baos.toByteArray(); X509EncodedKeySpec keySpec = new X509EncodedKeySpec(pkey); KeyFactory keyFactory = KeyFactory.getInstance("RSA"); PublicKey mypk = keyFactory.generatePublic(keySpec); Signature instance = Signature.getInstance("SHA1withRSA"); instance.initVerify(mypk); instance.update(email.getBytes()); //BASE64Decoder decoder = new BASE64Decoder(); //byte[] decodedBytes = decoder.decodeBuffer(licenseCode); return instance.verify(DatatypeConverter.parseBase64Binary(licenseCode)); }
From source file:com.kixeye.chassis.transport.websocket.WebSocketPskFrameProcessor.java
/** * @param cipherProvider/* w w w . j a v a2s .c om*/ * @param cipherTransformation * @param secretKeyProvider * @param secretKeyAlgorithm * @param secretKeyData * @param secretKeyPath * @param enabled * @param secretKey */ @Autowired public WebSocketPskFrameProcessor(@Value("${websocket.crypto.cipherProvider:}") String cipherProvider, @Value("${websocket.crypto.cipherTransformation:}") String cipherTransformation, @Value("${websocket.crypto.secretKeyAlgorithm:}") String secretKeyAlgorithm, @Value("${websocket.crypto.secretKeyData:}") String secretKeyData, @Value("${websocket.crypto.secretKeyPath:}") String secretKeyPath, @Value("${websocket.crypto.enabled:false}") boolean enabled) throws Exception { if (enabled) { byte[] secretKey = null; if (StringUtils.isNoneBlank(secretKeyData)) { secretKey = BaseEncoding.base16().decode(secretKeyData); } else if (StringUtils.isNoneBlank(secretKeyPath)) { Resource secretKeyFile = RESOURCE_LOADER.getResource(secretKeyPath); secretKey = IOUtils.toByteArray(secretKeyFile.getInputStream()); } else { throw new IllegalArgumentException("Neither secret key data nor path were provided."); } cipher = new SymmetricKeyCipher(cipherProvider, cipherTransformation, secretKeyAlgorithm, secretKey); } else { cipher = null; } }