01: package uk.org.ponder.springutil;
02:
03: import org.springframework.core.io.DefaultResourceLoader;
04: import org.springframework.core.io.Resource;
05: import org.springframework.core.io.InputStreamResource;
06:
07: import java.io.InputStream;
08:
09: /*
10: * @author Raymond Chan (raymond@caret.cam.ac.uk)
11: * A straightforward holder for an InputStream, wrapped as a Spring ResourceLoader.
12: * It will return the supplied stream for any request for a resource. This would
13: * typically be used with some form of request-scope proxy.
14: */
15: public class DynamicStreamResourceLoader extends DefaultResourceLoader {
16:
17: private InputStream inputstr = null;
18:
19: /*
20: * Set the InputStream from which the resource can be loaded.
21: */
22: public void setInputStream(InputStream inputstr) {
23: this .inputstr = inputstr;
24: }
25:
26: /*
27: * For whatever resource is requested, return a resource dispensing the
28: * supplied stream.
29: */
30: public Resource getResource(String wedontcarewhatthis is) {
31: return new InputStreamResource(inputstr);
32: }
33:
34: }
|