tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dave <javao...@yahoo.com>
Subject Re: image download
Date Sat, 27 Sep 2008 01:38:19 GMT
InputStream is = new FileInputStream("/apphome/pictures/image.jpg");
OutputStream os = response.getOutputStream();
 
byte[] buffer = new byte[256*1024];  //256k
while (true) {
     int n = is.read(buffer);
     if (n < 0)
          break;
      os.write(buffer, 0, n);
}
 
is.close();
os.close();


--- On Fri, 9/26/08, Dave <javaone9@yahoo.com> wrote:

From: Dave <javaone9@yahoo.com>
Subject: image download
To: "Tomcat Users List" <users@tomcat.apache.org>
Date: Friday, September 26, 2008, 6:33 PM

For <img src="http://domain.com/servlet/pictures/image.jpg"/>
 
in servlet get method,
 
InputStream is = new FileInputStream("/apphome/pictures/image.jpg");
OutputStream os = response.getOutputStream();
 
byte[] buffer = new byte[256*1024];  //256k
while (true) {
     int n = is.read(buffer);
     if (n < 0)
          return;
      os.write(buffer, 0, n);
}
 
is.close();
os.close();
 
 
Is this the right way? Sometimes only the half image is shown on web page. Is 
there a more efficient and robust way?  How about for audio/video files?
 
I want to take at how Tomcat does it. Could anyone tell me which class?
thanks
Dave


      


      
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message