Skip to content

Commit

Permalink
Use IOUtils with counting for unzipping as well
Browse files Browse the repository at this point in the history
  • Loading branch information
avram committed Oct 1, 2014
1 parent 37d79bd commit 0b92c1d
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/main/java/com/gimranov/zandy/app/AttachmentActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -663,18 +663,26 @@ protected void afterWrite(int n) throws IOException {
if ((!att.getType().equals("text/html")) || name.contains(".htm")) {
FileOutputStream fos2 = new FileOutputStream(file);
InputStream entryStream = zf.getInputStream(entry);
int counter = 0;
while ((current = entryStream.read()) != -1) {
fos2.write((byte) current);
if (counter % 2048 == 0) {
msg = mHandler.obtainMessage();
msg.arg1 = counter;
mHandler.sendMessage(msg);

final AtomicInteger counter = new AtomicInteger();

OutputStream outputStream = new CountingOutputStream(fos2) {
@Override
protected void afterWrite(int n) throws IOException {
super.afterWrite(n);
if (n > 0) {
int completed = counter.addAndGet(n);
Message message = mHandler.obtainMessage();
message.arg1 = completed;
mHandler.sendMessage(message);
}
}
counter++;
};

IOUtils.copy(entryStream, outputStream);

}
fos2.close();
entryStream.close();
Log.d(TAG, "Finished reading file");
} else {
Log.d(TAG, "Skipping file: " + name);
Expand Down Expand Up @@ -761,7 +769,6 @@ public boolean onOptionsItemSelected(MenuItem item) {
b.putString("itemKey", this.item.getKey());
b.putString("mode", "new");
removeDialog(DIALOG_NOTE);
com.crashlytics.android.internal.b = b;
showDialog(DIALOG_NOTE);
return true;
case R.id.do_prefs:
Expand Down

0 comments on commit 0b92c1d

Please sign in to comment.