https://bz.apache.org/bugzilla/show_bug.cgi?id=61282

--- Comment #3 from Violeta Georgieva <violet...@apache.org> ---
Hi,

(In reply to Jack from comment #2)
> (In reply to Violeta Georgieva from comment #1)
> > What is the problem that you think there is?
> I am sorry, let me state it one more time, I hope I can make it clear this
> time.
> 
> servlet specification support nio, so when a user upload a file to server,
> at the server side, a servlet does not have to use the
> inputstream=request.getInputStream() to read the data. Instead, we set a
> readListener to the inputstream, when data is available, we got notified
> onDataAvailable(). This is good.
> 
> The problem is that inside onDataAvailable, we read data
> byte[] ab=new byte[4096];
> int len=is.read(ab,0,ab.length);
>

How many times the onDataAvailable is invoked in your scenario?

> 
> we have to use ab inside onDataAvailable method, once this method returns,
> the content of ab will be changed for no reason! This is very weird, and
> should not happen unless the specification indicates the data is only valid
> inside onDataAvailable method. 

The container does not have reference to the array that is provided with the
read method. However as this is a non blocking read you may expect the
following to happen:

- onDataAvailable is invoked by the container as there is data available for
reading
- The code enters in while block, isReady returns true and the code reads the
available data
- on the next iteration isReady returns false and the code exits
onDataAvailable method
- when there is again data available for reading the container will invoke
again onDataAvailable
- on this invocation the code will use the same byte array for reading, so the
data in the byte array will be replaced with the new data

At some point the container will invoke onAllDataRead method in order to
indicate that there is no more data for reading. At that point the byte array
"ab" will contain the data from the last reading.

> 
> so what I do to get around it is to copy the data.
> byte[] ab2=new byte[len];
> System.arraycopy(ab,0,ab2,0,len);
> 
> then the content of ab2 is reliable, even after long time, the content of
> ab2 is not changed.
> 
> 
> Did I succeed in explaining this? Let me know if you have any doubt.

Regards,
Violeta

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to