You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Josh G <jo...@gfunk007.com> on 2004/02/10 03:08:23 UTC

Re: Image download? - FIX

At 09:58 AM 10/02/2004, you wrote:

Fix0r3d. For the archives, here's the fix:


                 //Set content-type
                 ServletContext context = getServletContext();
                 response.setContentType(context.getMimeType(media.getLocation()));

                 //Open file
                 try {
                         FileInputStream in = new 
FileInputStream(media.getLocation());

                         byte[] buffer = new byte[4096];
                         int rc;
                         ServletOutputStream out = response.getOutputStream();

                         //dump contents
                         for 
(rc=in.read(buffer,0,buffer.length);rc>0;rc=in.read(buffer,0,buffer.length))
                                 out.write(buffer,0,rc);

                         //Close file, and fuck off.

                         in.close();
                         return;

                 } catch (IOException e) {
                         Logger.debug(this,"IOException on media read/dump 
:(");
                         e.printStackTrace();
                         return;
                 }

God I loathe java's IO....


          "He likes to run, And then the thing with the.. person..
                ... Oh boy, that monkey is going to pay."

            [ Josh 'G' McDonald ]  --  [ Pirion Systems, Brisbane]

[ 07 3257 0490 ]  --  [ 0415 784 825 ]  --  [ http://www.gfunk007.com/ ] 


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