List of usage examples for org.springframework.core.io Resource getInputStream
InputStream getInputStream() throws IOException;
From source file:de.ingrid.iplug.opensearch.converter.IngridRSSConverterTest.java
public final void testProcessResult() { try {// ww w. j av a 2 s. c o m Resource resource = new ClassPathResource(XML_INPUT_FILE); IngridHits hits = ingridConverter.processResult("bla", resource.getInputStream(), null); assertTrue(hits.getHits().length > 0); } catch (Exception e) { e.printStackTrace(); fail("Test failed."); } }
From source file:nz.co.senanque.madura.bundle.BundleManagerTest.java
private void testBundleName(BundleManager bm, String bundleName) { StringWrapper n = (StringWrapper) this.applicationContext.getBean("bundleName"); assertTrue(n.toString().equals(bundleName)); TestBean tb = (TestBean) this.applicationContext.getBean("TestBean"); assertTrue(tb.getContent().toString().equals(bundleName)); try {//from www . j av a 2 s . co m Resource resource = tb.getResource(); InputStream is = resource.getInputStream(); assertNotNull(is); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String line = br.readLine(); assertEquals(bundleName, line); br.close(); } catch (IOException e) { throw new RuntimeException(e); } TestBean tb1 = (TestBean) this.applicationContext.getBean("TestBean1"); assertTrue(tb1.getContent().toString().equals(bundleName)); }
From source file:svc.data.citations.datasources.mock.MockCitationDataSourceTest.java
@SuppressWarnings("unchecked") @Test//w w w. j a v a 2 s . co m public void returnsCitationsWhenGivenDOBLastNameAndMultipleMunicipalities() throws ParseException, IOException { final Violation VIOLATION = new Violation(); VIOLATION.id = 4; final List<Violation> VIOLATIONS = Lists.newArrayList(VIOLATION); final Citation CITATION = new Citation(); CITATION.id = 3; final List<Citation> CITATIONS = Lists.newArrayList(CITATION); Resource resource = mock(Resource.class); when(resource.getInputStream()).thenReturn(null); when(resourceLoader.getResource(CLASSPATH_URL_PREFIX + "sql/citation/get-by-location.sql")) .thenReturn(resource); when(jdbcTemplate.query(Matchers.anyString(), Matchers.anyMap(), Matchers.<RowMapper<Citation>>any())) .thenReturn(CITATIONS); String dateString = "08/05/1965"; DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy"); LocalDate date = LocalDate.parse(dateString, formatter); List<Citation> citations = mockCitationDataSource.getByNameAndMunicipalitiesAndDOB("someLastName", Lists.newArrayList(19L, 20L), date); when(violationManagerMock.getViolationsByCitationNumber(Matchers.anyString())).thenReturn(VIOLATIONS); assertThat(citations.get(0).id, is(3)); }
From source file:com.seovic.io.ClasspathResourceReader.java
/** * Construct reader for a classpath resource. * * @param resourceName resource name/* w ww . ja v a 2s. co m*/ * * @throws IOException if an error occurs */ public ClasspathResourceReader(String resourceName) throws IOException { Resource resource = new DefaultResourceLoader().getResource(resourceName); m_reader = new InputStreamReader(resource.getInputStream()); }
From source file:fi.helsinki.opintoni.service.BackgroundImageService.java
public BufferedImage getDefaultBackgroundImage(String fileName) throws IOException { String filePath = fileNamesToPath.get(fileName); if (filePath == null) { return null; }/* w w w .j a va 2 s . com*/ Resource resource = resolver.getResource(filePath); return imageService.inputStreamToBufferedImage(resource.getInputStream()); }
From source file:com.siberhus.tdfl.excel.DefaultExcelWorkbookFactory.java
@Override public Workbook createAndRead(Resource resource) throws IOException { String ext = getFileExtension(resource); InputStream in = resource.getInputStream(); Workbook wb = null;//from ww w.j a v a2s . c om if ("XLS".equals(ext)) { wb = new HSSFWorkbook(in); } else if ("XLSX".equals(ext)) { wb = new XSSFWorkbook(in); } else { throw new UnknownFileTypeException("Support only *.xls and *.xlsx"); } IOUtils.closeQuietly(in); return wb; }
From source file:ru.jts_dev.gameserver.parser.data.npc.NpcDatasHolder.java
@PostConstruct private void parse() throws IOException { log.info("Loading data file: npcdata.txt"); final Resource file = context.getResource("scripts/npcdata.txt"); try (InputStream is = file.getInputStream()) { final ANTLRInputStream input = new ANTLRInputStream(is); final NpcDatasLexer lexer = new NpcDatasLexer(input); final CommonTokenStream tokens = new CommonTokenStream(lexer); final NpcDatasParser parser = new NpcDatasParser(tokens); //parser.getInterpreter().setPredictionMode(PredictionMode.SLL); //parser.setErrorHandler(new BailErrorStrategy()); //parser.setProfile(false); long start = System.nanoTime(); final ParseTree tree = parser.file(); log.info("ParseTime: " + (System.nanoTime() - start) / 1_000_000); final ParseTreeWalker walker = new ParseTreeWalker(); start = System.nanoTime(); walker.walk(this, tree); log.info("WalkTime: " + (System.nanoTime() - start) / 1_000_000); }/* ww w .j av a 2 s . c o m*/ }
From source file:org.meruvian.yama.social.google.GooglePlusService.java
@Override public User createUser(Connection<?> connection) { Google google = (Google) connection.getApi(); Person profile = google.plusOperations().getGoogleProfile(); String randomUsername = RandomStringUtils.randomAlphanumeric(6); User user = new User(); user.setUsername(StringUtils.join(profile.getGivenName(), profile.getFamilyName(), randomUsername)); user.getName().setFirst(profile.getGivenName()); user.getName().setLast(profile.getFamilyName()); user.setEmail(profile.getEmailAddresses().iterator().next()); user.setPassword(RandomStringUtils.randomAlphanumeric(8)); FileInfo fileInfo = new FileInfo(); try {//w w w .ja v a 2 s. c o m Resource resource = restTemplate.getForObject(profile.getImageUrl(), Resource.class); fileInfo.setDataBlob(resource.getInputStream()); user.setFileInfo(fileInfo); } catch (Exception e) { LOG.error(e.getMessage(), e); } return user; }
From source file:org.obiba.onyx.engine.ActionDefinitionReader.java
@SuppressWarnings("unchecked") public List<ActionDefinition> read() throws IOException { List<ActionDefinition> definitions = new ArrayList<ActionDefinition>(); for (int i = 0; i < this.resources.length; i++) { Resource resource = this.resources[i]; if (resource.exists()) { definitions.addAll((List<ActionDefinition>) xstream.fromXML(resource.getInputStream())); }/*from w ww . j a v a 2 s . c o m*/ } return definitions; }
From source file:org.openmrs.cwf.api.util.OpenMRSInit.java
@Override public void setApplicationContext(ApplicationContext appContext) throws BeansException { Resource resource = appContext.getResource(propertiesFile); InputStream is = null;/* ww w .j a va2s . c om*/ try { is = resource.getInputStream(); properties.load(is); } catch (Exception e) { log.error("Error loading startup properties file: " + propertiesFile, e); } finally { IOUtils.closeQuietly(is); } }