Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2005

Tip: Looking for answers? Try searching our database.

java.util.zip on hpux

Thread view: 
ctippur@gmail.com - 01 Dec 2005 20:54 GMT
All,

I have used java.util.zip package to compress a folder recursively
(which contains sub folders) using the package java.util.zip. It
created a zip file after that. I am unable to unzip OR gunzip this file
on HPUX.
There are couple of problems on HPUX:
1. there is no unzip tool that comes with the OS distribution
2. gunzip tool that resides in /usr/contrib/bin folder is not
appropriate. When I rename the file to .gz file and run gunzip on it,
it comes with "file exists" error.
I want to achieve the following things:
a) I want to compress a folder recursively.
b) I want to be able to access the files within the compressed file via
java
c) the compressed file must be "uncompressable" via tools available
with OS. THe most convenient tool is compress as it is available
everywhere with regular OS distribution.

I have read on java docs that in order to achieve compress via gzip, we
can do that only to a file. We have to essentially tar the folder and
then gzip the tar ball. If we do it this way, can we access the files
within the tar ball via java?

On Solaris however, I was able to unzip it.
Solaris8 $ unzip XXXX.zip
Archive:  XXXX.zip
 inflating: bin/hpux-risc
 inflating: bin/root.sh
 inflating: bin/createpackage
 inflating: bin/env
 inflating: bin/postinstallcheck
 inflating: bin/agentconnection.sh
Solaris8 $ ls -ltr
total 1168
-rw-r--r--   1 itv1     itv1      585115 Dec  1 16:23 XXXX.zip
drwxr-xr-x   2 itv1     itv1         618 Dec  1 16:23 bin

I appreciate any inputs on this issue.
Thanks
- Shekar
Roedy Green - 01 Dec 2005 21:32 GMT
>I have used java.util.zip package to compress a folder recursively
>(which contains sub folders) using the package java.util.zip. It
>created a zip file after that. I am unable to unzip OR gunzip this file
>on HPUX.

See what you can do with Jar.exe.

See http://mindprod.com/jgloss/zip.html
for how to write some code to unpack a zip.

Here is a sample of the sort of thing you need:

 /**
    * Unpack one zip file, and put all its contents into the target
directory.
    * It may contain some deadwood, but so long as we process zips in
the
    * proper order the deadwood will be over written.
    *
    * @param zd
    *        Which zip file to unpack.
    * @throws IOException
    */
   public static void unpackOneZip ( MiniZD zd ) throws IOException
       {

       // can't use ZipInputStream, since getSize would fail
       File zf = new File( zd.getZipFilename( ZD.ON_TARGET ) );
       ZipFile zip = new ZipFile( zf );
       // for each element in the zip
       // can't use for:each, only works with Iterator not
Enumeration.
       for ( Enumeration e = zip.entries(); e.hasMoreElements(); )
           {
           ZipEntry entry = (ZipEntry)e.nextElement();
           String elementName = entry.getName();
           Replicator.doing( "unpacking: " + elementName );
           // inside zip, uses / names.
           File elementFile = new File(
ConfigForReceiver.RECEIVER_BASE_DIR,
               elementName.replace( '/', File.separatorChar ) );
           IO.ensureDirectoryExists( elementFile.getParent() );
           // test for deleted marker, possibly null
           if ( "deleted".equals( entry.getComment() ) )
               {
               elementFile.delete();
               StatsForReceiver.deletedFilesCount++ ;
               }
           else
               {
               ft.copy( zip.getInputStream( entry ), elementFile );
               elementFile.setLastModified( entry.getTime() );
               StatsForReceiver.receivedFilesCount++ ;
               }
           } // end for each element in the zip

       zip.close();
       } // end unpackOneZip

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

ctippur@gmail.com - 02 Dec 2005 04:58 GMT
Thanks for the reply.
This certainly works with jar utility.
Is jar available on hpux and AIX with standard distribution?

