Guest User

Untitled

a guest
Aug 16th, 2012
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.58 KB | None | 0 0
  1. private ResourceStreamResource getDynamicResourceStreamResource(final String key, final String cType,
  2.                                                                     boolean asAttachment) {
  3.         ResourceStreamResource res = null;
  4.  
  5.         res = new ResourceStreamResource() {
  6.  
  7.             @Override
  8.             protected IResourceStream getResourceStream() {
  9.                 AbstractResourceStream stream = new AbstractResourceStream() {
  10.                     private InputStream stream;
  11.  
  12.                     @Override
  13.                     public InputStream getInputStream() throws ResourceStreamNotFoundException {
  14.                         AttachmentInputStream attIS = CouchDB.INSTANCE.getCouchDbConnector().getAttachment(doc.getId(),
  15.                                 key);
  16.                         stream = new BufferedInputStream(attIS);
  17.                         return stream;
  18.                     }
  19.  
  20.                     @Override
  21.                     public String getContentType() {
  22.                         return cType;
  23.                     }
  24.  
  25.                     @Override
  26.                     public void close() throws IOException {
  27.                         stream.close();
  28.                     }
  29.                 };
  30.                 return stream;
  31.             }
  32.         };
  33.  
  34.         res.setFileName(key);
  35.         res.setCacheDuration(Duration.NONE);
  36.         if (asAttachment) {
  37.             res.setContentDisposition(ContentDisposition.ATTACHMENT);
  38.         } else {
  39.             res.setContentDisposition(ContentDisposition.INLINE);
  40.         }
  41.  
  42.         return res;
  43.     }
Advertisement
Add Comment
Please, Sign In to add comment