Problem when uncompressing using GZIPInputStream
807569Jul 14 2006 — edited Jul 15 2006i uploaded a 2.7MB gzipped byte array into MySQL database. The original file size before compressing was 9.3MB. When I retrieve the file from the database, everything works fine, but after uncompressing it using GZIP, it's only 9.2MB. I compared both the files, both look same in the beginning, but the last bytes are missing in the retrieved file. Here is my code.Can somebody give me some insight?
byte[] bytes=getFile();
ByteArrayInputStream bStream=new ByteArrayInputStream(bytes);
GZIPInputStream iStream=new GZIPInputStream(bStream);
File file = new File("/home/antn/file/testfile.cel");
OutputStream oStream=new FileOutputStream(file);
byte [] buf = new byte[512];
int len = 0;
while ( (len=iStream.read(buf))!= -1 )
{
oStream.write(buf,0,len);
}
iStream.close();
oStream.close();
bStream.close();
Also I am getting this exception whenever I run the program.
Exception in thread "main" java.io.EOFException: Unexpected end of ZLIB input stream
at java.util.zip.InflaterInputStream.fill(InflaterInputStream.java:216)
at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:134)
at java.util.zip.GZIPInputStream.read(GZIPInputStream.java:87)
at java.io.FilterInputStream.read(FilterInputStream.java:90)
at service.RetrieveFile.main(RetrieveFile.java:93)