Reputation: 739
String inFileName = testDoc.gz;
File inFile = new File(inFileName);
System.out.println(inFileName);
FileInputStream fileStream = new FileInputStream(inFile);
GZIPInputStream gzipInputStream = new GZIPInputStream(fileStream);
When executing the above code in the the last line returns the error:
java.io.IOException: Not in GZIP format
I have tried it with multiple documents and cannot see the problem.
EDIT: The documents were not created by me, they are downloaded. They are in the .gz format and by multiple documents I mean different .gz files.
Upvotes: 2
Views: 590
Reputation: 5159
GZIPInputStream works with GZIP files, decompressing the input. GZIPOutputStream compressed whatever you write to it. So if you want to compress data, then you must write to a GZIPOutputStream.
To compress a file, read with with a FileInputStream and wrap a FileOutputStream with a GZIPOutputStream; read from the input file into a buffer, write the buffer to the GZIPOutputStream, until you're done and then close the GZIPOutputStream.
To decompress the data you can read it with a GZIPInputStream. I just checked it and it works; compressed a file with gzip on the command-line and read it with a GZIPInputStream (wrapped around a FileInputStream).
Upvotes: 0