オンラインからかなり大きな zip ファイルをダウンロードし、アプリケーションのストレージに展開したいと考えています。現在、これにはかなりの時間がかかります。速度を上げる方法について提案があるかどうか疑問に思っていました。SQLite データベースの場合、beginTransaction() を呼び出すことで一括挿入を実行できることを知っており、実際のファイル出力に同様のものがあるかどうか疑問に思っていました。ここに私がこれまでに持っているものがあります:
ZipInputStream zis = new ZipInputStream(new BufferedInputStream(is));
BufferedInputStream in = new BufferedInputStream(zis);
BufferedOutputStream bos;
byte buffer[] = new byte[8 * 1024];
int n;
try {
ZipEntry ze = null;
while ((ze = zis.getNextEntry()) != null)
{
String name = ze.getName();
if (!ze.isDirectory() && !name.contains("MACOSX"))
{
name = prefix + ze.getName();
name = name.replace('/', '_');
bos = new BufferedOutputStream(mContext.openFileOutput(name, Context.MODE_PRIVATE));
while ((n = in.read(buffer)) > 0)
bos.write(buffer, 0, n);
Log.i("Update", name + " is saved to internal storage.");
zis.closeEntry();
bos.close();
}
}
} finally {
in.close();
zis.close();
}