Code example for ZipOutputStream

Methods: close, closeEntry, putNextEntry

0
     * @param zipFilePath The file name with path. 
     * @param suffix The file suffix. 
     */ 
    private void createPartialTestPackageZip(String zipFilePath, String suffix)
                 throws IOException { 
        ZipOutputStream out = new ZipOutputStream(new FileOutputStream(
                zipFilePath));
 
        String packageName = zipFilePath.substring(zipFilePath
                .lastIndexOf(File.separator), zipFilePath.lastIndexOf("."));
        String file = packageName + suffix;
 
        addFileToZip(file, out);
 
        out.close();
    } 
 
    /** 
     * Add file to zip output stream. 
     * 
     * @param filename The file to be added to the zip output stream. 
     * @param out The zip output stream. 
     */ 
    private void addFileToZip(String filename, ZipOutputStream out)
            throws IOException { 
        out.putNextEntry(new ZipEntry(filename));
 
        out.closeEntry();
    } 
 
    /** 
     * Test listing package contents with different levels of expectation. 
     */