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


Java ZipOutputStream类代码示例

本文整理汇总了Java中java.util.zip.ZipOutputStream的典型用法代码示例。如果您正苦于以下问题:Java ZipOutputStream类的具体用法?Java ZipOutputStream怎么用?Java ZipOutputStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: zipBase64

import java.util.zip.ZipOutputStream; //导入依赖的package包/类
/**
 * Combines multiple files into a ZIP archive, then base-64 the ZIP archive.
 *
 * @param paths a list of one or more input files, that are to be compressed together
 * @return the compressed output, as a String
 */
private static String zipBase64(List<Path> paths) {
  if (paths.isEmpty()) {
    throw new IllegalArgumentException("PortfolioDataFile requires at least one file");
  }
  try {
    try (ByteArrayOutputStream baos = new ByteArrayOutputStream(1024 * 8)) {
      try (OutputStream baseos = Base64.getEncoder().wrap(baos)) {
        try (ZipOutputStream zos = new ZipOutputStream(baseos)) {
          for (Path path : paths) {
            ZipEntry entry = new ZipEntry(path.getFileName().toString());
            zos.putNextEntry(entry);
            Files.copy(path, zos);
            zos.closeEntry();
          }
        }
      }
      return baos.toString("ISO-8859-1");  // base-64 bytes are ASCII, so this is optimal
    }
  } catch (IOException ex) {
    throw new UncheckedIOException("Failed to zip base-64 content", ex);
  }
}
 
开发者ID:OpenGamma,项目名称:JavaSDK,代码行数:29,代码来源:PortfolioDataFile.java

示例2: main

import java.util.zip.ZipOutputStream; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    // create a zip file, and read it in as a byte array
    Path path = Files.createTempFile("bad", ".zip");
    try (OutputStream os = Files.newOutputStream(path);
            ZipOutputStream zos = new ZipOutputStream(os)) {
        ZipEntry e = new ZipEntry("x");
        zos.putNextEntry(e);
        zos.write((int) 'x');
    }
    int len = (int) Files.size(path);
    byte[] data = new byte[len];
    try (InputStream is = Files.newInputStream(path)) {
        is.read(data);
    }
    Files.delete(path);

    // year, month, day are zero
    testDate(data.clone(), 0, LocalDate.of(1979, 11, 30));
    // only year is zero
    testDate(data.clone(), 0 << 25 | 4 << 21 | 5 << 16, LocalDate.of(1980, 4, 5));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:ZeroDate.java

示例3: compressFiles

import java.util.zip.ZipOutputStream; //导入依赖的package包/类
/**
 * Compresses a collection of files to a destination zip file
 * @param listFiles A collection of files and directories
 * @param destZipFile The path of the destination zip file
 * @throws FileNotFoundException
 * @throws IOException
 */
public void compressFiles(List<File> listFiles, String destZipFile) throws FileNotFoundException, IOException {

    ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(destZipFile));

    for (File file : listFiles) {
        if (file.isDirectory()) {
            addFolderToZip(file, file.getName(), zos);
        } else {
            addFileToZip(file, zos);
        }
    }

    zos.flush();
    zos.close();
}
 
开发者ID:wu191287278,项目名称:sc-generator,代码行数:23,代码来源:ZipUtil.java

示例4: zipEntries

import java.util.zip.ZipOutputStream; //导入依赖的package包/类
private ByteArrayOutputStream zipEntries(List<Pair<String, byte[]>> entryList) throws IOException {
    ByteArrayOutputStream buffer = new ByteArrayOutputStream(8192);
    try (ZipOutputStream jar = new ZipOutputStream(buffer)) {
        jar.setMethod(ZipOutputStream.STORED);
        final CRC32 crc = new CRC32();
        for (Pair<String, byte[]> entry : entryList) {
            byte[] bytes = entry.second;
            final ZipEntry newEntry = new ZipEntry(entry.first);
            newEntry.setMethod(ZipEntry.STORED); // chose STORED method
            crc.reset();
            crc.update(entry.second);
            newEntry.setCrc(crc.getValue());
            newEntry.setSize(bytes.length);
            writeEntryToJar(newEntry, bytes, jar);
        }
        jar.flush();
    }
    return buffer;
}
 
