I noticed while working with GZIPInputStream that using an InputStream generated from Class.class.getResourceAsStream on a gzipped file causes a
java.util.zip.ZipException: invalid code lengths set
when used in GZIPInputStream, but using a FileInputStream on the same file seems to work fine. Does anyone know what is causing this?
For example:
InputStream is = new FileInputStream("src/main/resources/testFile.gz");
GZIPInputStream zis = new GZIPInputStream(is);
String outputStr = IOUtils.toString(zis, "utf-8");
Successfully generates an output string with the unzipped file data, while:
InputStream is = Class.class.getResourceAsStream("/testFile.gz");
GZIPInputStream zis = new GZIPInputStream(is);
String outputStr = IOUtils.toString(zis, "utf-8");
Generates the ZipException above.
I when I un-gzip the file I am able to get the correct outputString using IOUtils.toString on the InputStream generated either way so I know that the file is being accessed successfully and the issue appears to be with GZIPInputStream its self.