performance - Android bulk file output from ZIP file -
i download pretty big zip file online, , want extract application's storage. takes decent amount of time right now, , wondering if there suggestions on how speed up. know sqlite database can mass insert calling begintransaction() , wondering if there similar actual file output. here's i've got far:
zipinputstream zis = new zipinputstream(new bufferedinputstream(is)); bufferedinputstream in = new bufferedinputstream(zis); bufferedoutputstream bos; byte buffer[] = new byte[8 * 1024]; int n; seek { 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 + " saved internal storage."); zis.closeentry(); bos.close(); } } } { in.close(); zis.close(); }
you read , write info byte byte. seek read , write more info @ time, using buffer instead. byte byte big file may much phone ssd, lot of little size writes challenging these devices.
byte buffer [] = new byte[2048]; int n; while ( (n = in.read(buffer) > 0) { fos.write(buffer, 0, n); } android performance zip fileoutputstream
No comments:
Post a Comment