No never used with images.

 //length was "*2" but why?
That is for an buggy ftp-server, which mishandled multibyte encodings. On
UTF-16 Files he has reported the number of chars instead of bytes, so the
file size was just the half erverytime.

fos.write(data);
this should be something like:
  fos.write(buffer.toByteArray());


Am Do., 4. Juni 2020 um 15:29 Uhr schrieb Julia Ruzicka <
julia.ruzi...@simutech.at>:

> @Robert Paasche
>
> The code is used in an AsyncTask and there's more error handling to it
> (including proper error messages,...), I just simplified it. ;)
>
> Have you ever tested it with images too? Text files always seem to
> download properly (no matter what size), it's just the images that are
> messed up.
>
> Thanks for the code snippet, I just ran my app with it multiple times and
> the files are all the right size, even the images, but no program is able
> to actually open them, so not sure what's going on with that now:
>
> if(singleFile.length > 0) { //check if file exists
>     String localPath = localFolder + File.separator + filename;
>     FTPFile single = singleFile[0];
>     InputStream inStream = ftpClient.retrieveFileStream(filename);
>     ByteArrayOutputStream buffer = new ByteArrayOutputStream();
>
>     int nRead;
>     byte[] data = new byte[(int) (single.getSize())]; //length was "*2"
> but why?
>
>     while ((nRead = inStream.read(data, 0, data.length)) != -1) {
>         buffer.write(data, 0, nRead);
>     }
>
>     buffer.flush();
>     inStream.close();
>
>     FileOutputStream fos = new FileOutputStream(localPath);
>     fos.write(data);
>     fos.flush();
>     fos.close();
>
>     if(ftpClient.completePendingCommand()) {
>         Log.d(TAG,"DONE");
>     } else {
>         Log.d(TAG,"NOT DONE");
>     }
> }
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
> For additional commands, e-mail: user-h...@commons.apache.org
>
>

Reply via email to