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


Java ZipOutputStream.close方法代码示例

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


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

示例1: zipFolder

import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
private void zipFolder(Path sourceFolderPath, Path zipPath) throws Exception
{
    ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipPath.toFile()));
    Files.walkFileTree(
            sourceFolderPath,
            EnumSet.noneOf(FileVisitOption.class),
            Integer.MAX_VALUE,
            new SimpleFileVisitor<Path>() {
                public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException
                {
                    try
                    {
                        zos.putNextEntry(new ZipEntry(sourceFolderPath.relativize(file).toString()));
                        Files.copy(file, zos);
                        zos.closeEntry();
                    } catch (Exception ex)
                    {
                        zos.closeEntry();
                    }
                    return FileVisitResult.CONTINUE;
                }
            });
    zos.close();
}
 
开发者ID:Dytanic,项目名称:CloudNet,代码行数:25,代码来源:MasterTemplateDeploy.java

示例2: zipLogs

import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
public static boolean zipLogs(StringBuilder sb, String toZipFile){
    boolean success = false;
    try {
        FileOutputStream zip = new FileOutputStream(toZipFile);

        ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(zip));
        ZipEntry entry = new ZipEntry("logs.txt");
        out.putNextEntry(entry);

        out.write(sb.toString().getBytes());

        out.close();
        success = true;

    } catch (Exception e){
        Log.e("Exception when trying to zip the logs: " + e.getMessage());
    }

    return success;
}
 
开发者ID:treasure-lau,项目名称:Linphone4Android,代码行数:21,代码来源:LinphoneUtils.java

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

示例4: pack

import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
/**
 * Pack emojis into one zip file
 * @param directory Directory that includes the folder (which is stored in /splice/*.png)
 * @return Zipped file
 * @throws IOException 
 */
private static File pack(File directory) throws IOException {
	byte[] buffer = new byte[1024];
	File toReturn = new File(directory.getAbsolutePath() + "/splice.zip");
	ZipOutputStream zip = new ZipOutputStream(new FileOutputStream(toReturn));

	File dir = new File(directory.getAbsolutePath() + "/splice/");
	for (File f : dir.listFiles()) {
		FileInputStream in = new FileInputStream(f);
		
		zip.putNextEntry(new ZipEntry(f.getName()));
		int length;

		while((length = in.read(buffer)) > 0) {
			zip.write(buffer, 0, length);
		}
		in.close();
		zip.closeEntry();
	}
	zip.close();

	return toReturn;
}
 
开发者ID:paul-io,项目名称:momo-2,代码行数:29,代码来源:Slice.java

示例5: compress

import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
/**
 * Compresses a single file (source) and prepares a zip file (target)
 *
 * @param source
 * @param target
 * @throws IOException
 */
public static void compress(File source, File target) throws IOException {

    ZipOutputStream zipOut = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(target)));
    ZipEntry zipEntry = new ZipEntry(source.getName());
    zipOut.putNextEntry(zipEntry);
    BufferedInputStream bis = new BufferedInputStream(new FileInputStream(source), BUFFER);
    byte data[] = new byte[BUFFER];

    int count = 0;
    while ((count = bis.read(data, 0, BUFFER)) != -1) {
        zipOut.write(data, 0, count);
    }
    bis.close();
    zipOut.close();

}
 
开发者ID:yongbeam,项目名称:AirQuickUtils,代码行数:24,代码来源:AirSystem.java

示例6: writeJar

