If you want to read a stream without dealing with low-level headaches, you
can use
https://commons.apache.org/proper/commons-io/javadocs/api-release/org/apache/commons/io/IOUtils.html

Gary

On Thu, Jun 4, 2020 at 6:53 AM Julia Ruzicka <julia.ruzi...@simutech.at>
wrote:

> Thanks for your reply!
>
> I changed the code and did the usual AndroidStudio restart/clean/build but
> most images are still downloaded incompletely.
> I don't know if my other answer (sent about an hour ago) came through (I
> did some more testing today), so here's an imgur album with test images and
> their results:
> https://imgur.com/a/Mzngp11
>
> The last image (the satellite one) was now also affected for the first
> time.
>
> -----Ursprüngliche Nachricht-----
> Von: Robert Paasche <r.paas...@pripares.com>
> Gesendet: Donnerstag, 4. Juni 2020 12:18
> An: Commons Users List <user@commons.apache.org>
> Betreff: Re: [net] FTPClient doesn't download full images
>
> 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));
>  }
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
> For additional commands, e-mail: user-h...@commons.apache.org
>
>

Reply via email to