commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tom Maccariella <>
Subject Re: Upload Problem
Date Tue, 17 Jun 2003 12:38:01 GMT
I'm not sure if this code works either.  The OutputStream.write(byte[] b, int off, int len)
method returns null in JDK1.4, not int.  Am I missing something?

"Craig R. McClanahan" <> wrote:

On Tue, 10 Jun 2003, Ashok Madhavan wrote:

> Date: Tue, 10 Jun 2003 21:11:21 -0700 (PDT)
> From: Ashok Madhavan 
> Reply-To: Jakarta Commons Users List 
> To: Jakarta Commons Users List 
> Subject: Re: Upload Problem
> hi Rob,
> Thanks for the info. I am testing that now.
> I got a another question.
> I have a typical upload/download functionality. For
> the upload i use the commons-fileupload and for the
> download i use the ServletOutpurStream like this.
> ServletOutputStream stream =
> response.getOutputStream();
> int sent = 0;
> stream.write(data, sent, data.length - sent);
> stream.flush();
> stream.close();
> return null;

The download code snippet above seems bogus -- perhaps there were some
omitted lines? You cannot assume that stream.write() will write all of
the bytes of your data the frst time you call it, so you have to
encapsulate thngs in a while loop (assuming "data" is a byte array);

ServletOutputStream stream = response.getOutputStream();
int sent = 0;
while (sent < data.length) {
sent += stream.write(data, sent, data.length - sent);
return null;

If you do not do something like this, it's entirely possible that you will
receive only the beginning of the data, rather than all of it. The
precise behavior is totally subject to the JDK an servlet container you
are using, coupled with the dynamic situation when the request is made --
in short, what you'll actually see with your code is "undefined" behavior

> After a few times (some times just one ) uploading and
> downloading the browser seems to get slower and if i
> click any link on the site, the request does not go to
> the server at all. But if i click any link the second
> time, it goes to the server.

That could also be a result of not processing the entire byte array, and
somehow leaving a reference to it that occupies memory.

> Any idea why this weird error is happening?

What wierd error? All you've described is a performance issue :-). Such
a thing could easily result from dangling references to the byte array,
but that's most likely an application issue.

> I am using the weblogic 7.0 and working in Struts 1.1
> RC1.
> regards
> Ashok


To unsubscribe, e-mail:
For additional commands, e-mail:


Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message