TrueZip : Java Glossary

The JDisplay Java Applet displays the large program listings on this web page. JDisplay requires an up-to-date browser and Java version 1.5+, preferably 1.7.0_02. If you can’t see the listings, or if you just want to learn more about JDisplay, click  here for help.
TrueZip
The current version is 7.4.3 Last revised/verified: 2011-12-15. It is a Java library that lets you treat a zip file as if it were a directory. You can shuffle files around and when you are done, call umount() which creates a new zip reflecting all your changes.
TrueZip gives you complete flexibility in just how much qualification you include with each member. You can have none, full qualification, anything in between, or even include the original drive letter (which maps into a subdirectory called E: for example). It is up to you as a programmer to construct the file name of the zip entry, then pour your file/files into it. The name does not even have to bear any resemblance to the name of the file you are adding. You can’t just copy files into the root of the archive. You must first create a zip entry file with a name to contain each one. It behaves much more like a directory tree than a traditional archive.

TrueZip compresses as you add, but does not construct the final archive file until you call umount. Using the default settings, TrueZip archives take up about an extra 28% more space that WinZip using its proprietary compression algorithms. It possible to squeeze more compression out of TrueZip if you are willing to take more time.

See the timestamp gotchas about PkZip format. They plague TrueZip too. TrueZip can use other formats that may avoid these problems.

Java 7 will have built-in True-zip like features. Mark Hall is working on giving TrueZip an API (Application Programming Interface) that will be compatible. That means you can write code for Java 7 that will work on earlier JDKs.

TrueZip 7

TrueZip 7 is a rewrite of TrueZip 6 with a slightly different API.

There are many other little changes, but they pretty easy to discover letting the compiler point out syntax errors and scanning the Javadoc.

TrueZip 6 works onJava version 1.4 or later. TrueZip 7 works onJava version 1.6 or later.

Support

TrueZip supports to following flavours of archive:

Archive Formats that TrueZip supports
Type Canonical Suffixes Description Advantages Disadvantages
ZIP zip

ZIP file: Archive file with central directory and compressible entries

Widely supported. People can easily access the archive without TrueZip. Uses standard Java java.util.zip.Deflater to do the actual compression, which is also a disadvantage because it is not a particularly quick or strong. You can trade off time for additional compression. Incompetent date-time stamp format. They don't understand time zones or daylight saving. They are only accurate to two seconds.
JAR ear ❘ jar ❘ war Java Archive: ZIP with custom directory tree layout Fully multiplatform because of Java support. Uses rather lame compression techniques. Same advantages and disadvantages as zip. Jar is just a flavour of zip.
ODF odb ❘ odf ❘ odg ❘ odm ❘ odp ❘ ods ❘ odt ❘ otg ❘ oth ❘ otp ❘ ots ❘ ott OpenDocument Format, like XML (extensible Markup Language) compressed with PkZip. Works with OpenOffice Not a general format
TZP tzp ❘ zip.rae ❘ zip.raes RAES encrypted ZIP file AES (Advanced Encryption Standard) is serious encryption. Needs aux BouncyCastle bcprov.jar. Does not use JCE (Java Cryptography Extension) because JCE lacks the needed random access.
SFX/EXE exe ZIP file with a code preamble for self extraction If you send the archive to someone, they need no additional software at all to open it. This driver is pretty slow. Windows only. Read-only.
TAR (Tape Archive) tar TAR : Uncompressed tape archive file. Universally supported under Unix. Needs aux ant.jar.
TAR.BZ tbz ❘ tb2 ❘ tar.bz2 TAR file wrapped in BZIP2 compression format More aggressive compression than ZIP. Needs aux ant.jar.
TAR.GZ tar.gz ❘ tgz TAR file wrapped in GZIP compression format. Traditional Unix archive Not particularly aggressive compression. Needs aux ant.jar.

Sample Code for TrueZip 6

Here is a simple program to add a file to a zip and display a directory of its contents.

Sample Code for TrueZip 7

Here is a simple program to add a file to a zip and display a directory of its contents.

BackupToZip Substantial Truezip Application

Here is the source code for a more complex TrueZip program that maintains a mirror of a set of files in an archive view

Encoding Gotcha

ZIP files use IBM437, an eight bit character set to encode the filenames. Anything which is not representable in this charset gets rejected. You can change this in the File API and the ZIP API. For the File API, just do this:

Another way to do it is to create an empty zip file using ZipOutputStream with a specified encoding.

However, this will stop interoperability of the created ZIP files with older tools because support for UTF-8 has been added only fairly recently! So anybody else will probably not be able to extract these ZIP files. WinZip, however, can handle them.

If you need a better option, use the JAR file format — it supports UTF-8. The TAR file format is not an option either because it supports only US-ASCII.

ANT/Genjar

It is fairly tricky to bundle just the parts of the TrueZip jar that you need inside your own jar. Here is how
The truezip works jar contains some ant code in it. If you put that code in the ext directory, ant will stop working. Remove it from the jar first.

CMP homejump to top You can get the freshest copy of this page from: or possibly from your local J: drive (Java virtual drive/mindprod.com website mirror)
http://mindprod.com/jgloss/truezip.html J:\mindprod\jgloss\truezip.html
logofeedback Please email your feedback for publication, letters to the editor, errors, omissions, typos, formatting errors, ambiguities, unclear wording, broken/redirected link reports, suggestions to improve this page or comments to Roedy Green : feedback email If you want your message kept confidential, not considered for posting, please explicitly specify that.
mindprod.com IP:[65.110.21.43]
view BlogYour face IP:[38.107.179.211]
You are visitor number 11.