1

I am attempting to transfer a gzipped file using IOUtils.copyLarge. When I transfer from a GZIPInputStream to a non-compressed output, it works fine, but when I transfer the original InputStream (attempting to leave it compressed) the end result is 0 bytes.

I have verified the input file is correct. Here is an example of what works

IOUtils.copyLarge(new GZIPInputStream(inputStream), out)

This of course results in an uncompressed file being written out. I would like to keep the file compressed as it is in the original input.

When I try val countBytes = IOUtils.copyLarge(inputStream, out) the result is 0, and the resulting file is empty. The desired result is simply copying the already compressed gzip file to a new destination maintaining compression.

Reading the documentation for the API, I should be using this correctly. Any ideas on what is preventing it from working?

foobarbaz
  • 508
  • 1
  • 10
  • 27
  • 1
    I suspect that it is hard for your to make a [mcve] but still your story does not add up. Am I right that you claim that if you replace `val countBytes = IOUtils.copyLarge(inputStream, out)` with `val countBytes = IOUtils.copyLarge(new GZIPInputStream(inputStream), out)` at the **same place** in your code, the former return `0` and the latter some non-`0`? It is hard to believe in such a behavior. The best theory I have is that you actually have already read the whole `inputStream` before coming to `copyLarge`. Could you log the results of `.available()` and `.read()` calls before the copy? – SergGr Feb 02 '19 at 00:57
  • This was helpful in diagnosing the issue, and your theory was close. I had previously been copying line by line so still had a InputStreamReader opened with that same InputStream. Once I removed that line everything worked as expected. – foobarbaz Feb 02 '19 at 12:23

0 Answers0