import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
private static void writeJar(String jarFile, Manifest manifest, String classes[], int from, int to) throws Exception {
    if (DEBUG) {
        System.out.println("ClassFileInstaller: Writing to " + getJarPath(jarFile));
    }

    (new File(jarFile)).delete();
    FileOutputStream fos = new FileOutputStream(jarFile);
    ZipOutputStream zos = new ZipOutputStream(fos);

    // The manifest must be the first or second entry. See comments in JarInputStream
    // constructor and JDK-5046178.
    if (manifest != null) {
        writeToDisk(zos, "META-INF/MANIFEST.MF", manifest.getInputStream());
    }

    for (int i=from; i<to; i++) {
        writeClassToDisk(zos, classes[i]);
    }

    zos.close();
    fos.close();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:ClassFileInstaller.java

示例7: zip

import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
/**
 * ZIP the requested elements (files/directories) in the given directory and
 * download the resulting ZIP file.
 * 
 * @param request
 *            - the HttpServletRequest object
 * @param dir
 *            - the directory in which the element is renamed
 * @param elementList
 *            - the names of the elements (files/directories) to zip
 * @throws IOException
 *             - if an input or output error is detected when the servlet
 *             handles the request
 */
private ByteArrayOutputStream zip(HttpServletRequest request, File dir,
        List<String> elementList) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ZipOutputStream zos = new ZipOutputStream(baos);

    for (Iterator<String> it = elementList.iterator(); it.hasNext();) {
        String element = it.next();
        if (element.length() == 0) {
            continue;
        }
        File file = new File(dir, element);
        if (isAccessible(request, file)) {
            if (file.isDirectory()) {
                zipDir(zos, element, file);
            } else {
                zipFile(zos, element, file);
            }
        }
    }
    zos.close();

    return baos;
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:38,代码来源:ExampleServlet.java

示例8: main

import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    URLConnection conn = B7050028.class.getResource("B7050028.class").openConnection();
    int len = conn.getContentLength();
    byte[] data = new byte[len];
    InputStream is = conn.getInputStream();
    is.read(data);
    is.close();
    conn.setDefaultUseCaches(false);
    File jar = File.createTempFile("B7050028", ".jar");
    jar.deleteOnExit();
    OutputStream os = new FileOutputStream(jar);
    ZipOutputStream zos = new ZipOutputStream(os);
    ZipEntry ze = new ZipEntry("B7050028.class");
    ze.setMethod(ZipEntry.STORED);
    ze.setSize(len);
    CRC32 crc = new CRC32();
    crc.update(data);
    ze.setCrc(crc.getValue());
    zos.putNextEntry(ze);
    zos.write(data, 0, len);
    zos.closeEntry();
    zos.finish();
    zos.close();
    os.close();
    System.out.println(new URLClassLoader(new URL[] {new URL("jar:" + jar.toURI() + "!/")}, ClassLoader.getSystemClassLoader().getParent()).loadClass(B7050028.class.getName()));
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:27,代码来源:B7050028.java

示例9: buildUnknownFiles

import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
public void buildUnknownFiles(File appDir, File outFile, MetaInfo meta)
        throws AndrolibException {
    if (meta.unknownFiles != null) {
        LOGGER.info("Copying unknown files/dir...");

        Map<String, String> files = meta.unknownFiles;
        File tempFile = new File(outFile.getParent(), outFile.getName() + ".apktool_temp");
        boolean renamed = outFile.renameTo(tempFile);
        if(!renamed) {
            throw new AndrolibException("Unable to rename temporary file");
        }

        try {
            ZipFile inputFile = new ZipFile(tempFile);
            ZipOutputStream actualOutput = new ZipOutputStream(new FileOutputStream(outFile));
            copyExistingFiles(inputFile, actualOutput);
            copyUnknownFiles(appDir, actualOutput, files);
            actualOutput.close();
        } catch (IOException ex) {
            throw new AndrolibException(ex);
        }

        // Remove our temporary file.
        tempFile.delete();
    }
}
 
开发者ID:imkiva,项目名称:AndroidApktool,代码行数:27,代码来源:Androlib.java

示例10: createBugReport

import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
public static void createBugReport(File reportFile, Throwable exception, String userMessage, Process process,
		String logMessage, File[] attachments) throws IOException {
	ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(reportFile));
	zipOut.setComment("RapidMiner bug report - generated " + new Date());
	write("message.txt", "User message", userMessage, zipOut);
	write("_process.xml", "Process as in memory.", process.getRootOperator().getXML(false), zipOut);
	if (process.getProcessLocation() != null) {
		try {
			String contents = process.getProcessLocation().getRawXML();
			write(process.getProcessLocation().getShortName(), "Raw process file in repository.", contents, zipOut);
		} catch (Throwable t) {
			write(process.getProcessLocation().getShortName(), "Raw process file in repository.",
					"could not read: " + t, zipOut);
		}
	}
	write("_log.txt", "Log message", logMessage, zipOut);
	write("_properties.txt", "System properties, information about java version and operating system", getProperties(),
			zipOut);
	write("_exception.txt", "Exception stack trace", getStackTrace(exception), zipOut);

	for (File attachment : attachments) {
		writeFile(attachment, zipOut);
	}
	zipOut.close();
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:26,代码来源:BugReport.java

示例11: testLoadLoinc

import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
@Test
public void testLoadLoinc() throws Exception {
    ourLog.info("TEST = testLoadLoinc()");
    ByteArrayOutputStream bos1 = new ByteArrayOutputStream();
    ZipOutputStream zos1 = new ZipOutputStream(bos1);
    addEntry(zos1, "/loinc/", "loinc.csv");
    zos1.close();
    ourLog.info("ZIP file has {} bytes", bos1.toByteArray().length);

    ByteArrayOutputStream bos2 = new ByteArrayOutputStream();
    ZipOutputStream zos2 = new ZipOutputStream(bos2);
    addEntry(zos2, "/loinc/", "LOINC_2.54_MULTI-AXIAL_HIERARCHY.CSV");
    zos2.close();
    ourLog.info("ZIP file has {} bytes", bos2.toByteArray().length);

    RequestDetails details = mock(RequestDetails.class);
    when(codeSvc.findBySystem("http://loinc.org")).thenReturn(new CodeSystemEntity());
    mySvc.loadLoinc(list(bos1.toByteArray(), bos2.toByteArray()), details);

    verify(codeSvc).storeNewCodeSystemVersion( myCsvCaptor.capture(), any(RequestDetails.class));

    CodeSystemEntity ver = myCsvCaptor.getValue();
    ConceptEntity code = ver.getConcepts().iterator().next();
    assertEquals("10013-1", code.getCode());

}
 
开发者ID:nhsconnect,项目名称:careconnect-reference-implementation,代码行数:27,代码来源:TerminologyLoaderTest.java

示例12: packCourse

import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
private static void packCourse(@NotNull final VirtualFile baseDir, String locationDir, String zipName, boolean showMessage) {
  try {
    final File zipFile = new File(locationDir, zipName + ".zip");
    ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zipFile)));
    VirtualFile[] courseFiles = baseDir.getChildren();
    for (VirtualFile file : courseFiles) {
      ZipUtil.addFileOrDirRecursively(zos, null, new File(file.getPath()), file.getName(), null, null);
    }
    zos.close();
    if (showMessage) {
      ApplicationManager.getApplication().invokeLater(
        () -> Messages.showInfoMessage("Course archive was saved to " + zipFile.getPath(),
                                       "Course Archive Was Created Successfully"));

    }
  }
  catch (IOException e1) {
    LOG.error(e1);
  }
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:21,代码来源:CCCreateCourseArchive.java

