I have a requirement, where i need to process a set of files and create a compressed zip file out of it and then use it for download. I am using a Servlet for downloading that file, but the download takes quite sometime. So i want the user to know that the servlet is processing the request through a print writer output messsage instead of showing him a blank screen.But everytime i use a printwriter to write something to the screen, the message takes a lot of time to show on the screen and the file doesnt download. How can i achieve this? Any ides? Thanks.
Here's my code
OutputStream oStream = null;
DataInputStream dInput = null;
File file = new File(("PATH"));
int length = 0;
try{
DownloadServerLogs.processLogs();
oStream = res.getOutputStream();
res.setContentType("application/zip");
res.setContentLength((int)file.length());
res.setHeader("Content-Disposition",
"attachment;filename=\"" + file.getName() + "\"" );
byte[] bbuf = new byte[BYTES_DOWNLOAD];
dInput = new DataInputStream(new FileInputStream(file));
while ((dInput != null) && ((length = dInput.read(bbuf)) != -1))
{
oStream.write(bbuf,0,length);
}
dInput.close();
oStream.flush();
oStream.close();
}catch(Exception e){
Utility.getLogger().error(e.getMessage(), e);
}