I have written a program to uncompress a ".Z" file on Solaris. When I run it I get the following error:
java.io.IOException: Not in GZIP format at java.util.zip.GZIPInputStream.readHeader(GZIPInputStream.java:129) at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:57) at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:67) at Log.main(Log.java:12)
Here is the program:
What java class do I need to use in order to read a .Z file in a java program?
This created a file called csm.log.2006072106.gz which I was able to read using the code in the previous post. However, I need to find a way to process the file when it is named csm.log.2006072106.Z programatically.
The problem is that the file is compressed using a Platform dependent compression algorithm. This compress and uncompress commands will work with this file, but I don't believe that their is a Java API for this. It is fairly wide spread in the Unix community, but have never heard of it being used on either linux or windows.
Indeed, it's not used much these days. The program that writes capital-Z compressed files is called "compress". It uses a patented form of adaptive Lempel-Ziv coding; the patent is now expired. Because it was a patented algorithm, open-source implementations were rare for a time. If you searched long and hard, I'm sure you'd find a Java implementation.
Can you just run "uncompress" or gunzip using Runtime.exec()?
Is there a way to invoke the gunzip command in a Java class? What I need to do is to read a file that has a ".Z" suffix in memory, looking for a specific string. When I find the string in the compressed file, I want to write out the 1000 lines that occurred prior to seeing the string in the file and write out the 1000 lines that follow the string. I want to write to a plain text file.
I know that I can do this in perl by invoking the gunzip command to create a temporary uncompressed file. Then I can read thru it looking for the string. And I can delete the temp file when I am finished.
But I'd rather do this in Java so that I can practice my Java skills.