The following line is wrong:
     while ((len = bis.read(buf)) > 0) { //Same result using only 'is'

read == -1 marks the end of the stream. 0 shows only that the stream is
still waiting for the next chunk of data.

Please read the JavaDocs:

> Returns:
> the number of bytes read, or -1 if the end of the stream has been reached.


  while ((len = bis.read(buf)) >= 0) { //Same result using only 'is'
if (len >0)
       out.write(buf, 0, len);
else
        // prevent high CPU load
        LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(500));
 }

Reply via email to