本文整理汇总了Java中org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream.flush方法的典型用法代码示例。如果您正苦于以下问题:Java ZipArchiveOutputStream.flush方法的具体用法?Java ZipArchiveOutputStream.flush怎么用?Java ZipArchiveOutputStream.flush使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream
的用法示例。
在下文中一共展示了ZipArchiveOutputStream.flush方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: makeSourceZipFile
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; //导入方法依赖的package包/类
/**
* Creates a zip file with random content.
*
* @author S3460
* @param source the source
* @return the zip file
* @throws Exception the exception
*/
private ZipFile makeSourceZipFile(File source) throws Exception {
ZipArchiveOutputStream out = new ZipArchiveOutputStream(new FileOutputStream(source));
int size = randomSize(entryMaxSize);
for (int i = 0; i < size; i++) {
out.putArchiveEntry(new ZipArchiveEntry("zipentry" + i));
int anz = randomSize(10);
for (int j = 0; j < anz; j++) {
byte[] bytes = getRandomBytes();
out.write(bytes, 0, bytes.length);
}
out.flush();
out.closeArchiveEntry();
}
//add leeres Entry
out.putArchiveEntry(new ZipArchiveEntry("zipentry" + size));
out.flush();
out.closeArchiveEntry();
out.flush();
out.finish();
out.close();
return new ZipFile(source);
}
示例2: makeTargetZipFile
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; //导入方法依赖的package包/类
/**
* Writes a modified version of zip_Source into target.
*
* @author S3460
* @param zipSource the zip source
* @param target the target
* @return the zip file
* @throws Exception the exception
*/
private ZipFile makeTargetZipFile(ZipFile zipSource, File target) throws Exception {
ZipArchiveOutputStream out = new ZipArchiveOutputStream(new FileOutputStream(target));
for (Enumeration<ZipArchiveEntry> enumer = zipSource.getEntries(); enumer.hasMoreElements();) {
ZipArchiveEntry sourceEntry = enumer.nextElement();
out.putArchiveEntry(new ZipArchiveEntry(sourceEntry.getName()));
byte[] oldBytes = toBytes(zipSource, sourceEntry);
byte[] newBytes = getRandomBytes();
byte[] mixedBytes = mixBytes(oldBytes, newBytes);
out.write(mixedBytes, 0, mixedBytes.length);
out.flush();
out.closeArchiveEntry();
}
out.putArchiveEntry(new ZipArchiveEntry("zipentry" + entryMaxSize + 1));
byte[] bytes = getRandomBytes();
out.write(bytes, 0, bytes.length);
out.flush();
out.closeArchiveEntry();
out.putArchiveEntry(new ZipArchiveEntry("zipentry" + (entryMaxSize + 2)));
out.closeArchiveEntry();
out.flush();
out.finish();
out.close();
return new ZipFile(targetFile);
}
示例3: createZip
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; //导入方法依赖的package包/类
/**
* Create ZIP archive from file
*/
public static void createZip(File path, OutputStream os) throws IOException {
log.debug("createZip({}, {})", new Object[]{path, os});
if (path.exists() && path.canRead()) {
ZipArchiveOutputStream zaos = new ZipArchiveOutputStream(os);
zaos.setComment("Generated by OpenKM");
zaos.setCreateUnicodeExtraFields(UnicodeExtraFieldPolicy.ALWAYS);
zaos.setUseLanguageEncodingFlag(true);
zaos.setFallbackToUTF8(true);
zaos.setEncoding("UTF-8");
log.debug("FILE {}", path);
ZipArchiveEntry zae = new ZipArchiveEntry(path.getName());
zaos.putArchiveEntry(zae);
FileInputStream fis = new FileInputStream(path);
IOUtils.copy(fis, zaos);
fis.close();
zaos.closeArchiveEntry();
zaos.flush();
zaos.finish();
zaos.close();
} else {
throw new IOException("Can't access " + path);
}
log.debug("createZip: void");
}
示例4: computeDelta
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; //导入方法依赖的package包/类
/**
* Computes the binary differences of two zip files. For all files contained in source and target which
* are not equal, the binary difference is caluclated by using
* {@link com.nothome.delta.Delta#compute(byte[], InputStream, DiffWriter)}.
* If the files are equal, nothing is written to the output for them.
* Files contained only in target and files to small for {@link com.nothome.delta.Delta} are copied to output.
* Files contained only in source are ignored.
* At last a list of all files contained in target is written to <code>META-INF/file.list</code> in output.
*
* @param sourceName the original zip file
* @param targetName a modification of the original zip file
* @param source the original zip file
* @param target a modification of the original zip file
* @param output the zip file where the patches have to be written to
* @throws IOException if an error occurs reading or writing any entry in a zip file
*/
public void computeDelta(String sourceName, String targetName, ZipFile source, ZipFile target, ZipArchiveOutputStream output) throws IOException {
ByteArrayOutputStream listBytes = new ByteArrayOutputStream();
PrintWriter list = new PrintWriter(new OutputStreamWriter(listBytes));
list.println(sourceName);
list.println(targetName);
computeDelta(source, target, output, list, "");
list.close();
ZipArchiveEntry listEntry = new ZipArchiveEntry("META-INF/file.list");
output.putArchiveEntry(listEntry);
output.write(listBytes.toByteArray());
output.closeArchiveEntry();
output.finish();
output.flush();
}
示例5: closeEntry
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; //导入方法依赖的package包/类
/**
* Close entry.
*
* @param output the output
* @param outEntry the out entry
* @param crc the crc
* @throws IOException Signals that an I/O exception has occurred.
*/
private void closeEntry(ZipArchiveOutputStream output, ZipArchiveEntry outEntry, long crc) throws IOException {
output.flush();
output.closeArchiveEntry();
if (outEntry.getCrc() != crc)
throw new IOException("CRC mismatch for " + outEntry.getName());
}