Q:

Zip extraction fails

I need to decompress a zip file from my assets folder to the SD card, in order to complete the installation.
As the zip is about 10MB big, I put it as a mp3 file in the assets folder and then copy the archive to the SD card (the md5 sums are the same).
Then there is the problem of extracting it: I tried every single decompression method on stackoverflow for zip files, but none of them works.
The one I am using works partly - sometimes it extracts all the files, but most of the time it crashes in the middle (giving me an extremely long debug output).
I attached the code and parts of the output.
Can anyone help? And it doesn't have to be a zip file, any other archive format like tar is fine as well. /edit: I run this code in a service, might this be a problem?
Code for extracting:
private final static int CHUNK_SIZE = 32 * 1024;

public static void unzipFile( String zipFile, String directory) 
    throws IOException
{ 
    byte[] _fileIOBuffer = new byte[CHUNK_SIZE];
    ZipInputStream in = null; 
    FileOutputStream os = null; 
    try 
    {
        in = new ZipInputStream (new FileInputStream(new File(zipFile))); 
        ZipEntry entry = null; 
        while ((entry = in.getNextEntry ())!= null) 
        { 
            String entryName = entry.getName();                 
            if (entry.isDirectory ()) { 
                File file = new File (directory, entryName); 
                file.mkdirs(); 
            } 
            else { 
                File file = new File(directory, entryName);
                if (file.exists()){
                    file.delete();  // I don't know how to append, so delete it always
                }
                os = new FileOutputStream (file); 

                int bytesRead = 0; 
                while ((bytesRead = in.read (_fileIOBuffer))!= -1) {
                    os.write(_fileIOBuffer, 0, bytesRead);
                    // progress procedure
                }
                os.close();
            }
        }
    }
    catch (FileNotFoundException e) {        
        Log.v("unzip", e.getMessage());
    } 
    catch (IOException e) {
        Log.v("unzip", e.getMessage());
    } 
    finally{
        if (in != null ){
            in.close();
        }
        if (os != null ){
            os.close();
        }
    }
}

