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


Java ZipArchiveOutputStream.close方法代码示例

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


在下文中一共展示了ZipArchiveOutputStream.close方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: writeArchivedLogTailToStream

import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; //导入方法依赖的package包/类
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();
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:19,代码来源:LogArchiver.java

示例2: exportFolder

import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; //导入方法依赖的package包/类
@Override
public byte[] exportFolder(Folder folder) throws IOException {
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

    ZipArchiveOutputStream zipOutputStream = new ZipArchiveOutputStream(byteArrayOutputStream);
    zipOutputStream.setMethod(ZipArchiveOutputStream.STORED);
    zipOutputStream.setEncoding(StandardCharsets.UTF_8.name());
    String xml = createXStream().toXML(folder);
    byte[] xmlBytes = xml.getBytes(StandardCharsets.UTF_8);
    ArchiveEntry zipEntryDesign = newStoredEntry("folder.xml", xmlBytes);
    zipOutputStream.putArchiveEntry(zipEntryDesign);
    zipOutputStream.write(xmlBytes);
    try {
        zipOutputStream.closeArchiveEntry();
    } catch (Exception ex) {
        throw new RuntimeException(String.format("Exception occurred while exporting folder %s.",  folder.getName()));
    }

    zipOutputStream.close();
    return byteArrayOutputStream.toByteArray();
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:22,代码来源:FoldersServiceBean.java

示例3: compress

import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; //导入方法依赖的package包/类
public void compress(File[] files, File zipFile) throws IOException {
	if (files == null) {
		return;
	}
	ZipArchiveOutputStream out = new ZipArchiveOutputStream(zipFile);
	out.setUseZip64(Zip64Mode.AsNeeded);
	// 将每个文件用ZipArchiveEntry封装
	for (File file : files) {
		if (file == null) {
			continue;
		}
		compressOneFile(file, out, "");
	}
	if (out != null) {
		out.close();
	}
}
 
开发者ID:hoozheng,项目名称:AndroidRobot,代码行数:18,代码来源:ZipUtil.java

示例4: 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

示例5: 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

示例6: zip

import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; //导入方法依赖的package包/类
private File zip(File destination, String name) {
    try {
        File z = new File(Files.createTempDir(), name+".zip");
        ZipArchiveOutputStream out = ZipHelper.setupZipOutputStream(new FileOutputStream(z)); 
        for(String f : files(destination, "")) {
          out.putArchiveEntry(new ZipArchiveEntry(f));
          FileInputStream in = new FileInputStream(new File(destination, f));
          IOUtils.copy(in, out);
          in.close();
          out.closeArchiveEntry();
        }
        out.close();
        return z;
    } catch(Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:uq-eresearch,项目名称:aorra,代码行数:18,代码来源:HtmlZip.java

示例7: 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

示例8: 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

示例9: writeArchivedLogToStream

import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; //导入方法依赖的package包/类
public static void writeArchivedLogToStream(File logFile, OutputStream outputStream) throws IOException {
    if (!logFile.exists()) {
        throw new FileNotFoundException();
    }

    File tempFile = File.createTempFile(FilenameUtils.getBaseName(logFile.getName()) + "_log_", ".zip");

    ZipArchiveOutputStream zipOutputStream = new ZipArchiveOutputStream(tempFile);
    zipOutputStream.setMethod(ZipArchiveOutputStream.DEFLATED);
    zipOutputStream.setEncoding(ZIP_ENCODING);

    ArchiveEntry archiveEntry = newArchive(logFile);
    zipOutputStream.putArchiveEntry(archiveEntry);

    FileInputStream logFileInput = new FileInputStream(logFile);
    IOUtils.copyLarge(logFileInput, zipOutputStream);

    logFileInput.close();

    zipOutputStream.closeArchiveEntry();
    zipOutputStream.close();

    FileInputStream tempFileInput = new FileInputStream(tempFile);
    IOUtils.copyLarge(tempFileInput, outputStream);

    tempFileInput.close();

    FileUtils.deleteQuietly(tempFile);
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:30,代码来源:LogArchiver.java

示例10: zip

import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; //导入方法依赖的package包/类
public static void zip(File[] filesToZip, File baseDir, File zipFile, int clevel) throws Throwable {

		ZipArchiveOutputStream os = new ZipArchiveOutputStream(new BufferedOutputStream(new FileOutputStream(zipFile),
				BUFFER_SIZE));
		try {
			os.setLevel(clevel);
			os.setMethod(ZipArchiveOutputStream.DEFLATED);
			zip(filesToZip, baseDir, os);
		} finally {
			os.close();
		}

	}
 
开发者ID:uom-daris,项目名称:daris,代码行数:14,代码来源:ZipUtil.java

示例11: zipDir

import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; //导入方法依赖的package包/类
public static void zipDir(String zipFile, String dir) throws IOException {
  File dirObj = new File(dir);
  ZipArchiveOutputStream out = new ZipArchiveOutputStream(new FileOutputStream(zipFile));
  log.info("Creating : " + zipFile);
  try {
    addDir(dirObj, out, "");
  } finally {
    out.close();
  }
}
 
开发者ID:apache,项目名称:incubator-slider,代码行数:11,代码来源:TestUtility.java

示例12: 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

示例13: createZipFile

import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; //导入方法依赖的package包/类
public InputStream createZipFile(final FileStore.Folder folder)
    throws IOException, RepositoryException {
  final File tempFile = File.createTempFile("zipfile", "");
  final ZipArchiveOutputStream zos =
      ZipHelper.setupZipOutputStream(new FileOutputStream(tempFile));
  addFolderToZip(zos, folder, folder);
  zos.close();
  return new FileInputStream(tempFile) {
    @Override
    public void close() throws IOException {
      super.close();
      tempFile.delete();
    }
  };
}
 
开发者ID:uq-eresearch,项目名称:aorra,代码行数:16,代码来源:FileStoreHelper.java


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