Friday, 23 August 2013

Getting images from CBZ archive

Getting images from CBZ archive

I need to get images from CBZ archives and display them in my PageViewer.
At the moment I'm unzipping the CBZ archive and placing the images on the
SD-Card which is so slow... It takes 8 seconds to unzip one image. Is
there any other way to do this? I don't need to unzip the CBZ archive, but
just get the images to display them. Any suggestions would be great to
speed this up.
Code to unzip the archive:
package nl.MarcVale.ComicViewer;
/**
* Created by Marc on 23-8-13.
*/
import android.util.Log;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
public class DecompressZip {
private String _zipFile;
private String _location;
public DecompressZip(String zipFile, String location) {
_zipFile = zipFile;
_location = location;
_dirChecker("");
}
public void unzip() {
try {
FileInputStream fin = new FileInputStream(_zipFile);
ZipInputStream zin = new ZipInputStream(fin);
ZipEntry ze = null;
while ((ze = zin.getNextEntry()) != null) {
Log.v("Decompress", "Unzipping " + ze.getName());
if(ze.isDirectory()) {
_dirChecker(ze.getName());
} else {
FileOutputStream fout = new FileOutputStream(_location +
ze.getName());
for (int c = zin.read(); c != -1; c = zin.read()) {
fout.write(c);
}
zin.closeEntry();
fout.close();
}
}
zin.close();
} catch(Exception e) {
Log.e("Decompress", "unzip", e);
}
}
private void _dirChecker(String dir) {
File f = new File(_location + dir);
if(!f.isDirectory()) {
f.mkdirs();
}
}
}

No comments:

Post a Comment