List of usage examples for org.springframework.core.io ClassPathResource getInputStream
@Override public InputStream getInputStream() throws IOException
From source file:org.openmrs.module.dhisreport.api.dxf2.DataValueSetTest.java
@Test public void unMarshallDataValueSet() throws Exception { ClassPathResource resource = new ClassPathResource("dvset.xml"); JAXBContext jaxbContext = JAXBContext.newInstance(DataValueSet.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); DataValueSet dvset = (DataValueSet) jaxbUnmarshaller.unmarshal(resource.getInputStream()); assertEquals(5, dvset.getDataValues().size()); }
From source file:org.openlmis.fulfillment.web.TemplateControllerIntegrationTest.java
@Test public void shouldReturnBadRequestWhenTemplateExist() throws IOException { ClassPathResource podReport = new ClassPathResource("jasperTemplates/proofOfDelivery.jrxml"); given(templateRepository.findByName(TEMPLATE_CONTROLLER_TEST)).willReturn(new Template()); 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(400); }// www .ja va2s . c o m assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations()); }
From source file:com.wavemaker.tools.project.CloudFoundryStudioConfigurationTest.java
@Test public void testRename() throws IOException { String oldName = "oldFile.txt"; String oldFilePath = "/old/stuff/"; String newName = "newFile.txt"; String newFilePath = "/new/stuff/"; GridFSStudioFileSystem sf = new GridFSStudioFileSystem(this.mongoFactory); ClassPathResource testFile = new ClassPathResource("/com/wavemaker/tools/project/MyStuff/FileOne.txt"); GFSResource oldRes = (GFSResource) sf.getWaveMakerHome().createRelative(oldFilePath + oldName); FileCopyUtils.copy(testFile.getInputStream(), sf.getOutputStream(oldRes)); String oldContents = FileCopyUtils.copyToString(new InputStreamReader(oldRes.getInputStream())); GFSResource newRes = (GFSResource) sf.getWaveMakerHome().createRelative(newFilePath + newName); sf.rename(oldRes, newRes);/*from w w w .jav a2s .c o m*/ assertEquals(newName, newRes.getFilename()); String newContents = FileCopyUtils.copyToString(new InputStreamReader(newRes.getInputStream())); assertEquals(oldContents, newContents); }
From source file:com.wavemaker.tools.project.CloudFoundryStudioConfigurationTest.java
@Test public void testgetOutputStream_InvalidPath() throws IOException { String fileName = "doofenshmirtz.js"; String localPath = "/com/wavemaker/tools/project"; String targetFolderName = "/MyStuff//SubFolderOne/"; String path = "/test//invalid/"; GridFSStudioFileSystem sf = new GridFSStudioFileSystem(this.mongoFactory); ClassPathResource testFile = new ClassPathResource(localPath + targetFolderName + fileName); GFSResource gfsRes = (GFSResource) sf.getWaveMakerHome().createRelative(path + fileName); try {//from w ww. j a v a 2 s .c o m FileCopyUtils.copy(testFile.getInputStream(), sf.getOutputStream(gfsRes)); fail("An error should have been thrown."); } catch (WMRuntimeException ex) { // expected } }
From source file:com.marklogic.samplestack.database.DatabaseQnADocumentSearchIT.java
private void loadJson(String path) throws ResourceNotFoundException, ForbiddenUserException, FailedRequestException, IOException { ClassPathResource resource = new ClassPathResource(path); JSONDocumentManager docMgr = operations.newJSONDocumentManager(ClientRole.SAMPLESTACK_CONTRIBUTOR); docMgr.write("/" + path, new InputStreamHandle(resource.getInputStream())); }
From source file:com.coherentlogic.treasurydirect.client.applications.MainApplication.java
@Override protected void loadResources(ApplicationContext applicationContext, Map<String, GroovyExampleBean<? extends TypedFactory<AbstractQueryBuilder<String, Object>>>> groovyExampleBeanMap, GroovyEngine groovyEngine) throws Exception { ClassPathResource securitiesExample1Resource = (ClassPathResource) applicationContext .getBean("securitiesExample1Resource"); StringWriter securitiesExample1StringWriter = new StringWriter(); InputStream securitiesExample1In = securitiesExample1Resource.getInputStream(); IOUtils.copy(securitiesExample1In, securitiesExample1StringWriter); String securitiesExample1Example = securitiesExample1StringWriter.toString(); groovyExampleBeanMap.put("Securities Example (1)", new GroovyExampleBean<TypedFactory<AbstractQueryBuilder<String, Object>>>(securitiesExample1Example, queryBuilderFactory, groovyEngine)); // --------------------- ClassPathResource securitiesExample2Resource = (ClassPathResource) applicationContext .getBean("securitiesExample2Resource"); StringWriter securitiesExample2StringWriter = new StringWriter(); InputStream securitiesExample2In = securitiesExample2Resource.getInputStream(); IOUtils.copy(securitiesExample2In, securitiesExample2StringWriter); String securitiesExample2Example = securitiesExample2StringWriter.toString(); groovyExampleBeanMap.put("Securities Example (2)", new GroovyExampleBean<TypedFactory<AbstractQueryBuilder<String, Object>>>(securitiesExample2Example, queryBuilderFactory, groovyEngine)); // --------------------- ClassPathResource securitiesMultipleResultsWithDataFrameExampleResource = (ClassPathResource) applicationContext .getBean("securitiesMultipleResultsWithDataFrameExampleResource"); StringWriter securitiesMultipleResultsWithDataFrameExampleStringWriter = new StringWriter(); InputStream securitiesMultipleResultsWithDataFrameExampleIn = securitiesMultipleResultsWithDataFrameExampleResource .getInputStream();// w w w . ja va 2 s.c o m IOUtils.copy(securitiesMultipleResultsWithDataFrameExampleIn, securitiesMultipleResultsWithDataFrameExampleStringWriter); String securitiesMultipleResultsWithDataFrameExample = securitiesMultipleResultsWithDataFrameExampleStringWriter .toString(); groovyExampleBeanMap.put("Securities Example (3)", new GroovyExampleBean<TypedFactory<AbstractQueryBuilder<String, Object>>>( securitiesMultipleResultsWithDataFrameExample, queryBuilderFactory, groovyEngine)); // --------------------- ClassPathResource debtsMultipleResultsWithDataFrameExampleResource = (ClassPathResource) applicationContext .getBean("debtsMultipleResultsWithDataFrameExampleResource"); StringWriter debtsMultipleResultsWithDataFrameExampleStringWriter = new StringWriter(); InputStream debtsMultipleResultsWithDataFrameExampleIn = debtsMultipleResultsWithDataFrameExampleResource .getInputStream(); IOUtils.copy(debtsMultipleResultsWithDataFrameExampleIn, debtsMultipleResultsWithDataFrameExampleStringWriter); String debtsMultipleResultsWithDataFrameExample = debtsMultipleResultsWithDataFrameExampleStringWriter .toString(); groovyExampleBeanMap.put("Debt Example (1)", new GroovyExampleBean<TypedFactory<AbstractQueryBuilder<String, Object>>>( debtsMultipleResultsWithDataFrameExample, queryBuilderFactory, groovyEngine)); // --------------------- Distributed cache enabled below. groovyExampleBeanMap.put("Debt Example (2) with distributed cache set on the queryBuilder", new GroovyExampleBean<TypedFactory<AbstractQueryBuilder<String, Object>>>( debtsMultipleResultsWithDataFrameExample, distributedCacheEnabledQueryBuilderFactory, groovyEngine)); }
From source file:com.wavemaker.tools.project.CloudFoundryStudioConfigurationTest.java
@Test public void testgetOutputStream() throws IOException { String fileName = "doofenshmirtz.js"; String localPath = "/com/wavemaker/tools/project"; String targetFolderName = "/MyStuff/SubFolderOne/"; String path = "/test/js/"; GridFSStudioFileSystem sf = new GridFSStudioFileSystem(this.mongoFactory); ClassPathResource testFile = new ClassPathResource(localPath + targetFolderName + fileName); GFSResource gfsRes = (GFSResource) sf.getWaveMakerHome().createRelative(path + fileName); String localContents = FileCopyUtils.copyToString(new InputStreamReader(testFile.getInputStream())); FileCopyUtils.copy(testFile.getInputStream(), sf.getOutputStream(gfsRes)); String gfsResString = FileCopyUtils.copyToString(new InputStreamReader(gfsRes.getInputStream())); assertEquals(localContents, gfsResString); }
From source file:eu.databata.engine.dao.PropagationDAO.java
private String readSqlFromFile(String filePath) { // Enumeration<URL> findEntries = bundleContext.getBundle().findEntries(".", filePath, false); String fileLocation = "META-INF/databata/" + filePath; LOG.info("Reading file from " + fileLocation); ClassPathResource classPathResource = new ClassPathResource(fileLocation); try { String sqlFile = PropagationUtils.readFile(classPathResource.getInputStream()); sqlFile = sqlFile.replaceAll("--.*$\n", ""); return sqlFile; } catch (IOException e) { LOG.error("Cannot read " + fileLocation + " file from classpath."); throw new RuntimeException(e); }//w w w. j av a2s . com }
From source file:chronos.mbeans.QuartzSchedulerAdapter.java
/** * @param factory/*from w w w . j a v a2 s. c o m*/ * {@link StdSchedulerFactory} * @throws SchedulerException * on exception */ private void createOwnScheduler(final StdSchedulerFactory factory) throws SchedulerException { logger.debug("Creating new Quartz scheduler..."); final ClassPathResource resource = new ClassPathResource("quartz.properties"); if (resource.exists() && resource.isReadable()) { logger.debug("Configuring Quartz from resource: " + resource.getPath()); try { final InputStream is = resource.getInputStream(); try { factory.initialize(is); } finally { is.close(); } } catch (final IOException e) { logger.debug("Exception initializing from resource: " + e.getMessage(), e); } } else { logger.debug("Using minimal default properties"); final Properties props = new Properties(); props.put(PROP_SCHED_INSTANCE_NAME, schedulerInstanceName); props.put(PROP_THREAD_POOL_CLASS, SimpleThreadPool.class.getName()); factory.initialize(props); } }
From source file:ru.anr.base.tests.GlassfishLoader.java
/** * Executes a file with asadmin commands * //from w ww . j a v a 2 s . c o m * @param fileName * Name of a file * @throws IOException * In case of File not found * @throws GlassFishException * In case of Glassfish error */ private void executeScript(String fileName) throws IOException, GlassFishException { ClassPathResource script = new ClassPathResource(fileName); if (script.exists()) { List<String> lines = IOUtils.readLines(script.getInputStream()); CommandRunner cmd = glassfish.getCommandRunner(); for (String l : lines) { String[] tokens = translateCommandline(l); if (tokens.length == 0 || "#".equals(tokens[0])) { continue; } String[] args = ArrayUtils.subarray(tokens, 1, tokens.length); logger.info("Runnning a command: {} {}", tokens[0], args); CommandResult r = cmd.run(tokens[0], args); switch (r.getExitStatus()) { case SUCCESS: logger.info("SUCCESS >> {}", r.getOutput()); break; case WARNING: logger.info("WARNING >> {} ( {} )", r.getOutput(), r.getFailureCause()); break; case FAILURE: logger.info("ERROR >> \n{}", r.getOutput(), r.getFailureCause()); throw new ApplicationException(r.getFailureCause()); default: } } } else { logger.info("'glassfish.txt' file not found"); } }