- 使用 Spring Initializr 创建 Spring Boot 应用程序
- 在Spring Boot中配置Cassandra
- 在 Spring Boot 上配置 Tomcat 连接池
- 将Camel消息路由到嵌入WildFly的Artemis上
本文整理了Java中org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream
类的一些代码示例,展示了ZipArchiveOutputStream
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZipArchiveOutputStream
类的具体详情如下:
包路径:org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream
类名称:ZipArchiveOutputStream
[英]Reimplementation of java.util.zip.ZipOutputStream that does handle the extended functionality of this package, especially internal/external file attributes and extra fields with different layouts for local file data and central directory entries.
This class will try to use java.nio.channels.SeekableByteChannel when it knows that the output is going to go to a file.
If SeekableByteChannel cannot be used, this implementation will use a Data Descriptor to store size and CRC information for #DEFLATED entries, this means, you don't need to calculate them yourself. Unfortunately this is not possible for the #STORED method, here setting the CRC and uncompressed size information is required before #putArchiveEntry(ArchiveEntry) can be called.
As of Apache Commons Compress 1.3 it transparently supports Zip64 extensions and thus individual entries and archives larger than 4 GB or with more than 65536 entries in most cases but explicit control is provided via #setUseZip64. If the stream can not use SeekableByteChannel and you try to write a ZipArchiveEntry of unknown size then Zip64 extensions will be disabled by default.
[中]java的重新实现。util。拉链ZipOutputStream,它可以处理这个包的扩展功能,尤其是内部/外部文件属性,以及本地文件数据和中心目录条目的不同布局的额外字段。
这个类将尝试使用java。尼奥。频道。seekablebytechnel,当它知道输出将进入文件时。
如果SeekableByteChannel无法使用,此实现将使用数据描述符存储#DEFLATED条目的大小和CRC信息,这意味着,您不需要自己计算它们。不幸的是,对于#存储方法,这是不可能的,在调用#putArchiveEntry(ArchiveEntry)之前,需要设置CRC和未压缩的大小信息。
从Apache Commons Compress 1.3开始,它透明地支持Zip64扩展,因此单个条目和归档大于4 GB,或者在大多数情况下超过65536个条目,但通过#setUseZip64提供显式控制。如果流无法使用SeekableByteChannel,并且您尝试写入大小未知的ZipArchiveEntry,则默认情况下将禁用Zip64扩展。
代码示例来源:origin: org.apache.poi/poi-ooxml
ZipArchiveOutputStream zos = new ZipArchiveOutputStream(fos);
ZipArchiveEntry zeNew = new ZipArchiveEntry(ze.getName());
zeNew.setComment(ze.getComment());
zeNew.setExtra(ze.getExtra());
zeNew.setTime(ze.getTime());
zos.putArchiveEntry(zeNew);
FilterOutputStream fos2 = new FilterOutputStream(zos) {
cos.close();
fos2.close();
zos.closeArchiveEntry();
zos.close();
fos.close();
zis.close();
代码示例来源:origin: plutext/docx4j
zos.putArchiveEntry(new ZipArchiveEntry(targetName));
part.getPartName().getName().substring(1) );
if (bytes == null) throw new IOException("part '" + part.getPartName() + "' not found");
zos.write( bytes.getBytes() );
zos.write(bytes, 0, read);
zos.closeArchiveEntry();
代码示例来源:origin: stackoverflow.com
ZipArchiveOutputStream ostream = ...; // Your initialization code here
ostream.setEncoding("Cp437"); // This should handle your "special" characters
ostream.setFallbackToUTF8(true); // For "unknown" characters!
ostream.setUseLanguageEncodingFlag(true);
ostream.setCreateUnicodeExtraFields(
ZipArchiveOutputStream.UnicodeExtraFieldPolicy.NOT_ENCODEABLE);
代码示例来源:origin: org.apache.commons/commons-compress
/**
* Adds an archive entry with a raw input stream.
*
* If crc, size and compressed size are supplied on the entry, these values will be used as-is.
* Zip64 status is re-established based on the settings in this stream, and the supplied value
* is ignored.
*
* The entry is put and closed immediately.
*
* @param entry The archive entry to add
* @param rawStream The raw input stream of a different entry. May be compressed/encrypted.
* @throws IOException If copying fails
*/
public void addRawArchiveEntry(final ZipArchiveEntry entry, final InputStream rawStream)
throws IOException {
final ZipArchiveEntry ae = new ZipArchiveEntry(entry);
if (hasZip64Extra(ae)) {
// Will be re-added as required. this may make the file generated with this method
// somewhat smaller than standard mode,
// since standard mode is unable to remove the zip 64 header.
ae.removeExtraField(Zip64ExtendedInformationExtraField.HEADER_ID);
}
final boolean is2PhaseSource = ae.getCrc() != ZipArchiveEntry.CRC_UNKNOWN
&& ae.getSize() != ArchiveEntry.SIZE_UNKNOWN
&& ae.getCompressedSize() != ArchiveEntry.SIZE_UNKNOWN;
putArchiveEntry(ae, is2PhaseSource);
copyFromZipInputStream(rawStream);
closeCopiedEntry(is2PhaseSource);
}
代码示例来源:origin: plutext/docx4j
public void saveContentTypes(ContentTypeManager ctm) throws Docx4JException {
try {
zos.putArchiveEntry(new ZipArchiveEntry("[Content_Types].xml"));
ctm.marshal(zos);
zos.closeArchiveEntry();
} catch (Exception e) {
throw new Docx4JException("Error marshalling Content_Types ", e);
}
}
代码示例来源:origin: org.apache.poi/poi-ooxml
@SuppressWarnings("resource")
@Override
public boolean saveImpl(Document content, OutputStream out) {
final ZipArchiveOutputStream zos = (out instanceof ZipArchiveOutputStream)
? (ZipArchiveOutputStream) out : new ZipArchiveOutputStream(out);
ZipArchiveEntry partEntry = new ZipArchiveEntry(CONTENT_TYPES_PART_NAME);
try {
// Referenced in ZIP
zos.putArchiveEntry(partEntry);
try {
// Saving data in the ZIP file
return StreamHelper.saveXmlInStream(content, zos);
} finally {
zos.closeArchiveEntry();
}
} catch (IOException ioe) {
logger.log(POILogger.ERROR, "Cannot write: " + CONTENT_TYPES_PART_NAME
+ " in Zip !", ioe);
return false;
}
}
}
代码示例来源:origin: com.haulmont.cuba/cuba-global
public static void writeArchivedLogTailToStream(File logFile, OutputStream outputStream) throws IOException {
if (!logFile.exists()) {
throw new FileNotFoundException();
}
ZipArchiveOutputStream zipOutputStream = new ZipArchiveOutputStream(outputStream);
zipOutputStream.setMethod(ZipArchiveOutputStream.DEFLATED);
zipOutputStream.setEncoding(ZIP_ENCODING);
byte[] content = getTailBytes(logFile);
ArchiveEntry archiveEntry = newTailArchive(logFile.getName(), content);
zipOutputStream.putArchiveEntry(archiveEntry);
zipOutputStream.write(content);
zipOutputStream.closeArchiveEntry();
zipOutputStream.close();
}
代码示例来源:origin: org.apache.poi/poi-ooxml
protected void injectData(ZipEntrySource zipEntrySource, OutputStream out) throws IOException {
ZipArchiveOutputStream zos = new ZipArchiveOutputStream(out);
try {
Enumeration<? extends ZipArchiveEntry> en = zipEntrySource.getEntries();
while (en.hasMoreElements()) {
ZipArchiveEntry ze = en.nextElement();
ZipArchiveEntry zeOut = new ZipArchiveEntry(ze.getName());
zeOut.setSize(ze.getSize());
zeOut.setTime(ze.getTime());
zos.putArchiveEntry(zeOut);
try (final InputStream is = zipEntrySource.getInputStream(ze)) {
if (is instanceof ZipArchiveThresholdInputStream) {
zos.closeArchiveEntry();
zos.finish();
zipEntrySource.close();
代码示例来源:origin: plutext/docx4j
ZipArchiveEntry ze = new ZipArchiveEntry(resolvedPartUri);
ze.setMethod(ZipArchiveOutputStream.STORED);
ze.setSize(bytes.length);
ze.setCompressedSize(bytes.length);
ze.setCrc(crc.getValue());
zos.putArchiveEntry(ze);
} else {
zos.putArchiveEntry(new ZipArchiveEntry(resolvedPartUri));
zos.write( bytes );
zos.closeArchiveEntry();
代码示例来源:origin: stackoverflow.com
byte[] zip(byte[] data, String filename) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ZipArchiveOutputStream zos = new ZipArchiveOutputStream(bos);
ZipArchiveEntry entry = new ZipArchiveEntry(filename);
entry.setSize(data.length);
zos.putArchiveEntry(entry);
zos.write(data);
zos.closeArchiveEntry();
zos.close();
bos.close();
return bos.toByteArray();
}
代码示例来源:origin: naver/ngrinder
ZipArchiveOutputStream zos = new ZipArchiveOutputStream(os);
zos.setEncoding(charsetName);
FileInputStream fis = null;
ze = new ZipArchiveEntry(name);
zos.putArchiveEntry(ze);
try {
fis = new FileInputStream(f);
while ((length = fis.read(buf, 0, buf.length)) >= 0) {
zos.write(buf, 0, length);
zos.closeArchiveEntry();
zos.close();
代码示例来源:origin: stackoverflow.com
import java.io.*;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
public class ZipFiles {
public static void main(String[] args) throws Exception{
ZipArchiveOutputStream zipOut = new ZipArchiveOutputStream(new FileOutputStream("测试.zip"));
zipOut.setEncoding("Cp437"); // This should handle your "special" characters
zipOut.setFallbackToUTF8(true); // For "unknown" characters!
zipOut.setUseLanguageEncodingFlag(true);
zipOut.setCreateUnicodeExtraFields(
ZipArchiveOutputStream.UnicodeExtraFieldPolicy.NOT_ENCODEABLE);
zipOut.putArchiveEntry(new ZipArchiveEntry("测试.xml"));
zipOut.putArchiveEntry(new ZipArchiveEntry("test.xml"));
zipOut.closeArchiveEntry();
zipOut.flush();
zipOut.close();
}
}
代码示例来源:origin: stackoverflow.com
import org.apache.commons.compress.archivers.ArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
import java.util.Arrays;
public class Test {
public static void main(String[] args) throws Exception {
ZipArchiveOutputStream zipOut = new ZipArchiveOutputStream(System.out);
byte[] data = new byte[1024*1024];
for(byte i=49; i<120; i++) {
Arrays.fill(data, i);
ArchiveEntry file1 = new ZipArchiveEntry("file" + i + ".txt");
zipOut.putArchiveEntry(file1);
zipOut.write(data);
zipOut.closeArchiveEntry();
}
zipOut.finish();
zipOut.close();
}
}
代码示例来源:origin: apache/tika
private static void repairCopy(File brokenZip, File fixedZip) {
try (ZipArchiveOutputStream outputStream = new ZipArchiveOutputStream(fixedZip)) {
try (InputStream is = new FileInputStream(brokenZip)) {
ZipArchiveInputStream zipArchiveInputStream = new ZipArchiveInputStream(is);
while (zae != null) {
try {
if (!zae.isDirectory() && zipArchiveInputStream.canReadEntryData(zae)) {
outputStream.putArchiveEntry(zae);
outputStream.flush();
outputStream.closeArchiveEntry();
if (!successfullyCopied) {
break;
outputStream.flush();
outputStream.finish();
outputStream.close();
代码示例来源:origin: apache/sis
try (ZipArchiveOutputStream zip = new ZipArchiveOutputStream(targetFile)) {
zip.setLevel(9);
appendRecursively(sourceDirectory, artifactBase, zip);
ZipArchiveEntry entry = new ZipArchiveEntry(artifactBase + '/' + LIB_DIRECTORY + '/' + file.getName());
zip.putArchiveEntry(entry);
appendJAR(file, zip, nativeFiles);
zip.closeArchiveEntry();
ZipArchiveEntry entry = new ZipArchiveEntry(artifactBase + '/' + LIB_DIRECTORY + '/' + nf.getKey());
entry.setUnixMode(0555); // Readable and executable for all, but not writable.
zip.putArchiveEntry(entry);
zip.write(nf.getValue());
zip.closeArchiveEntry();
nf.setValue(null);
代码示例来源:origin: plutext/docx4j
/**
* @param zipOutputStream the zipOutputStream to set
*/
public void setOutputStream(OutputStream os) {
this.zos = new ZipArchiveOutputStream(os);
}
代码示例来源:origin: USPTO/PatentPublicData
@Override
public void open() throws IOException {
outputZip = new ZipArchiveOutputStream(filePath.toFile());
outputZip.setEncoding("UTF-8");
outputZip.setLevel(9);
ZipArchiveEntry zipEntry = new ZipArchiveEntry("corpus.xml");
outputZip.putArchiveEntry(zipEntry);
}
代码示例来源:origin: Zlika/reproducible-build-maven-plugin
final ZipArchiveOutputStream zout = new ZipArchiveOutputStream(out))
stripper.strip(tmp, tmp2);
final byte[] fileContent = Files.readAllBytes(tmp2.toPath());
strippedEntry.setSize(fileContent.length);
zout.putArchiveEntry(strippedEntry);
zout.write(fileContent);
zout.closeArchiveEntry();
zout.addRawArchiveEntry(strippedEntry, zip.getRawInputStream(entry));
代码示例来源:origin: stackoverflow.com
// Obtain reference to file
HttpGet httpGet = new HttpGet("http://blahblablah.com/file.txt");
HttpResponse httpResponse = httpclient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
// Create the output ZIP file
ZipArchiveOutputStream zip = new ZipArchiveOutputStream(zipFile);
try {
// Write a file header in the .zip file
ArchiveEntry entry = new ZipArchiveEntry("file.txt");
zip.putArchiveEntry(entry);
// Download the file and write it to a compressed file
IOUtils.copy(httpEntity.getContent(), zip);
// The file is now written
zip.closeArchiveEntry();
} finally {
// Ensure output file is closed
zip.close();
}
代码示例来源:origin: org.openengsb.connector/org.openengsb.connector.git
@Override
public File export() {
try {
if (repository == null) {
initRepository();
}
LOGGER.debug("Exporting repository to archive");
File tmp = File.createTempFile("repository", ".zip");
ZipArchiveOutputStream zos = new ZipArchiveOutputStream(tmp);
packRepository(localWorkspace, zos);
zos.close();
return tmp;
} catch (IOException e) {
throw new ScmException(e);
}
}
有没有办法从 archive.org 上传或触发自己网站的快照到 WayBackMachine?我已经检查了常见问题解答和 archive.org API,但找不到任何使用脚本触发此问题的方法。 最佳
在我当前的项目中,我正在集成 RestKit 库(我不知道它是否重要),当我使用编译器提示的“存档”时尝试交付应用程序进行测试 "RestKit/RestKit.h" is not found 在构
在我的项目开始时,有两个 terraform 模块:base 和 reusable_module。 base/main.tf # Provide abstraction to define a lam
我试图弄清楚如何以正确的方式构建我的 Cocoa 应用程序的发布版本。 到目前为止,我已经使用了 为归档而构建 选项,并从 Xcode 的 DerivedData 文件夹深处获取应用程序包。 今天我试
我有一个 Swift 语言的 iOS 项目,我必须在终端上使用命令创建存档和 .ipa。 我正在使用 Github 操作在试飞中上传 iOS 版本。 我正在遵循此链接中提到的所有说明: https:/
我正在使用 GCC 从两个 *.a(静态库)创建一个共享对象库。我引用了这些文章: How to force gcc to link an unused static library How to i
我的应用程序突然停止创建 iOS App Archive,而是开始创建 Xcode Generic Archive。 这是在为我的应用程序的新版本进行更改后发生的,我添加了逻辑、UI 更改和一些新框架
我有一个包含大约 800 个 .tgz 文件的目录,每个文件包含大约 10 个文件。实际上,我想将每个存档转换为同名目录。是否有一个简单的一行命令来执行此操作,还是我应该编写一个脚本? 最佳答案 自
在 gcc 中使用 -Wl--whole-archive ... -Wl--no-whole-archive 标志时,您如何验证库内部的所有内容都正确链接?另外,您如何验证该库是否可以调用由 LD_L
我有一个用 Swift 编写的小型命令行应用程序,现在我想将其归档。然而,像我之前的许多其他人一样,我遇到了如何将 Archive Type 从 Generic Xcode Archive 更改为 M
我不确定是否应该对 .emacs.d 下的以下文件进行版本控制: [lucas@lucas-ThinkPad-W520]/home/lucas/.emacs.d$ file elpa/archives
我正在处理 Postgres DVD tutorial并且在导入示例数据库时遇到问题。 运行 pg_restore -U postgres -d dvdrental ~[filepath]/dvd-d
注意: Boost 的存档方案基于对称的输入和输出存档类。一直写这两者很乏味,所以我将使用 ?archive 来表示 oarchive 和 iarchive。 总结: 将自定义存档的基类从 binar
是否可以使用 Node.js 流构建一个 zip 存档,并在创建时通过对 HTTP GET 请求的响应将该 zip 存档提供给客户端/用户?我正在寻找一种最好避免将整个 zip 缓冲到服务器内存中的解
我正在尝试使用 XCODE 4.3.1 发布一个临时 ipa。归档我的 iOS 应用程序时,我可以在管理器中看到归档类型是“Mac App Archive”,虽然我知道它应该是“iOS App Arc
我正在参加 Udacity 的类(class),该类(class)要求我在我的系统上设置虚拟机。我已经下载并安装了 Virtual Box 和 Vagrant。当我尝试运行命令 vagrant up
我试图找到一个很好的例子来说明如何使用这些二进制宽字符版本的 boost 序列化内容。我拼凑了一些代码来尝试让它工作,但不幸的是,我在尝试编译它时遇到了链接器错误的轰炸。 这是我的代码,以防我做任何明
目标与问题 我在 IntelliJ 中创建了一个 Java 程序。我按照说明将其构建为 .jar 文件 here 。当我尝试运行它时,它给出以下输出: Parameters: archive-name
我已包含在 hector-core-1.1-2 文件夹中找到的所有 jar。还有其他我没有包含的 jar 吗?我尝试过的事情。1)清除netbeans缓存2)下载org.apache.xbean.fi
我正在尝试打开包含创建数据库和 INSERT 语句的 PostgreSQL 的 SQL 脚本(.sql 文件),但是当我尝试使用 PgAdmin 4 恢复数据库时,它给我错误提示“pg_restore
我是一名优秀的程序员,十分优秀!