当前位置: 首页>>代码示例>>Java>>正文


Java ZipArchiveOutputStream.finish方法代码示例

本文整理汇总了Java中org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream.finish方法的典型用法代码示例。如果您正苦于以下问题:Java ZipArchiveOutputStream.finish方法的具体用法?Java ZipArchiveOutputStream.finish怎么用?Java ZipArchiveOutputStream.finish使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream的用法示例。


在下文中一共展示了ZipArchiveOutputStream.finish方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
 
开发者ID:NitorCreations,项目名称:javaxdelta,代码行数:31,代码来源:JarDeltaJarPatcherTest.java

示例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);
}
 
开发者ID:NitorCreations,项目名称:javaxdelta,代码行数:34,代码来源:JarDeltaJarPatcherTest.java

示例3: addToZipFile

import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; //导入方法依赖的package包/类
public static File addToZipFile(final File directory, final String zipFilename, final String entryFilename, final String entryContent) throws IOException {
    final File zipFile = File.createTempFile(zipFilename, ".zip", directory);

    final FileOutputStream fileOutputStream = new FileOutputStream(zipFile);
    try {
        final ZipArchiveOutputStream zipArchiveOutputStream = new ZipArchiveOutputStream(fileOutputStream);
        zipArchiveOutputStream.putArchiveEntry(new ZipArchiveEntry(entryFilename));
        IOUtils.write(entryContent.getBytes(), zipArchiveOutputStream);
        zipArchiveOutputStream.closeArchiveEntry();
        zipArchiveOutputStream.finish();
    } finally {
        IOUtils.closeQuietly(fileOutputStream);
    }

    return zipFile;
}
 
开发者ID:RIPE-NCC,项目名称:whois,代码行数:17,代码来源:FileHelper.java

示例4: makeZip

import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; //导入方法依赖的package包/类
public static void makeZip() throws IOException, ArchiveException{
		File f1 = new File("D:/compresstest.txt");
        File f2 = new File("D:/test1.xml");
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        
        //ArchiveOutputStream ostemp = new ArchiveStreamFactory().createArchiveOutputStream("zip", baos);
        ZipArchiveOutputStream ostemp = new ZipArchiveOutputStream(baos);
        ostemp.setEncoding("GBK");
        ostemp.putArchiveEntry(new ZipArchiveEntry(f1.getName()));
        IOUtils.copy(new FileInputStream(f1), ostemp);
        ostemp.closeArchiveEntry();
        ostemp.putArchiveEntry(new ZipArchiveEntry(f2.getName()));
        IOUtils.copy(new FileInputStream(f2), ostemp);
        ostemp.closeArchiveEntry();
        ostemp.finish();
        ostemp.close();

//      final OutputStream out = new FileOutputStream("D:/testcompress.zip");
        final OutputStream out = new FileOutputStream("D:/中文名字.zip");
        ArchiveOutputStream os = new ArchiveStreamFactory().createArchiveOutputStream("zip", out);
        os.putArchiveEntry(new ZipArchiveEntry("打包.zip"));
        baos.writeTo(os);
        os.closeArchiveEntry();
        baos.close();
        os.finish();
        os.close();
	}
 
开发者ID:h819,项目名称:spring-boot,代码行数:28,代码来源:CompressExample.java

示例5: 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");
}
 
开发者ID:openkm,项目名称:document-management-system,代码行数:32,代码来源:ArchiveUtils.java

示例6: zip

import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; //导入方法依赖的package包/类
/**
 * Zips the contents of the tree at the (optionally) specified revision and the (optionally) specified basepath to the supplied outputstream.
 * 
 * @param repository
 * @param basePath
 *            if unspecified, entire repository is assumed.
 * @param objectId
 *            if unspecified, HEAD is assumed.
 * @param os
 * @return true if repository was successfully zipped to supplied output stream
 */
public static boolean zip(Repository repository, String basePath, String objectId, OutputStream os) {
	RevCommit commit = JGitUtils.getCommit(repository, objectId);
	if (commit == null) {
		return false;
	}
	boolean success = false;
	RevWalk rw = new RevWalk(repository);
	TreeWalk tw = new TreeWalk(repository);
	try {
		tw.reset();
		tw.addTree(commit.getTree());
		ZipArchiveOutputStream zos = new ZipArchiveOutputStream(os);
		zos.setComment("Generated by Gitblit");
		if (!StringUtils.isEmpty(basePath)) {
			PathFilter f = PathFilter.create(basePath);
			tw.setFilter(f);
		}
		tw.setRecursive(true);
		MutableObjectId id = new MutableObjectId();
		ObjectReader reader = tw.getObjectReader();
		long modified = commit.getAuthorIdent().getWhen().getTime();
		while (tw.next()) {
			FileMode mode = tw.getFileMode(0);
			if (mode == FileMode.GITLINK || mode == FileMode.TREE) {
				continue;
			}
			tw.getObjectId(id, 0);

			ZipArchiveEntry entry = new ZipArchiveEntry(tw.getPathString());
			entry.setSize(reader.getObjectSize(id, Constants.OBJ_BLOB));
			entry.setComment(commit.getName());
			entry.setUnixMode(mode.getBits());
			entry.setTime(modified);
			zos.putArchiveEntry(entry);

			ObjectLoader ldr = repository.open(id);
			ldr.copyTo(zos);
			zos.closeArchiveEntry();
		}
		zos.finish();
		success = true;
	} catch (IOException e) {
		error(e, repository, "{0} failed to zip files from commit {1}", commit.getName());
	} finally {
		tw.close();
		rw.close();
		rw.dispose();
	}
	return success;
}
 