示例13: toZip

import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
public static void toZip(File file) {
    try {
        File zipFile = new File(file.getParentFile(), stripExtension(file.getName()) + ".zip");

        FileOutputStream dest = new FileOutputStream(zipFile);
        CheckedOutputStream checksum = new CheckedOutputStream(dest, new Adler32());
        ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(checksum));

        byte data[] = new byte[BUFFER];
        FileInputStream fi = new FileInputStream(file);
        BufferedInputStream origin = new BufferedInputStream(fi, BUFFER);
        ZipEntry entry = new ZipEntry(file.getName());
        out.putNextEntry(entry);
        int count;
        while ((count = origin.read(data, 0, BUFFER)) != -1) {
            out.write(data, 0, count);
        }
        out.closeEntry();
        origin.close();

        out.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:iLefty,项目名称:mcClans,代码行数:26,代码来源:FileUtils.java

示例14: unzip1

import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
@Test
public void unzip1() throws Exception {

    final FileSystem fs = Jimfs.newFileSystem();

    final String expected = "Hello, world. ";

    // Write a test file.
    Files.write(fs.getPath("hello.txt"), expected.getBytes());

    // Create the zip.
    {
        final ZipOutputStream zipOutputStream = new ZipOutputStream(
            Files.newOutputStream(fs.getPath("stuff.zip")));

        zipOutputStream.finish();
        zipOutputStream.close();
    }

    // Add the test file to the zip.
    try (final FileSystem zipFileSystem = EvenMoreFiles.zipFileSystem(fs.getPath("stuff.zip"))) {

        Files.copy(fs.getPath("hello.txt"), zipFileSystem.getPath("message.txt"),
            StandardCopyOption.REPLACE_EXISTING);
    }

    // Unpack the zip!
    EvenMoreFiles.unzip(fs.getPath("stuff.zip"), fs.getPath("stuff"), Optional.empty());

    // Verify the unzipped file matches the test file
    final byte[] bytes = Files.readAllBytes(fs.getPath("stuff", "message.txt"));
    final String actual = Charset.defaultCharset().decode(ByteBuffer.wrap(bytes)).toString();

    assertEquals(expected, actual);
}
 
开发者ID:LoopPerfect,项目名称:buckaroo,代码行数:36,代码来源:EvenMoreFilesTest.java

示例15: createZipFile

import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
private void createZipFile(String targetOutZipFileName, File[] inputFiles) throws Exception{
ZipOutputStream zos=new ZipOutputStream(new FileOutputStream(targetOutZipFileName));  
for(File inputFile:inputFiles){
	zip(zos,inputFile);  				
}
zos.closeEntry();
zos.close();		
  }
 
开发者ID:bsteker,项目名称:bdf2,代码行数:9,代码来源:DesignerServiceController.java


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