Take a look at this Servlet what is used for downloading zip files. The code from there might help you in completing your script.
https://github.com/openkm/document-mana ... rvlet.java
https://github.com/openkm/document-mana ... rvlet.java