Android unpacks RAR files programmatically

Is there a way to unzip rar files in android 1.6 programmatically?

I already tried JUNRAR but got some exceptions ...

Here is my code after successfully opening the rar file using the junrar library:

FileHeader fh=null;
  while(true)
  {
   fh=rar.nextFileHeader();
   if(fh==null) return false;    
   if(fh.isEncrypted()) continue;     
   //check file

   if(!fh.isDirectory() && fh.getFileNameString().toLowerCase().endsWith(".jpg")) 
   {
    try 
    {
      File f=new File(tmppath+covername);      //name of the destination file

      OutputStream stream = new FileOutputStream(f);            
      rar.extractFile(fh, stream);         //call junrar    

      stream.close();
      return true;
     } 
     catch (FileNotFoundException e1) 
     {
        // TODO Auto-generated catch block
         return false;
     }
     catch (RarException e) 
     {
      // TODO Auto-generated catch block
         return false;
     } 
     catch (IOException e) 
     {
        // TODO Auto-generated catch block
         return false;
     }    
   }

And the DDMS perspective shows this exception ...?

ERROR/AndroidRuntime(2733): Uncaught handler: thread Thread-9 exiting due to uncaught exception

ERROR/AndroidRuntime(2733): java.lang.VerifyError: de.innosystec.unrar.unpack.ppm.SubAllocator

ERROR/AndroidRuntime(2733): at de.innosystec.unrar.unpack.ppm.ModelPPM.<init>(ModelPPM.java:73)

ERROR/AndroidRuntime(2733): at de.innosystec.unrar.unpack.Unpack.<init>(Unpack.java:43)

ERROR/AndroidRuntime(2733): at de.innosystec.unrar.Archive.doExtractFile(Archive.java:456)

ERROR/AndroidRuntime(2733): at de.innosystec.unrar.Archive.extractFile(Archive.java:440)

ERROR/AndroidRuntime(2733): at com.pmc.myRar.unrarCover(myRar.java:164)

ERROR/AndroidRuntime(2733): at com.pmc.myDataBase.addRar(myDataBase.java:541)

ERROR/AndroidRuntime(2733): at com.pmc.libraryActivity.addtoDB(libraryActivity.java:306)

ERROR/AndroidRuntime(2733): at com.pmc.libraryActivity$2.run(libraryActivity.java:240)

ERROR/AndroidRuntime(2733): at java.lang.Thread.run(Thread.java:1060)

Thank you PMK

+3
source share
3 answers

You have a java.lang.Verify error, which is quite difficult to determine. Is there any source code for this library to recompile it myself? Perhaps the library was compiled using a different version of a different jar.

As workarounds:

There is a C library here: http://www.unrarlib.org/download.html that has a link to the JNI interface

( ) - Runtime.exec() : http://forum.xda-developers.com/showthread.php?t=1015814

+4

JUNRAR, " " rar.

0

you can use src, change the function "doExtractFile" archive.java add the code dataIO.endpack (); unpack = NULL;

Example

private void doExtractFile (FileHeader hd, OutputStream os)

        throws RarException, IOException {
    dataIO.init(os);
    dataIO.init(hd);
    dataIO.setUnpFileCRC(this.isOldFormat() ? 0 : 0xffFFffFF);
    if (unpack == null) {
        unpack = new Unpack(dataIO);
    }
    if (!hd.isSolid()) {
        unpack.init(null);
    }
    unpack.setDestSize(hd.getFullUnpackSize());
    try {
        unpack.doUnpack(hd.getUnpVersion(), hd.isSolid());
        // Verify file CRC
        hd = dataIO.getSubHeader();
        long actualCRC = hd.isSplitAfter() ? ~dataIO.getPackedCRC()
                : ~dataIO.getUnpFileCRC();
        int expectedCRC = hd.getFileCRC();
        if (actualCRC != expectedCRC) {
            throw new RarException(RarExceptionType.crcError);
            // System.out.println(hd.isEncrypted());
        }

        dataIO.endpack();//add yzd
        unpack=null;// add yzd

    } catch (Exception e) {
        unpack.cleanUp();
        if (e instanceof RarException) {
            // throw new RarException((RarException)e);
            throw (RarException) e;
        } else {
            throw new RarException(e);
        }
    }
}
0
source

All Articles