commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Frank W. Zammetti" <fzli...@omnytex.com>
Subject Re: [fileupload] Re: Using parseRequest(request) more than once
Date Sun, 03 Apr 2005 01:04:28 GMT
While I agree with Martin that it seems odd that you *have* to read from 
the stream twice, you know the requirements of your use case better than 
we do certainly... so be it :)

Here's a suggestion, and mind you this is after about 10 seconds of 
thought, it may be completely wacky...

How about creating your own version of InputStream that accepts an 
InputStream in the constructor and copies the entire stream to a byte 
array?  Then you just override the required methods so you can use that 
as you would a regular InputStream, but you would have the ability to 
read from it as many times as you want (maybe add a restart() method?).

Then, just modify FileUpload to use that class instead of a regular 
InputStream.  In fact, I *think* the only required change (Martin can 
check me on this) is in FileUploadBase.java, line 334 in the current source:

InputStream input = req.getInputStream();

to:

InputStream input = new MyInputStream(req.getInputStream());

Would that do the trick for you?  Am I missing something incredibly 
obviously stupid with the idea?

Frank

Martin Cooper wrote:
> On Apr 2, 2005 4:17 PM, Navid Mehregani <navid89@yahoo.com> wrote:
> 
>>It's not as easy as that.  I'm modifying an existing
>>code and your suggestion wouldn't be feasible in my
>>case.
> 
> 
> Well it's not possible to read the servlet input stream more than
> once, because after it's been read, it's gone. So there's no viable
> alternative, I'm afraid.
> 
> --
> Martin Cooper
> 
> 
> 
>>Navid
>>
>>
>>--- Martin Cooper <mfncooper@gmail.com> wrote:
>>
>>>First of all, please follow the conventions of the
>>>mailing list and
>>>prepend the name of the relevant component to the
>>>subject line, in
>>>square brackets. That way, people know at a glance
>>>which component
>>>your question is about.
>>>
>>>On Apr 2, 2005 12:00 PM, Navid Mehregani
>>><navid89@yahoo.com> wrote:
>>>
>>>>I have a HttpServletRequest object that's
>>>
>>>multipart
>>>
>>>>content (i.e
>>>
>>>FileUpload.isMultipartContent(request) ==
>>>
>>>>true).
>>>>
>>>>I have to read the parameters of this request
>>>
>>>object
>>>
>>>>in several different functions.
>>>
>>>Why? I mean, why do you need to *read* them in
>>>several different
>>>functions? Why can't you read them once and then
>>>pass them around?
>>>
>>>That's actually what you're going to have to do.
>>>Once you've called
>>>parseRequest(), the request input stream has been
>>>consumed, and cannot
>>>be read again. This is not something that FileUpload
>>>can do anything
>>>about - it's just how streams work.
>>>
>>>--
>>>Martin Cooper
>>>
>>>
>>>>When I do the following in the first function:
>>>>DiskFileUpload upload = new DiskFileUpload();
>>>>List items = upload.parseRequest(request);
>>>>
>>>>it works fine, but in subsequent functions, the
>>>>parameters from the request object are missing.
>>>
>>>The
>>>
>>>>following returns zero:
>>>>DiskFileUpload upload = new DiskFileUpload();
>>>>List items = upload.parseRequest(request);
>>>>items.size() <-- This is zero.
>>>>
>>>>It seems as if the upload.parseRequest(request)
>>>>changes the request object.  What is the general
>>>>work-around if someone wants to read the parameter
>>>
>>>of
>>>
>>>>a multipart request object more than once?
>>>>
>>>>Any help would be greatly appreciated.
>>>>
>>>>Thanks,
>>>> Navid Mehregani
>>>>
>>>>
>>>
>>______________________________________________________________________
>>
>>>>Post your free ad now! http://personals.yahoo.ca
>>>>
>>>>
>>>
>>---------------------------------------------------------------------
>>
>>>>To unsubscribe, e-mail:
>>>
>>>commons-user-unsubscribe@jakarta.apache.org
>>>
>>>>For additional commands, e-mail:
>>>
>>>commons-user-help@jakarta.apache.org
>>>
>>>>
>>>
>>---------------------------------------------------------------------
>>
>>>To unsubscribe, e-mail:
>>>commons-user-unsubscribe@jakarta.apache.org
>>>For additional commands, e-mail:
>>>commons-user-help@jakarta.apache.org
>>>
>>>
>>
>>______________________________________________________________________
>>Post your free ad now! http://personals.yahoo.ca
>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
> 
> 
> 
> 

-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com


---------------------------------------------------------------------
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