Downloads in Java program are sometimes corrupted -


i trying write java program backup http directory on remote server. remote server across several vpns/firewalls/whatever, connection not best.

so start downloading root directory listing , go through entries recursively. simple single-threaded program.

so problem is, html corrupted. has multiple null-bytes on whole document, can remove replaceall. other thing is, seems have text chunks 2 (or more?) times, instead of "this text, please read me." "this teis xt, please read me.". if cut out duplicate "is ", fine. there multiple of these duplicate texts on whole document.

when browse directory browser (namely firefox) have no problems, seems fine. downloader keeps getting corrupt data.

so here code snippet, gets html listing data:

        inputstream = con.getinputstream();         if ("gzip".equals(con.getcontentencoding())) {             = new gzipinputstream(is);         }         int x = 0;         byte[] data = new byte[1024];         while ((x = is.read(data, 0, 1024)) >= 0) {             if (x > 0) {                 retval += new string(data);             }         } 

any ideas, doing wrong?

greetings!

replace this:
retval += new string(data, 0, x);

if read less 1024 , 1024 read previously, x + (1024-x) data being left on previous loop


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -