The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
January 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

File download Servlet is SLOW!

Posted by Mark Tinderholt on January 08, 2001 at 6:04 PM

This is driving me nuts! This servlet will download properly BUT it does it sooo slowly! Over a 100mbps LAN it will download at about 11.1kbps (on the average) ... WHY!!?!! Is it my code? Is it a problem with my server or server settings? I am running Windows 2000 Advanced Server (NO IIS :P) with Jigsaw. PLEASE, please, please, please, help! Thanks in advance!

--Mark

///////////////////////////////////////////////////////////////

try {
int size = 0;
filename = request.getParameter("filename");
File target = new File(filename);

//BufferedOutputStream bout = new BufferedOutputStream(response.getOutputStream());
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment; filename=\"" + target.getName() + "\";");
response.setHeader("Cache-Control", "no-cache");
/*
int len = new Long(target.length()).intValue();
byte[] content = new byte[1024];

BufferedInputStream bin = new BufferedInputStream(new FileInputStream(target));
// BufferedInputStream bin = new BufferedInputStream(fin);
// BufferedOutputStream bout = new BufferedOutputStream(out);
while((size = bin.read(content, 0, content.length)) != -1) {
bout.write(content, 0, size);
}
bout.flush();
bout.close();
*/

ServletOutputStream stream = response.getOutputStream();

BufferedInputStream fif = new BufferedInputStream(new FileInputStream(target));
int data;
while((data = fif.read()) != -1) {
stream.write(data);
}
fif.close();
stream.close();

//out.close();
} catch (Exception e) {
}

///////////////////////////////////////////////////////////////




Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us