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

[2783 byte] By [kuroyume0161a] at [2007-10-1 22:05:42]
# 1

Well, ACK!

Simply changed InflaterInputStream() to GZIPInputStream() and removed Inflater. Decided to try this since, after perusing my C++ ZLIB class, I see that it uses the gzxx methods. It's been nearly two years since the C++ code was even looked at - that's how standardized and solid my wrapper class is. :)

So, if you need to inflate a zlib-compressed file, just perform these changes on the previous code.

Thanks,

Robert

kuroyume0161a at 2007-7-13 8:18:34 > top of Java-index,Administration Tools,Sun Connection...