我正在使用一个使用plexus-archiver的maven插件来创建一个zip文件。 基本上,我通过Sisu获取组件注入,然后我遍历指定的文件集并注册所需的文件:
zipArchiver.addFile(from_file, to_file);
正确生成拉链。
但我需要在一些正在添加到zip中的文件中为文件mime-type包含一个额外字段。
我怎么能用plexus-archiver做到这一点?
答案 0 :(得分:0)
目前的plexus-archiver(3.0)似乎不支持额外的字段。 为了继续使用plexus-archive,我必须进行一些修改。
解决方案是扩展ZipArchiver类并覆盖方法 initZipOutputStream ,该方法提供ZipArchiveOutputStream类的对象。
有了它,我可以创建条目及其额外字段:
@Override
protected void initZipOutputStream(ZipArchiveOutputStream pZOut)
throws ArchiverException, IOException {
super.initZipOutputStream(pZOut);
ZipArchiveEntry ae = new ZipArchiveEntry(pFile,
pFile.getName());
ZipExtraField zef = new ContentTypeExtraField(
Constants.MIME_STRING);
ae.addExtraField(zef);
pZOut.putArchiveEntry(ae);
pZOut.write(content);
pZOut.closeArchiveEntry();
}