> From: Christopher Schultz [mailto:ch...@christopherschultz.net]
> Subject: Re: Debian Tomcat Fail
> 
> >                     i = 0;
> >                     len = 0;
> >
> >                     while((i = is.read(raw)) != -1) {
> >
> >                     }
> 
> That's an interesting idiom. I had to read it several times to convince
> myself that it would actually work.

Depends on what you mean by "work"; it's not terribly useful, as written - each 
pass through the while loop will read the next chunk of data into offset 0 of 
the array, thereby losing anything that's come before.  If it works at all, it 
can only be due to something upstream buffering the data first, and then 
delivering it in one chunk.  What would be useful is this:

                        i = 0;
                        len = 0;
                        while((i = is.read(raw, len, raw.length - len)) != -1) {
                          len += i;
                          if (len == raw.length) throw new TooBigException();
                        }

> >               fos.write(raw);

This also isn't terribly effective, since it writes the whole 800000 bytes out, 
regardless of how many were actually read.  If the modified read sequence above 
is used, the write should be:

                        fos.write(raw, 0, len);

But back to the main point: as Chris implied, writing to the webapps directory 
is *never* a good idea; you must store the uploaded files outside of Tomcat's 
directory structure if you ever want this to be reliable.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY 
MATERIAL and is thus for use only by the intended recipient. If you received 
this in error, please contact the sender and delete the e-mail and its 
attachments from all computers.


Reply via email to