當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。