List of usage examples for org.springframework.core.io Resource getInputStream
InputStream getInputStream() throws IOException;
From source file:org.obiba.onyx.core.domain.participant.ParticipantAttributeReader.java
@SuppressWarnings("unchecked") public List<ParticipantAttribute> read() throws IOException { List<ParticipantElement> participantElements = new ArrayList<ParticipantElement>(); for (int i = 0; i < this.resources.length; i++) { Resource resource = this.resources[i]; if (resource.exists()) { participantElements.addAll((List<ParticipantElement>) xstream.fromXML(resource.getInputStream())); }/* ww w .ja va 2 s . c o m*/ } return flatten(participantElements); }
From source file:org.web4thejob.orm.CustomSessionFactoryBean.java
private void applyResources(LocalSessionFactoryBuilder sfb) { if (ContextUtil.isInitialized()) { List<Joblet> joblets = new ArrayList<Joblet>(); joblets.add(ContextUtil.getSystemJoblet()); joblets.addAll(ContextUtil.getJoblets()); for (Joblet joblet : joblets) { for (Resource resource : joblet.getResources()) { try { sfb.addInputStream(resource.getInputStream()); } catch (IOException e) { e.printStackTrace(); throw new RuntimeException(e); }/* w w w. java2 s .c o m*/ } LOG.info("Joblet " + joblet.getName() + " has been loaded automatically."); } } else { LOG.warn("Root context not initialized yet. Falling back to classpath scanning..."); JobletScanner scanner = new JobletScanner(); for (Object clazz : scanner.getComponentClasses("org.web4thejob")) { try { Joblet joblet = (Joblet) ((Class) clazz).newInstance(); for (Resource resource : joblet.getResources()) { try { sfb.addInputStream(resource.getInputStream()); } catch (IOException e) { e.printStackTrace(); throw new RuntimeException(e); } } LOG.info("Joblet " + joblet.getName() + " has been loaded automatically."); } catch (Exception e) { e.printStackTrace(); } } } }
From source file:com.ecsteam.cloudlaunch.controller.RestServices.java
@RequestMapping(value = "/pagetext", method = RequestMethod.GET) public Map<String, List<String>> getPageText() throws IOException { Resource resource = applicationContext.getResource("classpath:/pagetext.txt"); InputStream in = resource.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); List<String> lines = new ArrayList<String>(); String line = null;/*from w w w. j a va 2s . c o m*/ while ((line = reader.readLine()) != null) { lines.add(line); } return Collections.singletonMap("pageText", lines); }
From source file:com.vilt.minium.script.test.impl.MiniumRhinoTestsSupport.java
protected Object parseJson(Context cx, Scriptable scope, Resource resource) throws ParseException, IOException { String json = IOUtils.toString(resource.getInputStream()); return parseJson(cx, scope, json); }
From source file:org.springframework.boot.cli.command.init.AbstractHttpClientMockTests.java
protected byte[] readClasspathResource(String contentPath) throws IOException { Resource resource = new ClassPathResource(contentPath); return StreamUtils.copyToByteArray(resource.getInputStream()); }
From source file:org.jnap.core.assets.HandlebarsAssetsHandler.java
@Override public void handle() { final Handlebars handlebars = new Handlebars(); try {//from w w w .ja va2 s. c o m Resource[] resources = this.resourceResolver.getResources(source); Resource destRes = new ServletContextResource(servletContext, destination); resetResource(destRes); BufferedWriter writer = new BufferedWriter( new FileWriterWithEncoding(destRes.getFile(), this.encoding, true)); writer.write("(function() {"); writer.write(IOUtils.LINE_SEPARATOR); writer.write("var template = Handlebars.template, "); writer.write("templates = Handlebars.templates = Handlebars.templates || {};"); writer.write(IOUtils.LINE_SEPARATOR); final Set<String> templateNames = new TreeSet<String>(); for (Resource resource : resources) { Template template = handlebars .compile(StringUtils.trimToEmpty(IOUtils.toString(resource.getInputStream()))); final String templateName = FilenameUtils.getBaseName(resource.getFilename()); templateNames.add(templateName); writer.write("templates[\"" + templateName + "\"] = "); writer.write("template("); writer.write(template.toJavaScript()); writer.write(");"); writer.write(IOUtils.LINE_SEPARATOR); } writer.write(IOUtils.LINE_SEPARATOR); if (this.bindToBackboneView) { writer.write("$(function() {"); writer.write(IOUtils.LINE_SEPARATOR); for (String templateName : templateNames) { writer.write(format("if (window[\"{0}\"]) {0}.prototype.template " + "= templates[\"{0}\"];", templateName)); writer.write(IOUtils.LINE_SEPARATOR); } writer.write("});"); writer.write(IOUtils.LINE_SEPARATOR); } writer.write("})();"); IOUtils.closeQuietly(writer); } catch (Exception e) { e.printStackTrace(); } }
From source file:fm.lastify.config.LastifyFmWebappConfig.java
/** * Used to configure the in-memory HSQLDB database Remove this method if * different datasource is used//from ww w .j ava 2 s. c om * * @throws IOException */ @PostConstruct public void createDatabaseTable() throws IOException { Resource resource = new ClassPathResource( "org/springframework/social/connect/jdbc/JdbcUsersConnectionRepository.sql"); BufferedInputStream is = new BufferedInputStream(resource.getInputStream()); final char[] buffer = new char[0x10000]; StringBuilder out = new StringBuilder(); Reader in = new InputStreamReader(resource.getInputStream(), "UTF-8"); int read; do { read = in.read(buffer, 0, buffer.length); if (read > 0) { out.append(buffer, 0, read); } } while (read >= 0); JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); jdbcTemplate.execute(out.toString()); }
From source file:griffon.plugins.i18n.ExtendedResourceBundleMessageSource.java
private List<ResourceBundle> loadBundleForFilename(String filename) { List<ResourceBundle> bundles = new ArrayList<ResourceBundle>(); try {/* w ww.j a va 2 s .c o m*/ Resource[] resources = resolver.getResources("classpath*:/" + filename + ".properties"); if (LOG.isTraceEnabled()) { LOG.trace("Found " + resources.length + " matches for classpath *:/" + filename + ".properties"); } for (Resource resource : resources) { if (LOG.isTraceEnabled()) LOG.trace("Initializing bundle with " + resource.getURI()); bundles.add(new PropertyResourceBundle(resource.getInputStream())); } } catch (IOException e) { // ignore } return bundles; }
From source file:org.alloy.metal.xml.merge.MergeXmlConfigResource.java
public String serialize(Resource resource) { String response = ""; try {//from www . j a v a 2 s . com response = serialize(resource.getInputStream()); } catch (IOException e) { LOG.error("Unable to merge source and patch locations", e); } return response; }
From source file:org.cleverbus.core.common.version.impl.ManifestVersionInfoSource.java
private Collection<VersionInfo> getVersionData(String location, @Nullable VersionInfo filter) throws IOException, PatternSyntaxException { Collection<VersionInfo> result = new ArrayList<VersionInfo>(); Resource[] resources = applicationContext.getResources(location); for (Resource resource : resources) { try {// ww w .ja va 2 s . c om InputStream is = resource.getInputStream(); if (is != null) { Manifest manifest = new Manifest(is); VersionInfo info = createVersionInfo(manifest); // Log.debug(location + ": " + info); // Version entries may be empty or incomplete. // Return only entries that match the specified filter. if (info.matches(filter)) { result.add(info); } } } catch (IOException e) { Log.error("Unable to process manifest resource '{}'", e, resource.getURL()); throw e; } catch (PatternSyntaxException e) { Log.error("Unable to process version data, invalid filter '{}'", e, filter.toString()); } } return result; }