Have PDF's in [jcr:data]. 
Am  trying to zip the pdf files on a node and the response using spring blossom 
controllers.

Following is the code for doing this
@RequestMapping(path = "/zip", params = {"do=zip" }, method = 
RequestMethod.POST, produces = "application/zip")
public void download(HttpServletRequest request, HttpServletResponse response, 
Node content){
    response.getWriter().write(zipFiles())
}

public static byte[] zipFiles(String... uuids){

                // creating byteArray stream, make it buffurable and passing 
this buffur to ZipOutputStream
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                BufferedOutputStream bos = new BufferedOutputStream(baos);
                ZipArchiveOutputStream zaos = new ZipArchiveOutputStream(bos);

                try {
                        for (String uuid : uuids) {
                                Node fileNode = 
NodeUtil.getNodeByIdentifier(ApplicationFunctions.LITERATURE_WORKSPACE, uuid);
                                Binary binary = 
fileNode.getProperty("jcr:data").getBinary();
                                InputStream is = binary.getStream();

                                ZipArchiveEntry entry = new 
ZipArchiveEntry(fileNode.getProperty("fileName").getString());
                                
entry.setSize(fileNode.getProperty("size").getLong());
                                zaos.putArchiveEntry(entry);
                                zaos.write(IOUtils.toByteArray(is));
                                zaos.closeArchiveEntry();
                        }

                } catch (Exception e) {
                        EtechLogger.error(FileUtil.class, "Exception in 
zipFiles: " + e.getMessage());
                } finally {
                        if (zaos != null) {
                                zaos.finish();
                                zaos.flush();
                                IOUtils.closeQuietly(zaos);
                        }
                        IOUtils.closeQuietly(bos);
                        IOUtils.closeQuietly(baos);
                }
                return baos.toByteArray();
        }

-- 
Context is everything: 
http://forum.magnolia-cms.com/forum/thread.html?threadId=14c92789-1e21-4784-8257-0b068cd04fc3


----------------------------------------------------------------
For list details, see http://www.magnolia-cms.com/community/mailing-lists.html
Alternatively, use our forums: http://forum.magnolia-cms.com/
To unsubscribe, E-mail to: <user-list-unsubscr...@magnolia-cms.com>
----------------------------------------------------------------

Reply via email to