tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dave <javao...@yahoo.com>
Subject image download
Date Sat, 27 Sep 2008 01:33:28 GMT
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