2011/3/1 <[email protected]>:
> Author: markt
> Date: Tue Mar 1 09:00:01 2011
> New Revision: 1075719
>
> URL: http://svn.apache.org/viewvc?rev=1075719&view=rev
> Log:
> Better fix, we actually need to read 20 byres for the test to pass
>
> Modified:
> tomcat/trunk/test/org/apache/catalina/startup/TestTomcat.java
>
> + int read = 0;
> try {
> - is = conn.getInputStream();
> - reader = new InputStreamReader(is);
> - int len = reader.read(cbuf);
> - res.getWriter().write(cbuf, 0, len);
> + while (read < 20) {
> + is = conn.getInputStream();
> + reader = new InputStreamReader(is);
The above two lines should be moved outside the loop.
Besides creating a new Reader on each loop, there is no guarantee that
conn.getInputStream() always returns the same stream that we started
reading, and not a new one.
(It looks like JarURLConnection always returns a new stream)
The write() below can be moved below the loop, but keeping it inside
the loop looks more interesting.
> + int len = reader.read(cbuf, read, cbuf.length -
> read);
> + res.getWriter().write(cbuf, 0, len);
> + read = read + len;
> + }
> } finally {
> if (reader != null) {
> try { reader.close(); } catch(IOException ioe)
> {/*Ignore*/}
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]