1

I get the following error

java.util.zip.ZipException: invalid distance too far back

I am downloading a compressed file from a FTP server using edtftp.jar. I am doing something like that:

 GZipInputStream unzipped = new GZIPInputStream(new ByteArrayInputStream(downloadFileAsStream(ftpFile).toByteArray())));

When running my program on a Mac everything works fine. Testing the jar or even build the project in eclipse on a Windows machine will result in the error listed above.

Both machines are running Java 7 update 37. The only hint on StackOverflow was a corrupted archive file, but since the mac can extract the file properly it should not be this reason. Even 7zip on windows does not show any error while extracting the file.

Any idea what I can do to solve the issue on windows? Or why it only happens on a windows machine?

NobodyNada
  • 7,529
  • 6
  • 44
  • 51
TribuneX
  • 41
  • 1
  • 6
  • 1
    How large is the archive? Any chances it's larger than 2GB or 4GB? Are both JVMs 64-bit? – 9000 Oct 08 '14 at 22:30
  • No, it is only a small compressed xml file (1.5KB) – TribuneX Oct 08 '14 at 22:34
  • It sounds like you might be attempting to GZIP decompress a file that isn't compressed. – Hot Licks Oct 08 '14 at 23:59
  • 1
    This sort of thing is often caused by end-of-line conversions, which occur only on Windows machines. A LF is converted to a CRLF, which screws up binary formats such as compressed formats. See if there is somewhere in the data flow where end-of-line conversions are being performed. – Mark Adler Oct 09 '14 at 04:01
  • Thanks for the explanation, could be the reason why the issue only appears on the windows machine. Is there a way I can check that in an efficient way? I can also make available a demo file of the compressed files I try to decompress? – TribuneX Oct 09 '14 at 06:43
  • I think I am getting closer to the problem. If I try to decompress the same file locally, everything is fine with the GZIPInputStream. After downloading the file with com.enterprisedt.net.ftp.FTPClient, I cannot decompress it on windows any more, neither with Java or with 7Zip. EDIT: I just tried the apache FTPClient and get the same error on Windows. – TribuneX Oct 09 '14 at 16:27
  • YEAH I got it fixed thanks to the help here: http://stackoverflow.com/questions/9501681/ftp-doesnt-download-the-file-properly-in-java. After setting the filetype like this: client.setFileType(FTPClient.BINARY_FILE_TYPE) everything works now on windows. – TribuneX Oct 09 '14 at 16:35
  • possible duplicate of [ZipException: invalid distance too far back error when running app](http://stackoverflow.com/questions/16594307/zipexception-invalid-distance-too-far-back-error-when-running-app) – Frodo Baggins Apr 16 '15 at 20:03
  • @SharkStack: Did you solve this issue? I am getting the same error and yet to test the code on the linux machine. – sampopes Jan 19 '17 at 12:08

0 Answers0