开发者ID:yrom,项目名称:shrinker,代码行数:20,代码来源:JarProcessor.java

示例5: write

import java.util.zip.ZipOutputStream; //导入依赖的package包/类
@Override
public boolean write(OutputStream out, ProgressReporter progressReporter) throws SerializerException {
	if (getMode() == Mode.BODY) {
		try {
			ZipOutputStream zipOutputStream = new ZipOutputStream(out);
			zipOutputStream.putNextEntry(new ZipEntry("doc.kml"));
			writeKmlFile(zipOutputStream);
			zipOutputStream.closeEntry();
			zipOutputStream.putNextEntry(new ZipEntry("files/collada.dae"));
			ifcToCollada.writeToOutputStream(zipOutputStream, progressReporter);
			zipOutputStream.closeEntry();
			zipOutputStream.finish();
			zipOutputStream.flush();
		} catch (IOException e) {
			LOGGER.error("", e);
		}
		setMode(Mode.FINISHED);
		return true;
	} else if (getMode() == Mode.HEADER) {
		setMode(Mode.BODY);
		return true;
	} else if (getMode() == Mode.FINISHED) {
		return false;
	}
	return false;
}
 
开发者ID:shenan4321,项目名称:BIMplatform,代码行数:27,代码来源:KmzSerializer.java

示例6: zipFolder

import java.util.zip.ZipOutputStream; //导入依赖的package包/类
public static void zipFolder(String folderToZip, String destZipFile)
{
	try
	{
		FileOutputStream fileWriter = new FileOutputStream(destZipFile);
		ZipOutputStream zip = new ZipOutputStream(fileWriter);

		addFolderToZip("", folderToZip, zip);
		
		zip.flush();
		zip.close();
	}
	catch(Exception e)
	{
		e.printStackTrace();
	}
}
 
开发者ID:ObsidianSuite,项目名称:ObsidianSuite,代码行数:18,代码来源:ZipUtils.java

示例7: dowloadCode

import java.util.zip.ZipOutputStream; //导入依赖的package包/类
/** 코드를 다운로드함.
 * @param code
 * @param os
 */
public void dowloadCode(Code code, OutputStream os){
	try {
		ZipOutputStream zip = new ZipOutputStream(new BufferedOutputStream(os),Charset.forName("8859_1"));
		for(SimpleCode simpleCode :code.getCodes()){
			zip.putNextEntry(new ZipEntry(new String (simpleCode.getFileName().getBytes(),"8859_1") ));
			if(WebUtil.isCodeName(new String(simpleCode.getFileName().getBytes("8859_1"),"EUC-KR")))
				zip.write(simpleCode.getContent().getBytes("EUC-KR"));
			else
				zip.write(simpleCode.getContent().getBytes("8859_1"));

		}	
		code.download();
		codeDao.update(code);
		zip.close();
	} catch(Exception e) {
		System.err.println(e.getMessage());
	}
}
 
开发者ID:forweaver,项目名称:forweaver2.0,代码行数:23,代码来源:CodeService.java

示例8: createTestFile

