I have a problem when I try to unzip a file with Android SDK. With a
similar code in Java SDK 6 this doesn't happen! It works well in Java.
This is the code I use to read the zip:
public void unzip() {
try {
float time = System.currentTimeMillis();
ZipInputStream zin = new ZipInputStream(new
BufferedInputStream( new FileInputStream(_zipFile)));
ZipEntry ze = zin.getNextEntry();
L.d("ze", ze.toString());
while (ze != null) {
Log.v("ze", ze.toString());
Log.v("Decompress", "Unzipping " + ze.getName());
if(ze.isDirectory()) {
_dirChecker(ze.getName());
} else {
BufferedOutputStream fout = new BufferedOutputStream(new
FileOutputStream(_location + ze.getName()));
int n;
byte b[] = new byte[8192];
L.d("Antes de leer");
//TODO: ver si es >0 o != -1
while ((n = zin.read(b,0,8192)) > 0) {
L.d("Leyendo "+n);
fout.write(b,0,n);
}
L.d("Despues de leer");
fout.close();
L.d("Despues de cerrar");
}
//zin.closeEntry();
L.d("Obteniendo siguiente entrada");
if (zin.available() > 0) {
L.d("Hay mas bytes available!");
ze = zin.getNextEntry();
L.d("Esto no lo vas a ver oprque acá se cuelga");
if (ze != null)
L.d("ze", ze.toString());
else
L.d("ze is null");
} else {
ze = null;
}
}
zin.close();
L.d("Files unzipped in "+((System.currentTimeMillis() - time)/
1000)+" seconds");
} catch(Exception e) {
Log.e("Decompress", "unzip", e);
throw new RuntimeException(e);
}
}
private void _dirChecker(String dir) {
File f = new File(_location + dir);
if(!f.isDirectory()) {
f.mkdirs();
}
}
The unzip function freezes always (no matter what is the lenght of the
file or the number of files inside the zip) in the last entry, in
zip.getNextEntry() function. This doesn't happen in Java. Is this a
bug of the Android SDK? I've tested with 2.2 and 2.3 API and I have
the same behavior.
This is the last input in adb logcat:
(...)
D/sur_comics( 281): Leyendo 2027
D/sur_comics( 281): Leyendo 535
D/sur_comics( 281): Despues de leer
D/sur_comics( 281): Despues de cerrar
D/sur_comics( 281): Obteniendo siguiente entrada
D/sur_comics( 281): Hay mas bytes available!
And after a while...
D/SntpClient( 67): request time failed: java.net.SocketException:
Address family not supported by protocol
Any help is welcome :D
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en