tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jake Alley" <jake_al...@hotmail.com>
Subject Differences betwen Tomcat 5 and 4 writing to output stream?
Date Wed, 28 Jan 2004 20:12:38 GMT
Hi,
  I just upgraded to TC 5 from TC 4 running on RH linux 9.  I had a servlet 
that acted as a downloader for file requests to a restriced directory.  It 
worked very well in 4, but now it doesn't work in 5.  In 5 it adds a small 
number of bytes in the output stream.  It doesn't have to do with adding a 
CR every time it sees an LF or anything like that.  It adds about 10 bytes 
at the beginning and then nothing else.  Weird.

Here's my code.  I did have some other problems with using the wrong 
servlet-api version to compile, but those are fixed I think.  Thanks.

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

	int i = request.getRequestURI().lastIndexOf("/");
	String fileName = request.getRequestURI().substring(i+1);
	Downloader dl = new Downloader();
	if (dl.checkContactInfo(request, fileName) == false)
	{
		response.sendRedirect("/sysforms/dlcontact.jsp?filename=" + fileName);
		return;
	}

	response.setContentType("application/octet-stream");

                response.setHeader("Content-Disposition","filename=" + 
fileName);

	String path = manager.getBaseDir() + "/"  + request.getRequestURI();
	File file = new File(path);

	response.setContentLength((int) file.length());

    PrintWriter out = new PrintWriter (response.getOutputStream());

      int b;
      BufferedInputStream in = new BufferedInputStream (
        new FileInputStream(file));
      while ((b = in.read()) != -1)
      {
        out.write(b);
      }
      in.close();
      out.close();

  }

_________________________________________________________________
High-speed usersóbe more efficient online with the new MSN Premium Internet 
Software. http://join.msn.com/?pgmarket=en-us&page=byoa/prem&ST=1


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message