Some log output:
W/dalvikvm(23094): "Binder Thread #1" prio=5 tid=5 NATIVE
W/dalvikvm(23094):   | group="main" sCount=1 dsCount=0 s=N obj=0x46e7a300 self=0x12aba8
W/dalvikvm(23094):   | sysTid=23098 nice=0 sched=3/0 cgrp=unknown handle=1369000
W/dalvikvm(23094):   | schedstat=( 806168347 48580865164 5171 )
W/dalvikvm(23094):   at dalvik.system.NativeStart.run(Native Method)
W/dalvikvm(23094): 
W/dalvikvm(23094): "Compiler" daemon prio=5 tid=4 VMWAIT
W/dalvikvm(23094):   | group="system" sCount=1 dsCount=0 s=N obj=0x46e732a0 self=0x125638
W/dalvikvm(23094):   | sysTid=23097 nice=0 sched=3/0 cgrp=unknown handle=1225832
W/dalvikvm(23094):   | schedstat=( 864668103 47259131847 4450 )
W/dalvikvm(23094):   at dalvik.system.NativeStart.run(Native Method)
W/dalvikvm(23094): 
W/dalvikvm(23094): "Signal Catcher" daemon prio=5 tid=3 RUNNABLE
W/dalvikvm(23094):   | group="system" sCount=0 dsCount=0 s=N obj=0x46e731e8 self=0x12b278
W/dalvikvm(23094):   | sysTid=23096 nice=0 sched=3/0 cgrp=unknown handle=1308736
W/dalvikvm(23094):   | schedstat=( 113256650 45104360665 3544 )
W/dalvikvm(23094):   at dalvik.system.NativeStart.run(Native Method)
W/dalvikvm(23094): 
W/dalvikvm(23094): "HeapWorker" daemon prio=5 tid=2 VMWAIT
W/dalvikvm(23094):   | group="system" sCount=1 dsCount=0 s=N obj=0x448f6f78 self=0x149d40
W/dalvikvm(23094):   | sysTid=23095 nice=0 sched=3/0 cgrp=unknown handle=1304104
W/dalvikvm(23094):   | schedstat=( 1423918773 45794713359 3888 )
W/dalvikvm(23094):   at dalvik.system.NativeStart.run(Native Method)
W/dalvikvm(23094): 
W/dalvikvm(28514): 
W/dalvikvm(28514): 
W/dalvikvm(28514): ----- pid 28514 at 2011-12-10 17:08:17 -----
W/dalvikvm(28514): Cmd line: com.google.android.apps.maps:NetworkLocationService
W/dalvikvm(28514): 
W/dalvikvm(28514): DALVIK THREADS:
W/dalvikvm(28514): "main" prio=5 tid=1 WAIT
W/dalvikvm(28514):   | group="main" sCount=1 dsCount=0 s=N obj=0x4001d938 self=0xcd98
W/dalvikvm(28514):   | sysTid=28514 nice=0 sched=3/0 cgrp=unknown handle=-1345017808
W/dalvikvm(28514):   | schedstat=( 1203913753 1177626459 364 )
W/dalvikvm(28514):   at java.lang.Object.wait(Native Method)
W/dalvikvm(28514):   - waiting on <0x46faf6c8> (a android.os.MessageQueue)
W/dalvikvm(28514):   at java.lang.Object.wait(Object.java:288)
W/dalvikvm(28514):   at android.os.MessageQueue.next(MessageQueue.java:146)
W/dalvikvm(28514):   at android.os.Looper.loop(Looper.java:110)
W/dalvikvm(28514):   at android.app.ActivityThread.main(ActivityThread.java:4627)
W/dalvikvm(28514):   at java.lang.reflect.Method.invokeNative(Native Method)
W/dalvikvm(28514):   at java.lang.reflect.Method.invoke(Method.java:521)
W/dalvikvm(28514):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
W/dalvikvm(28514):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
W/dalvikvm(28514):   at dalvik.system.NativeStart.main(Native Method)
W/dalvikvm(28514): 
W/dalvikvm(28514): "RefQueueWorker@org.apache.http.impl.conn.tsccm.ConnPoolByRoute@47054bc0" daemon prio=5 tid=16 WAIT
W/dalvikvm(28514):   | group="main" sCount=1 dsCount=0 s=N obj=0x47036980 self=0x242a70
W/dalvikvm(28514):   | sysTid=28535 nice=0 sched=3/0 cgrp=unknown handle=1227616
W/dalvikvm(28514):   | schedstat=( 206874 20758542 2 )
W/dalvikvm(28514):   at java.lang.Object.wait(Native Method)
W/dalvikvm(28514):   - waiting on <0x46fd3838> (a java.lang.ref.ReferenceQueue)
W/dalvikvm(28514):   at java.lang.Object.wait(Object.java:326)
W/dalvikvm(28514):   at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:107)
W/dalvikvm(28514):   at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:80)
W/dalvikvm(28514):   at org.apache.http.impl.conn.tsccm.RefQueueWorker.run(RefQueueWorker.java:102)
W/dalvikvm(28514):   at java.lang.Thread.run(Thread.java:1096)
W/dalvikvm(28514): 
W/dalvikvm(28514): "NetworkLocationCallbackRunner" prio=5 tid=15 WAIT
W/dalvikvm(28514):   | group="main" sCount=1 dsCount=0 s=N obj=0x470429d8 self=0x13c4c8
W/dalvikvm(28514):   | sysTid=28534 nice=-4 sched=3/0 cgrp=unknown handle=1248160
W/dalvikvm(28514):   | schedstat=( 568270822 541402506 640 )
W/dalvikvm(28514):   at java.lang.Object.wait(Native Method)
W/dalvikvm(28514):   - waiting on <0x47112b88> (a android.os.MessageQueue)
W/dalvikvm(28514):   at java.lang.Object.wait(Object.java:288)
W/dalvikvm(28514):   at android.os.MessageQueue.next(MessageQueue.java:146)
W/dalvikvm(28514):   at android.os.Looper.loop(Looper.java:110)
W/dalvikvm(28514):   at com.google.android.location.os.real.i.run((null):-1)
W/dalvikvm(28514):   at java.lang.Thread.run(Thread.java:1096)
W/dalvikvm(28514): 
W/dalvikvm(28514): "Thread-16" daemon prio=1 tid=14 WAIT
W/dalvikvm(28514):   | group="main" sCount=1 dsCount=0 s=N obj=0x470706a0 self=0x243c38
W/dalvikvm(28514):   | sysTid=28533 nice=19 sched=3/0 cgrp=unknown handle=2374056
W/dalvikvm(28514):   | schedstat=( 343958 16096459 3 )
W/dalvikvm(28514):   at java.lang.Object.wait(Native Method)
W/dalvikvm(28514):   - waiting on <0x470709c8> (a java.lang.VMThread)
W/dalvikvm(28514):   at java.lang.Thread.parkFor(Thread.java:1535)
W/dalvikvm(28514):   at java.lang.LangAccessImpl.parkFor(LangAccessImpl.java:48)
W/dalvikvm(28514):   at sun.misc.Unsafe.park(Unsafe.java:317)
W/dalvikvm(28514):   at java.util.concurrent.locks.LockSupport.park(LockSupport.java:131)
W/dalvikvm(28514):   at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:1996)
W/dalvikvm(28514):   at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:359)
W/dalvikvm(28514):   at b.a.run((null):-1)

A:

in.read(byte[]) in not defined on ZipInputStream but rather on parent class FilterInputStream. I assume it messes the ZipInputStream's entry boundaries.
Instead try using in.read(_fileIOBuffer, 0, _fileIOBuffer.length). 