import java.util.zip.ZipOutputStream; //导入依赖的package包/类
private static File createTestFile(int compression) throws Exception {
    File tempZipFile =
        File.createTempFile("test-data" + compression, ".zip");
    tempZipFile.deleteOnExit();

    try (FileOutputStream fos = new FileOutputStream(tempZipFile);
            ZipOutputStream zos = new ZipOutputStream(fos)) {
        zos.setLevel(compression);
        for (int i = 0; i < ZIP_ENTRY_NUM; i++) {
            String text = "Entry" + i;
            ZipEntry entry = new ZipEntry(text);
            zos.putNextEntry(entry);
            try {
                zos.write(data[i], 0, data[i].length);
            } finally {
                zos.closeEntry();
            }
        }
    }

    return tempZipFile;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:23,代码来源:ClearStaleZipFileInputStreams.java

示例9: processFiles

import java.util.zip.ZipOutputStream; //导入依赖的package包/类
private void processFiles(ZipOutputStream outputStream, Iterable<? extends File> files, byte[] buffer, HashSet<String> seenPaths, Map<String, List<String>> services,
                          ProgressLogger progressLogger) throws Exception {
    PercentageProgressFormatter progressFormatter = new PercentageProgressFormatter("Generating", Iterables.size(files) + ADDITIONAL_PROGRESS_STEPS);

    for (File file : files) {
        progressLogger.progress(progressFormatter.getProgress());

        if (file.getName().endsWith(".jar")) {
            processJarFile(outputStream, file, buffer, seenPaths, services);
        } else {
            processDirectory(outputStream, file, buffer, seenPaths, services);
        }

        progressFormatter.increment();
    }

    writeServiceFiles(outputStream, services);
    progressLogger.progress(progressFormatter.incrementAndGetProgress());

    writeIdentifyingMarkerFile(outputStream);
    progressLogger.progress(progressFormatter.incrementAndGetProgress());
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:23,代码来源:RuntimeShadedJarCreator.java

示例10: addFolderToZip

import java.util.zip.ZipOutputStream; //导入依赖的package包/类
private static void addFolderToZip(String path, String srcFolder, ZipOutputStream zip) throws Exception 
{
	File folder = new File(srcFolder);

	for (String fileName : folder.list()) 
	{
		if (path.equals("")) 
		{
			addFileToZip(folder.getName(), srcFolder + "/" + fileName, zip);
		} 
		else 
		{
			addFileToZip(path + "/" + folder.getName(), srcFolder + "/" + fileName, zip);
		}
	}
}
 
开发者ID:ObsidianSuite,项目名称:ObsidianSuite,代码行数:17,代码来源:ZipUtils.java

示例11: saveResultsFile

import java.util.zip.ZipOutputStream; //导入依赖的package包/类
@Override
public void saveResultsFile(Document doc, Element root, ZipOutputStream zos) throws IOException {
	int algo, numRes = clusterOperation.size();
	String algoName;

	for (int i = 0; i < numRes; i++) {
		algo = clusterOperation.get(i).getClusteringType();
		algoName = String.valueOf(clusterOperation.get(i).getName());
		algoName += "_" + i;
		zos.putNextEntry(new ZipEntry(algoName + JwatSession.BINext));
		switch (algo) {
			case JWATConstants.KMEANS:
				saveKmeansData(zos, (KMean) clusterOperation.get(i));
				break;
			case JWATConstants.FUZZYK:
				saveFuzzyData(zos, (FuzzyKMean) clusterOperation.get(i));
				break;
		}
		zos.closeEntry();
	}

}
 
开发者ID:HOMlab,项目名称:QN-ACTR-Release,代码行数:23,代码来源:WorkloadAnalysisSession.java

示例12: compress

import java.util.zip.ZipOutputStream; //导入依赖的package包/类
/**
 *
 * @param map key压缩条目路径 value重命名
 * @param zipPath 压缩文件路径
 * @return
 * @throws IOException
 */
public static boolean compress(Map<String, String> map, String zipPath) throws IOException {
    ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(zipPath));
    for (Map.Entry<String, String> entry : map.entrySet()) {
        File file = new File(entry.getKey());
        if (file.exists()) {
            InputStream inputStream = new FileInputStream(file);
            ZipEntry zipEntry = new ZipEntry(entry.getValue());
            zipOutputStream.putNextEntry(zipEntry);
            int len = inputStream.read();
            while (len != -1) {
                zipOutputStream.write(len);
                len = inputStream.read();
            }
            inputStream.close();
        }
    }
    zipOutputStream.close();
    return true;
}
 
开发者ID:Topview-us,项目名称:school-website,代码行数:27,代码来源:OperateFileUtils.java

示例13: zipFile

import java.util.zip.ZipOutputStream; //导入依赖的package包/类
/**
 * Compactar uma arquivo.
 * @param inputFile informar o arquivo a ser compactado.
 * @param zipFilePath informar o nome e caminho zip.
 * @param iZipFile se necessário, informar uma {@link IZipFile}.
 * @throws IOException
 */
public static void zipFile(File inputFile, String zipFilePath, IZipFile iZipFile) throws IOException {
    FileOutputStream fileOutputStream = new FileOutputStream(zipFilePath);
    ZipOutputStream zipOutputStream = new ZipOutputStream(fileOutputStream);
    ZipEntry zipEntry = new ZipEntry(inputFile.getName());
    zipOutputStream.putNextEntry(zipEntry);
    FileInputStream fileInputStream = new FileInputStream(inputFile);
    FileChannel fileChannel = fileInputStream.getChannel();
    FileLock fileLock = fileChannel.tryLock(0L, Long.MAX_VALUE, /*shared*/true);
    long sizeToZip = fileInputStream.available();
    long sizeCompacted = 0;
    try {
        byte[] buf = new byte[1024];
        int bytesRead;
        while ((bytesRead = fileInputStream.read(buf)) > 0) {
            sizeCompacted += bytesRead;
            zipOutputStream.write(buf, 0, bytesRead);
            if (iZipFile != null) iZipFile.progress(sizeToZip, sizeCompacted);
        }
    } finally {
        fileLock.release();
        zipOutputStream.closeEntry();
        zipOutputStream.close();
        fileOutputStream.close();
    }
}
 
开发者ID:brolam,项目名称:OpenHomeAnalysis,代码行数:33,代码来源:OhaHelper.java

示例14: testGetFileForInputWithCachingArchive

import java.util.zip.ZipOutputStream; //导入依赖的package包/类
public void testGetFileForInputWithCachingArchive() throws  Exception {
    final File wd = getWorkDir();
    final File archiveFile = new File (wd, "src.zip");
    final ZipOutputStream out = new ZipOutputStream(new FileOutputStream(archiveFile));
    try {
        out.putNextEntry(new ZipEntry("org/me/resources/test.txt"));
        out.write("test".getBytes());
    } finally {
        out.close();
    }
    final URL archiveRoot = FileUtil.getArchiveRoot(Utilities.toURI(archiveFile).toURL());
    final URI expectedURI = new URL (archiveRoot.toExternalForm()+"org/me/resources/test.txt").toURI();
    doTestGetFileForInput(ClassPathSupport.createClassPath(archiveRoot),
    Arrays.asList(
        Pair.<Pair<String,String>,URI>of(Pair.<String,String>of("","org/me/resources/test.txt"), expectedURI),
        Pair.<Pair<String,String>,URI>of(Pair.<String,String>of("org.me","resources/test.txt"), expectedURI),
        Pair.<Pair<String,String>,URI>of(Pair.<String,String>of("org.me","resources/doesnotexist.txt"), null)
    ));

}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:CachingFileManagerTest.java

示例15: zipDir

import java.util.zip.ZipOutputStream; //导入依赖的package包/类
private static void zipDir(File dir, String relativePath, ZipOutputStream zos,
                           boolean start) throws IOException {
  String[] dirList = dir.list();
  for (String aDirList : dirList) {
    File f = new File(dir, aDirList);
    if (!f.isHidden()) {
      if (f.isDirectory()) {
        if (!start) {
          ZipEntry dirEntry = new ZipEntry(relativePath + f.getName() + "/");
          zos.putNextEntry(dirEntry);
          zos.closeEntry();
        }
        String filePath = f.getPath();
        File file = new File(filePath);
        zipDir(file, relativePath + f.getName() + "/", zos, false);
      }
      else {
        String path = relativePath + f.getName();
        if (!path.equals(JarFile.MANIFEST_NAME)) {
          ZipEntry anEntry = new ZipEntry(path);
          copyToZipStream(f, anEntry, zos);
        }
      }
    }
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:27,代码来源:JarFinder.java


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