I have a problem with GZip in Java. Currently i work with files that are gzipped. One file in one gzip archive. And if i decompress them manually and then parse them everything works. But i want to automate this with Java and GZipInputStream but it doesn't work. I need to have DataInputStream at the end. My code is:
byte[] bytesArray = Files.readAllBytes(baseFile.toPath());
try {
reader = new DataInputStream(new GZIPInputStream(new ByteArrayInputStream(bytesArray)));
System.out.println("gzip");
} catch (ZipException notZip) {
reader = new DataInputStream(new ByteArrayInputStream(bytesArray));
System.out.println("no gzip");
}
I also tried new GZIPInputStream(new FileInputStream(baseFile)); The result is the same. Due to output i see that Gzip stream creates without exception but later i get invalid data from DataInputStream. Please help :)