List of usage examples for org.springframework.core.io Resource getInputStream
InputStream getInputStream() throws IOException;
From source file:org.obiba.onyx.engine.variable.export.OnyxDataExportReader.java
@SuppressWarnings("unchecked") public List<OnyxDataExportDestination> read() throws IOException { List<OnyxDataExportDestination> onyxDestinations = new ArrayList<OnyxDataExportDestination>(); for (int i = 0; i < this.resources.length; i++) { Resource resource = this.resources[i]; if (resource.exists()) { onyxDestinations/* ww w . jav a2 s . c o m*/ .addAll((List<OnyxDataExportDestination>) xstream.fromXML(resource.getInputStream())); } } return onyxDestinations; }
From source file:org.openlmis.fulfillment.Resource2DbTest.java
@Test(expected = IllegalArgumentException.class) public void resourceCsvToBatchedPairShouldThrowExceptionIfRecordIsInconsistent() throws IOException { // given//from www . java 2 s. co m Resource resource = mock(Resource.class); InputStream inputStream = spy(IOUtils.toInputStream("Col1,Col2\na,b,c")); when(resource.getInputStream()).thenReturn(inputStream); // when resource2Db.resourceCsvToBatchedPair(resource); }
From source file:org.dkpro.similarity.experiments.sts2013baseline.util.StopwordFilter.java
@SuppressWarnings("unchecked") @Override//from ww w .j a v a 2 s. com public void initialize(UimaContext context) throws ResourceInitializationException { super.initialize(context); try { annotationType = (Class<? extends Annotation>) Class.forName(annotationTypeName); } catch (ClassNotFoundException e) { throw new ResourceInitializationException(e); } PathMatchingResourcePatternResolver r = new PathMatchingResourcePatternResolver(); Resource res = r.getResource(stopwordList); InputStream s; try { s = res.getInputStream(); } catch (IOException e) { throw new ResourceInitializationException(e); } loadStopwords(s); }
From source file:ru.jts_dev.gameserver.parser.impl.PcParametersHolder.java
@PostConstruct private void parse() throws IOException { log.info("Loading data file: pc_parameter.txt"); Resource file = context.getResource("scripts/pc_parameter.txt"); try (InputStream is = file.getInputStream()) { ANTLRInputStream input = new ANTLRInputStream(is); PcParametersLexer lexer = new PcParametersLexer(input); CommonTokenStream tokens = new CommonTokenStream(lexer); PcParametersParser parser = new PcParametersParser(tokens); ParseTree tree = parser.file();//from w w w.ja v a2 s .c o m ParseTreeWalker walker = new ParseTreeWalker(); walker.walk(this, tree); } }
From source file:ws.antonov.config.provider.ResourceConfigProvider.java
public Message.Builder retrieveConfigData(Class<? extends Message> configClass, ConfigParamsBuilder.ConfigParamsMap configParams) throws IOException { Resource resource = computeResourceDestinationFromParams(configParams); try {/*from ww w . j av a2s . co m*/ return convertMessage(configClass, determineContentType(resource), resource.getInputStream()); } catch (Exception e) { throw new IOException("Unable to load requested config from " + resource.getDescription(), e); } finally { resource.getInputStream().close(); } }
From source file:it.tidalwave.northernwind.frontend.ui.component.gallery.spi.GalleryAdapterSupport.java
/******************************************************************************************************************* * * * ******************************************************************************************************************/ @Nonnull/*from w ww . j a va 2 s . c o m*/ private String loadDefaultTemplate(final @Nonnull String templateName) throws IOException { final String packagePath = getClass().getPackage().getName().replace('.', '/'); final Resource resource = new ClassPathResource("/" + packagePath + "/" + templateName); final @Cleanup Reader r = new InputStreamReader(resource.getInputStream()); final char[] buffer = new char[(int) resource.contentLength()]; r.read(buffer); return new String(buffer); }
From source file:com.complexible.stardog.ext.spring.DataImporter.java
/** * Loads any configured resources at init time * (non-Javadoc)//w w w . j a v a2 s. co m * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet() */ @Override public void afterPropertiesSet() throws Exception { if (inputFiles == null) { return; } snarlTemplate.execute(new ConnectionCallback<Boolean>() { @Override public Boolean doWithConnection(Connection connection) { try { for (Resource entry : inputFiles) { connection.add().io().format(format).stream(entry.getInputStream()); } } catch (StardogException e) { log.error("Error with io adder to Stardog", e); return false; } catch (IOException e) { log.error("Error reading files for DataImporter initialization", e); return false; } return true; } }); }
From source file:com.datazuul.iiif.presentation.backend.repository.impl.PresentationRepositoryImpl.java
@Override public Manifest getManifest(String identifier) throws NotFoundException { Manifest manifest = null;// w w w . ja v a 2 s.c om LOGGER.debug("Try to get manifest for: " + identifier); LOGGER.debug("START getManifest() for " + identifier); PresentationResolver resolver = getManifestResolver(identifier); URI manifestUri = resolver.getURI(identifier); String json; try { if (manifestUri.getScheme().equals("file")) { json = IOUtils.toString(manifestUri); manifest = objectMapper.readValue(json, Manifest.class); } else if (manifestUri.getScheme().equals("classpath")) { Resource resource = applicationContext.getResource(manifestUri.toString()); InputStream is = resource.getInputStream(); json = IOUtils.toString(is); manifest = objectMapper.readValue(json, Manifest.class); } else if (manifestUri.getScheme().startsWith("http")) { String cacheKey = getCacheKey(identifier); manifest = httpCache.getIfPresent(cacheKey); if (manifest == null) { LOGGER.debug("HTTP Cache miss!"); json = httpExecutor.execute(Request.Get(manifestUri)).returnContent().asString(); manifest = objectMapper.readValue(json, Manifest.class); httpCache.put(cacheKey, manifest); } else { LOGGER.debug("HTTP Cache hit!"); } } } catch (IOException e) { throw new NotFoundException(e); } LOGGER.debug("DONE getManifest() for " + identifier); if (manifest == null) { throw new NotFoundException("No manifest for identifier: " + identifier); } return manifest; }
From source file:de.iteratec.iteraplan.xmi.XmiImport.java
/** * Imports the XMI data.//w w w . ja v a 2 s. c om * * @throws IOException if the {@code iteraplanData.xmi} file will be not found */ public void importData() throws IOException { LOGGER.info("Start Bank Data Import"); ConfigurableApplicationContext context = prepareEnvironment(HistoryInitialization.USE_CONFIG_FILE); try { XmiImportService xmiDeserializer = context.getBean("xmiImportService", XmiImportService.class); Resource importFile = new ClassPathResource("de/iteratec/iteraplan/xmi/iteraplanData.xmi"); xmiDeserializer.importXmi(importFile.getInputStream()); LOGGER.info("XMI data imported successfuly"); } finally { context.close(); } }
From source file:org.openlmis.fulfillment.Resource2DbTest.java
@Test public void resourceCsvToBatchedPairShouldReturnListPair() throws IOException { // given/*from w ww . j av a2 s . co m*/ Resource resource = mock(Resource.class); InputStream inputStream = spy(IOUtils.toInputStream("Col1,Col2\na,b")); when(resource.getInputStream()).thenReturn(inputStream); // when Pair<List<String>, List<Object[]>> batchedPair = resource2Db.resourceCsvToBatchedPair(resource); // then List headers = batchedPair.getLeft(); assertEquals(2, headers.size()); assertEquals("Col1", headers.get(0)); assertEquals("Col2", headers.get(1)); List rows = batchedPair.getRight(); assertEquals(1, rows.size()); Object[] rowData = batchedPair.getRight().get(0); assertEquals(2, rowData.length); assertEquals("a", rowData[0]); assertEquals("b", rowData[1]); }