Win a copy of Python Continuous Integration and Delivery this week in the Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

uncompressing .Z file in Unix  RSS feed

 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Robin Clark
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I decompressed the file by using this command:

gunzip csm.log.2006072106.Z

Then I recompressed it by using this command:

gzip csm.log.2006072106

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.

Any ideas?
 
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
author and iconoclast
Posts: 24203
43
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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()?
 
Robin Clark
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Robin Clark
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like you gave me the answer while I was writing my previous post! Thank you. I am experimenting with the Runtime exec method as we speak.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!