W3C home > Mailing lists > Public > www-jigsaw@w3.org > January to February 2001

download servlet is slow!

From: Mark Tinderholt <mtinderholt@bankone.com>
Date: Thu, 4 Jan 2001 15:51:14 -0500 (EST)
To: <www-jigsaw@w3.org>
Message-ID: <LAEKJIMPOBLNMJDEHLOOCECBCAAA.mtinderholt@bankone.com>
argh! i can only get a crappy 10kbps over 100mbps LAN!!! argh... please look
at me could and help me out! thanks!


 import javax.servlet.*;
 import javax.servlet.http.*;
 import java.io.*;
 import java.util.*;
 import java.lang.*;

public class Download extends HttpServlet {
   String filename = "";

   public void init(ServletConfig config) throws ServletException {
      super.init(config);
   }

   public void doGet(HttpServletRequest request,
                     HttpServletResponse response)
      throws ServletException, IOException {

      doPost(request,response);

   }

   public void doPost(HttpServletRequest request,
                      HttpServletResponse response)
      throws ServletException, IOException {
	  //PrintWriter tout = response.getWriter();
	  //response.setContentType("text/html");
	  try {
      int size = 0;
      filename = request.getParameter("filename");
      File target = new File(filename);

      OutputStream out = response.getOutputStream();
      response.setContentType("application/octet-stream");
      response.setHeader("Content-Disposition", "attachment; filename=" +
filename + ";");
      response.setHeader("Cache-Control", "no-cache");
      // byte[] for piece by piece.
      byte[] buffer = new byte[4 * 1024];
        // byte[] for all
	  byte[] content;
	  int len=0;
//      FileInputStream in = new FileInputStream(target);
//      while(in.read() != -1) {
//	     len++;
//	  }
//	  in.close();
      len = new Long(target.length()).intValue();
	  content = new byte[len];
//    FileInputStream fin = new FileInputStream(target);
 BufferedInputStream bin = new BufferedInputStream(fin, 4*1024);
// flat out transfer all bytes.
// bin.read(content, 0, len);
// out.write(content, 0, len);
      // piece by piece
      while ((size = bin.read(buffer, 0, buffer.length)) != -1) {
         out.write(buffer, 0, size);
      }

      bin.close();
	  fin.close();
      out.close();

	  //tout = response.getWriter();
	  } catch (Exception e) {
	     //response.setContentType("text/html");
	     //e.printStackTrace(tout);
	  }

   }
}
Received on Thursday, 4 January 2001 19:13:34 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 9 April 2012 12:13:35 GMT