List of usage examples for org.springframework.core.io ClassPathResource getInputStream
@Override public InputStream getInputStream() throws IOException
From source file:com.github.mrstampy.gameboot.otp.OtpTestConfiguration.java
private InputStream getResource(String name) throws Exception { ClassPathResource r = new ClassPathResource(name); if (!r.exists()) throw new IllegalStateException("No " + name + " on the classpath"); return r.getInputStream(); }
From source file:com.uimirror.auth.StartApp.java
private File getKeyStoreFile() throws IOException { ClassPathResource resource = new ClassPathResource("keystore"); try {//from w w w. j ava2 s .c o m return resource.getFile(); } catch (Exception ex) { File temp = File.createTempFile("keystore", ".tmp"); FileCopyUtils.copy(resource.getInputStream(), new FileOutputStream(temp)); return temp; } }
From source file:org.nd4j.linalg.jcublas.kernel.KernelFunctionLoaderTests.java
@Test public void testLoader() throws Exception { Nd4j.dtype = DataBuffer.DOUBLE; KernelFunctionLoader loader = KernelFunctionLoader.getInstance(); loader.load();/*from w w w. j a v a 2 s .c om*/ ClassPathResource res = new ClassPathResource("/cudafunctions.properties"); if (!res.exists()) throw new IllegalStateException("Please put a cudafunctions.properties in your class path"); Properties props = new Properties(); props.load(res.getInputStream()); loader.unload(); }
From source file:magoffin.matt.sobriquet.sendmail.test.SendmailAliasLDIFGeneratorTests.java
@Test public void generateSamples() throws IOException { ClassPathResource r = new ClassPathResource("aliases.txt", getClass()); InputStreamReader in = null;// ww w . j a v a 2s . c o m ByteArrayOutputStream byos = new ByteArrayOutputStream(); try { in = new InputStreamReader(r.getInputStream()); SendmailAliasFileParser parser = new SendmailAliasFileParser(in); SendmailAliasLDIFGenerator gen = new SendmailAliasLDIFGenerator("ou=Test", "aliases", "example.com"); gen.generate(parser, byos); String generated = new String(byos.toByteArray(), "US-ASCII"); log.debug("Generated LDIF:\n{}", generated); String expected = FileCopyUtils .copyToString(new FileReader(new ClassPathResource("aliases.ldif", getClass()).getFile())); Assert.assertEquals("Generated LDIF", expected, generated); } finally { if (in != null) { try { in.close(); } catch (IOException e) { // ignore } } } }
From source file:org.cagrid.gaards.websso.utils.FileHelper.java
public InputStream getFileAsStream(String fileName) throws AuthenticationConfigurationException { ClassPathResource cpr = new ClassPathResource(fileName); if (!cpr.exists()) { throw new AuthenticationConfigurationException("Unable to load " + fileName + " file"); }//from ww w . j av a 2 s .c o m try { return cpr.getInputStream(); } catch (IOException ie) { throw new AuthenticationConfigurationException("Unable to load " + fileName + " file"); } }
From source file:org.flywaydb.test.junit.FlywayHelperFactory.java
/** * Create a new flyway instance and call {@link Flyway#configure(java.util.Properties)} with * content of file <i>flyway.properties</i>. * * @return the flyway instance//from w w w . j av a 2s. co m */ public synchronized Flyway createFlyway() { if (flyway == null) { logger.info("Create a new flyway instance."); Flyway toReturn = new Flyway(); setFlyway(toReturn); // now use the flyway properties Properties configuredProperties = getFlywayProperties(); if (configuredProperties == null) { // try to search flyway.properties in classpath configuredProperties = new Properties(); setFlywayProperties(configuredProperties); ClassPathResource classPathResource = new ClassPathResource("flyway.properties"); InputStream inputStream = null; try { inputStream = classPathResource.getInputStream(); configuredProperties.load(inputStream); inputStream.close(); } catch (IOException e) { logger.error("Can not load flyway.properties.", e); } logger.info(String.format("Load flyway.properties with %d entries.", configuredProperties.size())); } else { logger.info(String.format("Used preconfigured flyway.properties with %d entries.", configuredProperties.size())); } toReturn.configure(getFlywayProperties()); } return flyway; }
From source file:org.openlmis.fulfillment.web.TemplateControllerIntegrationTest.java
@Test public void shouldAddReportTemplate() throws IOException { ClassPathResource podReport = new ClassPathResource("jasperTemplates/proofOfDelivery.jrxml"); try (InputStream podStream = podReport.getInputStream()) { restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()) .contentType(MediaType.MULTIPART_FORM_DATA_VALUE) .multiPart("file", podReport.getFilename(), podStream) .formParam("name", TEMPLATE_CONTROLLER_TEST).formParam("description", TEMPLATE_CONTROLLER_TEST) .when().post(RESOURCE_URL).then().statusCode(200); }//from w w w . j a v a 2s .c om assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations()); }
From source file:com.enonic.cms.itest.client.InternalClientImpl_CreateImageContentTest.java
private byte[] loadImageFile(String fileName) throws IOException { ClassPathResource resource = new ClassPathResource(createFileName(fileName)); InputStream in = resource.getInputStream(); return IOUtils.toByteArray(in); }
From source file:py.una.pol.karaku.test.cucumber.DatabasePopulatorCucumberExecutionListener.java
/** * @param cpr//from w w w . ja va2s . com * @param br * @return */ private BufferedReader _getBr(ClassPathResource cpr) { try { return new BufferedReader(new InputStreamReader(cpr.getInputStream(), "UTF-8")); } catch (UnsupportedEncodingException e) { throw new KarakuRuntimeException(e); } catch (IOException e) { throw new KarakuRuntimeException("Can not load the file " + cpr.getFilename(), e); } }