此文介绍apache的压缩包,好处是可以自己设置ZipFile文件名的编码.

而jdk自带的ZipFIle只支持utf-8,导致压缩后中文出现乱码.

 

*下面给出个zip压缩解压的示例

---zip压缩

Zip Compress

 

---zip解压

Zip Decompress

 

*tar包

---默认tar中entry的长度限制是TarConstants.NAMELEN = 100 [0x64]

原因有待研究?

这个长度应当=操作系统支持的最小长度.

---长文件名处理setLongFileMode(int longFileMode)

参数

/** Fail if a long file name is required in the archive. */
public static final int LONGFILE_ERROR = 0;

/** Long paths will be truncated in the archive. */
public static final int LONGFILE_TRUNCATE = 1;

/** GNU tar extensions are used to store long file names in the archive. */
public static final int LONGFILE_GNU = 2;

在putArchiveEntry()中根据上面的设置处理文件名.

使用长文件名的设置缺点是在其他非gnu操作系统上可能无法解压

"If you choose the GNU tar option, the archive can not be extracted using many other tar implementations like the ones of OpenBSD, Solaris or MacOS X"

---注意

"The tar package does not support the full POSIX tar standard nor more modern GNU extension of said standard. It cannot deal with entries larger than 2 GByte either. "

 

*Jar包

“Note that ArchiveStreamFactory doesn't distinguish ZIP archives from JAR archives, so if you use the one-argument createArchiveInputStream  method on a JAR archive, it will still return the more generic ZipArchiveInputStream.

The JarArchiveEntry class contains fields for certificates and attributes that are planned to be supported in the future but are not supported as of Compress 1.0.”

从源码可知JarArchive*Stream和JarArchiveEntry继承自对应的Zip,从说明可知,目前两者功能是一致的

 

详细参考:

http://commons.apache.org/compress/examples.html

posted on 2010-09-17 13:05  戴忠  阅读(11932)  评论(0)    收藏  举报