- Shekar
Thomas Kellerer - 02 Dec 2005 08:02 GMT
> All,
>
[quoted text clipped - 7 lines]
> appropriate. When I rename the file to .gz file and run gunzip on it,
> it comes with "file exists" error.

I assume you used java.util.ZipOutputStream. Did you try to use
java.util.zip.GZIPOutputStream and then try gunzip on the created archive?

Thomas
ctippur@gmail.com - 02 Dec 2005 10:45 GMT
The problem with  java.util.zip.GZIPOutputStream is that we can only
use this for a single file. I can certainly tar the folder and try to
use this to compress the tar bundle but I am not sure how I can access
the files within the gzip bindle via java.

- Shekar
ctippur@gmail.com - 02 Dec 2005 10:50 GMT
Is there a java utility available which uses the compress algorithm?
compress is a tool available on all the platforms (as far as I can
tell).

- Shekar
Chris Uppal - 02 Dec 2005 11:36 GMT
> Is there a java utility available which uses the compress algorithm?
> compress is a tool available on all the platforms (as far as I can
> tell).

No.

The best bet for cross-platform compression/decompression (especially if you
want to compress more than one file into an archive) is ZIP format (which is
almost the same as JAR format).

A bit of background.  There are many compression /algorithms/ and there are
many compression /programs/, but the two are not the same.  Any given
compression program will use one or more specific algorithms to compress the
data, and then will write the data out into a specific file /format/.  So to
read the file you have to use a program (not necessarily the same program) that
understands that format.

As far as I know, the only compression /algorithm/ that is in widespread use
(i.e. you can expect to find tools that use it on almost any default
installation of almost any OS) is the so-called gzip algorithm.   That
algorithm is used in at least two compression /formats/, the format used by the
UNIX-based tool gzip, and the format used by the DOS/Windows/etc-based tool(s)
PKZIP (and other members of that family).  Despite the similarity of their
names, those two tools use completely different file formats -- not least
because ZIP is a multiple-file archive format, whereas gzip is (in normal use)
a single-file format.

There are many, many, programs on Windows that understand the ZIP format.
Windows itself does in recent versions.  You cannot assume that a Windows
installation will have any tools that understand the gzip format (or the
combination of gzip and tar which is often used).  Many Windows installations
/do/ have such tools, but none come as standard, and no single third-party tool
is so dominant that you can assume that users will have installed it, or are
willing to do so.

All UNIX-style boxed understand the gzip format, and they all understand the
tar format too.  There is a freely-distributable tool for handling ZIP files
called "zip" (http://www.info-zip.org/), that tool is installed on many
UNIX-like systems by default, but I don't know whether its included in /all/ of
them (I can't think of any reason why it should not be included).

Java has a (somewhat weak) implementation of ZIP file handling and it
understands the gzip format too, but it does not have standard libraries for
handling "tar" files, so it does not (by default) understand the common UNIX
"tarball" (tar + gzip) format.

(The "compress" program, and the corresponding format, is essentially defunct.
You will find it hard to find any tools for non-UNIX OSes that understand it,
and you certainly cannot assume that any particular Windows installation will
have one installed.)

So, you are limited to ZIP and gzip compression if you want to do it in Java.
Neither ZIP nor gzip is so universal that any given installation of any given
OS is /certain/ to have tools for handling it.  Of the two ZIP comes closest,
and I would say that it's a rare Windows or UNIX-style installation that
doesn't understand ZIP.

   -- chris
ctippur@gmail.com - 02 Dec 2005 11:45 GMT
Chris,

Thanks for the excellent explanation. We have 3 hpux boxes that do not
have zip utility but they do have man pages for the same. I am not sure
what to make out of that but again, thanks for putting everything in
perspective.

- Shekar
Roedy Green - 02 Dec 2005 19:05 GMT
>Is there a java utility available which uses the compress algorithm?
>compress is a tool available on all the platforms (as far as I can
>tell).
have a look into pack2000

http://java.sun.com/j2se/1.5.0/docs/tooldocs/share/pack200.html
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.