I am trying to write a servlet to download files as a zip, which will read multiple nodes in a repository (CRX) to get Inputstream of multiple images.
I am using ZipOutputStream to download the zip file. But as the length after zipping is not known, I can't set the content-length header in response, hence the browser is not able to show the remaining time to download.
Current code:
String[] paths = request.getRequestParameters("path");
ZipOutputStream out = new ZipOutputStream(response.getOutputStream());
for (int i=0; i<paths.length;i++){
InputStream is = getStream(paths[i]);
IOUtils.copy(is, out);
IOUtils.closeQuietly(is);
out.closeEntry();
}
Is there a way to generate the ZipFile and then write to the output stream?