Android Utililty Methods Zip Unzip Directory

List of utility methods to do Zip Unzip Directory

Description

The list of methods to do Zip Unzip Directory are organized into topic(s).

Method

VectorunzipDirectory(File p2BeUnzippedDir, File pZipFile)
unzip Directory
if (p2BeUnzippedDir == null) {
    throw new IllegalArgumentException(
            "parameter p2BeUnzippedDir must not be null");
if (!p2BeUnzippedDir.isDirectory()) {
    throw new IllegalArgumentException(
            "parameter p2BeUnzippedDir has to be a directory");
if (pZipFile == null) {
    throw new IllegalArgumentException(
            "parameter pZipFile must not be null");
if (pZipFile.isDirectory()) {
    throw new IllegalArgumentException(
            "parameter pZipFile has to be a file and not a directory");
Vector<String> lFilenameList = new Vector<String>();
try {
    ZipFile lZipFile = new ZipFile(pZipFile);
    Enumeration<? extends ZipEntry> lEntryEnum = lZipFile.entries();
    while (lEntryEnum.hasMoreElements()) {
        ZipEntry lEntry = lEntryEnum.nextElement();
        InputStream lIS = lZipFile.getInputStream(lEntry);
        BufferedInputStream lBIS = new BufferedInputStream(lIS);
        String lFilename = p2BeUnzippedDir.getAbsolutePath() + "/"
                + lEntry.getName();
        new File(lFilename).getParentFile().mkdirs();
        FileOutputStream lFOS = new FileOutputStream(lFilename);
        BufferedOutputStream lBOS = new BufferedOutputStream(lFOS);
        FileUtil.copy(lBIS, lBOS);
        lBOS.close();
        lFilenameList.add(lFilename);
    lZipFile.close();
} catch (IOException lE) {
    LogWrapper.e(LOGTAG,
            "can not unzip file:" + pZipFile.getAbsolutePath()
                    + " to:" + p2BeUnzippedDir);
return lFilenameList;
voidzipSubFolder(ZipOutputStream out, File folder, int basePathLength)
zip Sub Folder
File[] fileList = folder.listFiles();
BufferedInputStream origin = null;
for (File file : fileList) {
    if (file.isDirectory()) {
        zipSubFolder(out, file, basePathLength);
    } else {
        byte data[] = new byte[BUFFER_SIZE];
        String unmodifiedFilePath = file.getPath();
...
voidzipSubFolder(ZipOutputStream out, File folder, int basePathLength)
zip Sub Folder
File[] fileList = folder.listFiles();
BufferedInputStream origin = null;
for (File file : fileList) {
    if (file.isDirectory()) {
        zipSubFolder(out, file, basePathLength);
    } else {
        byte data[] = new byte[BUFFER_SIZE];
        String unmodifiedFilePath = file.getPath();
...
voidzipSubFolder(ZipOutputStream out, File folder, int basePathLength)
zip Sub Folder
File[] fileList = folder.listFiles();
for (File file : fileList) {
    if (file.isDirectory()) {
        zipSubFolder(out, file, basePathLength);
    } else {
        BufferedInputStream origin;
        byte data[] = new byte[BUFFER];
        String unmodifiedFilePath = file.getPath();
...
voidzipSubFolder(ZipOutputStream out, File folder, int basePathLength)
zip Sub Folder
File[] fileList = folder.listFiles();
for (File file : fileList) {
    if (file.isDirectory()) {
        zipSubFolder(out, file, basePathLength);
    } else {
        BufferedInputStream origin;
        byte data[] = new byte[BUFFER];
        String unmodifiedFilePath = file.getPath();
...
voidzipSubFolder(ZipOutputStream out, File folder, int basePathLength)
zip Sub Folder
final int BUFFER = 2048;
File[] fileList = folder.listFiles();
BufferedInputStream origin = null;
for (File file : fileList) {
    if (file.isDirectory()) {
        zipSubFolder(out, file, basePathLength);
    } else {
        byte data[] = new byte[BUFFER];
...
voidzipSubFolder(final ZipOutputStream out, final File folder, final int basePathLength)
zip Sub Folder
final int BUFFER = 2048;
final File[] fileList = folder.listFiles();
BufferedInputStream origin = null;
for (final File file : fileList) {
    if (file.isDirectory()) {
        zipSubFolder(out, file, basePathLength);
    } else {
        final byte data[] = new byte[BUFFER];
...
booleanzipFileAtPath(String[] sourcePaths, String toLocation)
zip File At Path
try {
    BufferedInputStream origin = null;
    FileOutputStream dest = new FileOutputStream(toLocation);
    ZipOutputStream out = new ZipOutputStream(
            new BufferedOutputStream(dest));
    for (String sourcePath : sourcePaths) {
        File sourceFile = new File(sourcePath);
        if (sourceFile.isDirectory()) {
...
booleanzipFileAtPath(String[] sourcePaths, String toLocation)
zip File At Path
try {
    BufferedInputStream origin = null;
    FileOutputStream dest = new FileOutputStream(toLocation);
    ZipOutputStream out = new ZipOutputStream(
            new BufferedOutputStream(dest));
    for (String sourcePath : sourcePaths) {
        File sourceFile = new File(sourcePath);
        if (sourceFile.isDirectory()) {
...
booleanzipFileAtPath(final String sourcePath, final String toLocation)
Zips a file at a location and places the resulting zip file at the toLocation Example: zipFileAtPath("downloads/myfolder", "downloads/myFolder.zip");
final int BUFFER = 2048;
final File sourceFile = new File(sourcePath);
try {
    BufferedInputStream origin = null;
    final FileOutputStream dest = new FileOutputStream(toLocation);
    final ZipOutputStream out = new ZipOutputStream(
            new BufferedOutputStream(dest));
    if (sourceFile.isDirectory()) {
...