commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ashok Madhavan <ashsud2...@yahoo.com>
Subject Re: Upload Problem
Date Tue, 17 Jun 2003 18:07:52 GMT
hi Craig,

The stream.write() method returns void. 
I had taken the original code snippet from one of your
other postings. 
I had the 
"while (sent < data.length) 
{
  sent += stream.write(data, sent, data.length -
sent);
}" code but it does not compile. 
Thatz the reason i didnt do the "while" check.

What is the proper way to make sure all the data
reaches teh browser.

Regards
Ashok


--- "Craig R. McClanahan" <craigmcc@apache.org> wrote:
> 
> 
> On Tue, 10 Jun 2003, Ashok Madhavan wrote:
> 
> > Date: Tue, 10 Jun 2003 21:11:21 -0700 (PDT)
> > From: Ashok Madhavan <ashsud2000@yahoo.com>
> > Reply-To: Jakarta Commons Users List
> <commons-user@jakarta.apache.org>
> > To: Jakarta Commons Users List
> <commons-user@jakarta.apache.org>
> > 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);
>   }
>   stream.flush();
>   stream.close();
>   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
> >
> 
> Craig
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> commons-user-help@jakarta.apache.org
> 


Mime
View raw message