Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private ResourceStreamResource getDynamicResourceStreamResource(final String key, final String cType,
- boolean asAttachment) {
- ResourceStreamResource res = null;
- res = new ResourceStreamResource() {
- @Override
- protected IResourceStream getResourceStream() {
- AbstractResourceStream stream = new AbstractResourceStream() {
- private InputStream stream;
- @Override
- public InputStream getInputStream() throws ResourceStreamNotFoundException {
- AttachmentInputStream attIS = CouchDB.INSTANCE.getCouchDbConnector().getAttachment(doc.getId(),
- key);
- stream = new BufferedInputStream(attIS);
- return stream;
- }
- @Override
- public String getContentType() {
- return cType;
- }
- @Override
- public void close() throws IOException {
- stream.close();
- }
- };
- return stream;
- }
- };
- res.setFileName(key);
- res.setCacheDuration(Duration.NONE);
- if (asAttachment) {
- res.setContentDisposition(ContentDisposition.ATTACHMENT);
- } else {
- res.setContentDisposition(ContentDisposition.INLINE);
- }
- return res;
- }
Advertisement
Add Comment
Please, Sign In to add comment