Android Utililty Methods Zip Entry Add

List of utility methods to do Zip Entry Add

Description

The list of methods to do Zip Entry Add are organized into topic(s).

Method

voidsaveEntry(String destPath, ZipEntry target, ZipFile zf)
save Entry
try {
    File file = new File(destPath + "/" + target.getName());
    if (target.isDirectory()) {
        file.mkdirs();
    } else {
        InputStream is = zf.getInputStream(target);
        BufferedInputStream bis = new BufferedInputStream(is);
        File dir = new File(file.getParent());
...
voidaddToArchive(String source, String target, String entryName)
add To Archive
File zip = new File(source);
File tempFile = File.createTempFile(zip.getName(), null);
tempFile.delete();
if (!zip.renameTo(tempFile)) {
    throw new RuntimeException("could not rename the file "
            + zip.getAbsolutePath() + " to "
            + tempFile.getAbsolutePath());
byte[] buffer = new byte[32 * 1024];
ZipInputStream zin = new ZipInputStream(new FileInputStream(
        tempFile));
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zip));
    ZipEntry entry = zin.getNextEntry();
    while (entry != null) {
        String name = entry.getName();
        if (!name.equals(entryName)) {
            out.putNextEntry(new ZipEntry(name));
            int bytesRead;
            while ((bytesRead = zin.read(buffer)) != -1) {
                out.write(buffer, 0, bytesRead);
        out.flush();
        out.closeEntry();
        entry = zin.getNextEntry();
    zin.close();
    InputStream in = new FileInputStream(target);
    out.putNextEntry(new ZipEntry(entryName));
    int bytesRead;
    while ((bytesRead = in.read(buffer)) != -1) {
        out.write(buffer, 0, bytesRead);
    out.flush();
    out.closeEntry();
    in.close();
out.finish();
out.close();
tempFile.delete();