Skip to main content
Inspiring
September 5, 2013
Question

Native extension to unzip a file crash my air app

  • September 5, 2013
  • 0 replies
  • 845 views

Hello,

I have a problem with a native extension for android

I want to unzip a file

my java code

File f = new File("my zip file");

File outputDir = new File ("output folder");

ZipHelper.unzip(f, outputDir);

and

import java.util.zip.*;

import java.io.*;

import java.util.Enumeration;

import org.apache.commons.io.IOUtils;

import android.util.Log;


public class ZipHelper

{

static public void unzip(File archive, File outputDir)

{

try {

Log.d("control","ZipHelper.unzip() - File: " + archive.getPath());

ZipFile zipfile = new ZipFile(archive);

for (Enumeration e = zipfile.entries(); e.hasMoreElements(); ) {

ZipEntry entry = (ZipEntry) e.nextElement();

unzipEntry(zipfile, entry, outputDir);

}

}

catch (Exception e) {

Log.d("control","ZipHelper.unzip() - Error extracting file " + archive+": "+ e);

}

}


static private void unzipEntry(ZipFile zipfile, ZipEntry entry, File outputDir) throws IOException

{

if (entry.isDirectory()) {

createDirectory(new File(outputDir, entry.getName()));

return;

}


File outputFile = new File(outputDir, entry.getName());

if (!outputFile.getParentFile().exists()){

createDirectory(outputFile.getParentFile());

}


Log.d("control","ZipHelper.unzipEntry() - Extracting: " + entry);

BufferedInputStream inputStream = new BufferedInputStream(zipfile.getInputStream(entry));

BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outputFile));


try {

IOUtils.copy(inputStream, outputStream);

}

catch (Exception e) {

Log.d("control","ZipHelper.unzipEntry() - Error: " + e);

}

finally {

outputStream.close();

inputStream.close();

}

}


static private void createDirectory(File dir)

{

Log.d("control","ZipHelper.createDir() - Creating directory: "+dir.getName());

if (!dir.exists()){

if(!dir.mkdirs()) throw new RuntimeException("Can't create directory "+dir);

}

else Log.d("control","ZipHelper.createDir() - Exists directory: "+dir.getName());

}

}

i copy the file commons-io-2.4.jar (I get at http://commons.apache.org/proper/commons-io/download_io.cgi) in the lib folder of eclipse.

in a native android app, this code work fine

in a native extension for air, my air app crash

LogCat in eclipse return

NoClassDefFoundError: org.apache.comons.io.IOUtils.copy

IOUtils class is not in commons-io-2.4.jar ???

thanks

This topic has been closed for replies.