Reading and Inflating a zlib compressed file?
There seems to be absolutely no information on how to use thenew ZLIB compression/decompression in 1.4.2 for ZLIB-compressed files (NOT ZIP archives!). I have tried from a more general example here on using InflaterInputStream(), but there is always an error about the data format or compression method and no decompression at all - just a 0-byte file.
I've had no problems whatsoever using the C++ version of the zlib library on Windows and MacOS on the same files - theyare zlib-compressed. How rudimentary is this supposed ZLIB support in Java? Why is there no information about how to use it in this scenario?
Code:
/**/
privateboolean Decompress()
/**/
{
System.out.println("Decompress "+poser_File.toString());
try{
// Initialize InputStream
String zfile ="temp.txt";
Inflater inf =new Inflater();
FileInputStream fis =new FileInputStream(poser_File);
InflaterInputStream zis =new InflaterInputStream(new BufferedInputStream(fis), inf);
// Initialize OutputStream
FileOutputStream fos =new FileOutputStream(zfile);
BufferedOutputStream dest =new BufferedOutputStream(fos, BUFFER);
// write the files to the disk
int count;
byte data[] =newbyte[BUFFER];
while ((count = zis.read(data, 0, BUFFER)) != -1)
{
dest.write(data, 0, count);
}
dest.flush();
dest.close();
zis.close();
poser_File =new File(zfile);//new File(poser_File.getParent() + File.pathSeparator + zfile);
tmpCompressed =true;
}catch(Exception e){
e.printStackTrace();
}
returntrue;
}
Thanks,
Robert