开发者ID:tomaswolf,项目名称:gerrit-gitblit-plugin,代码行数:62,代码来源:CompressionUtils.java

示例7: addFilesToZip

import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; //导入方法依赖的package包/类
public void addFilesToZip(String archive, String[] files) throws IOException {
	ZipArchiveOutputStream zos = new ZipArchiveOutputStream(new BufferedOutputStream(new FileOutputStream(archive)));
	
	for (String file : files) {
		addFileToZip(zos, file, "");
	}
	
	zos.finish();
       zos.close();
}
 
开发者ID:mihhail-lapushkin,项目名称:CocoonJS-Compiler,代码行数:11,代码来源:ZipArchiver.java

示例8: zip

import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; //导入方法依赖的package包/类
/**
 * Zips the contents of the tree at the (optionally) specified revision and
 * the (optionally) specified basepath to the supplied outputstream.
 * 
 * @param repository
 * @param basePath
 *            if unspecified, entire repository is assumed.
 * @param objectId
 *            if unspecified, HEAD is assumed.
 * @param os
 * @return true if repository was successfully zipped to supplied output
 *         stream
 */
public static boolean zip(Repository repository, String basePath, String objectId,
		OutputStream os) {
	RevCommit commit = JGitUtils.getCommit(repository, objectId);
	if (commit == null) {
		return false;
	}
	boolean success = false;
	RevWalk rw = new RevWalk(repository);
	TreeWalk tw = new TreeWalk(repository);
	try {
		tw.reset();
		tw.addTree(commit.getTree());
		ZipArchiveOutputStream zos = new ZipArchiveOutputStream(os);
		zos.setComment("Generated by Gitblit");
		if (!StringUtils.isEmpty(basePath)) {
			PathFilter f = PathFilter.create(basePath);
			tw.setFilter(f);
		}
		tw.setRecursive(true);
		MutableObjectId id = new MutableObjectId();
		ObjectReader reader = tw.getObjectReader();
		long modified = commit.getAuthorIdent().getWhen().getTime();
		while (tw.next()) {
			FileMode mode = tw.getFileMode(0);
			if (mode == FileMode.GITLINK || mode == FileMode.TREE) {
				continue;
			}
			tw.getObjectId(id, 0);

			ZipArchiveEntry entry = new ZipArchiveEntry(tw.getPathString());
			entry.setSize(reader.getObjectSize(id, Constants.OBJ_BLOB));
			entry.setComment(commit.getName());
			entry.setUnixMode(mode.getBits());
			entry.setTime(modified);
			zos.putArchiveEntry(entry);

			ObjectLoader ldr = repository.open(id);
			ldr.copyTo(zos);
			zos.closeArchiveEntry();
		}
		zos.finish();
		success = true;
	} catch (IOException e) {
		error(e, repository, "{0} failed to zip files from commit {1}", commit.getName());
	} finally {
		tw.release();
		rw.dispose();
	}
	return success;
}
 
开发者ID:warpfork,项目名称:gitblit,代码行数:64,代码来源:CompressionUtils.java

示例9: createTestZipFile

import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; //导入方法依赖的package包/类
public File createTestZipFile(String encoding) {
  OutputStream outputStream = null;

  try {
    File zipfile = TempFileProvider.createTempFile("zip_output", ".zip");

    outputStream = new FileOutputStream(zipfile);

    ZipArchiveOutputStream logicalZip = (ZipArchiveOutputStream) new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.ZIP, outputStream);

    if (StringUtils.isNotBlank(encoding)) {
      logicalZip.setEncoding(encoding);
    }

    addFileToZip("file1.txt", logicalZip);
    addFileToZip("file2.txt", logicalZip);
    addFileToZip("folder.with.dots.in.the.name/", logicalZip);
    addFileToZip("folder.with.dots.in.the.name/file5.txt", logicalZip);
    addFileToZip("folder.with.dots.in.the.name/file4.txt", logicalZip);
    addFileToZip("folder1/", logicalZip);
    addFileToZip("folder1/file3.txt", logicalZip);
    addFileToZip("file_ending_with_a_dot.", logicalZip);
    addFileToZip("file+with+plus+in+it.txt", logicalZip);
    addFileToZip("file\"qoute_in_it.txt", logicalZip);
    addFileToZip("file_with_&_in_it.txt", logicalZip);
    // addFileToZip("1. Överenskommelser/5. Utskickade tåkar under 2013/608 Primärvården VGR PNV Tåk FM-kontor Lokalvård PV Mölnlycke barnmott, Mödrabarnhälsa i haga, Psykologi.pdf", logicalZip);
    
    logicalZip.finish();

    return zipfile;
  } catch (Exception ex) {
    throw new RuntimeException(ex);
  } finally {
    IOUtils.closeQuietly(outputStream);
  }
}
 
开发者ID:Redpill-Linpro,项目名称:alfresco-unzip,代码行数:37,代码来源:AbstractUnzipIntegrationTest.java

示例10: disposeContainer

import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; //导入方法依赖的package包/类
@Override
protected void disposeContainer(ZipArchiveOutputStream container) throws IOException {
    container.finish();
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:5,代码来源:MCRZipServlet.java

示例11: 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();
}
 
开发者ID:NitorCreations,项目名称:javaxdelta,代码行数:31,代码来源:JarDelta.java


注:本文中的org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream.finish方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。