crazycircuit7
unread,Mar 14, 2012, 11:00:44 PM3/14/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to android-g...@googlegroups.com
こんにちは
お世話になります。
PCで作った(deflate)ZIPファイルを効率よく解凍するにはいい方法がないでしょうか?
解凍はすぐ終わるが、GCが起きて遅くなるのを解決したい。
Heapメモリが8MBを超えそうになってGCが走り待たされる状況です。
ZipFile zipFile = new ZipFile(zipPath);
ここが一番メモリを食う原因ですが new するしかないですよね?
別ライブラリを使った方がメモリを食わないでしょうか?
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipOutputStream;
// Zipファイル内のファイルを解凍する。
public static int meltZipFile(String zipPath, String innerfile,String outFile) {
try {
// outFileのフォルダが無い時は作成する。
File dir = new File(outFile);
File dirpath_only = new File(dir.getParent());
if (!dirpath_only.exists()) {
dirpath_only.mkdirs();
}
dir = null;
dirpath_only = null;
ZipFile zipFile = new ZipFile(zipPath);
ZipEntry entry = zipFile.getEntry(innerfile);
InputStream is = zipFile.getInputStream(entry);
OutputStream os = new FileOutputStream(outFile);
byte[] buffer = new byte[1024];
int r = 0;
while (-1 != (r = is.read(buffer))) {
os.write(buffer, 0, r);
}
os.close();
is.close();
zipFile.close();
//開放する。
os=null;
is = null;
entry =null;
zipFile = null;
buffer = null;
return 0;
} catch (Exception ex) {
return -1;
}
}