summaryrefslogtreecommitdiffstats
path: root/packages/Shell
diff options
context:
space:
mode:
authorFelipe Leme <felipeal@google.com>2015-06-16 20:07:31 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2015-06-16 20:07:31 +0000
commit8234ed70cb8b009845a9b0e974e7fdfb1eefafeb (patch)
tree67e825d288580f2825c638ee3f3adead962051f2 /packages/Shell
parentde3799ca167dc424e2128dd3a041efaa806dde7c (diff)
parentfcb559021da91b13ff3b0efd86b9aba957f9712c (diff)
downloadframeworks_base-8234ed70cb8b009845a9b0e974e7fdfb1eefafeb.zip
frameworks_base-8234ed70cb8b009845a9b0e974e7fdfb1eefafeb.tar.gz
frameworks_base-8234ed70cb8b009845a9b0e974e7fdfb1eefafeb.tar.bz2
am fcb55902: Merge "Improved zipping logic so it zips chunks, instead of the whole file at once, to avoid OOM." into mnc-dev
* commit 'fcb559021da91b13ff3b0efd86b9aba957f9712c': Improved zipping logic so it zips chunks, instead of the whole file at once, to avoid OOM.
Diffstat (limited to 'packages/Shell')
-rw-r--r--packages/Shell/src/com/android/shell/BugreportReceiver.java28
1 files changed, 5 insertions, 23 deletions
diff --git a/packages/Shell/src/com/android/shell/BugreportReceiver.java b/packages/Shell/src/com/android/shell/BugreportReceiver.java
index d299d66..13747ed 100644
--- a/packages/Shell/src/com/android/shell/BugreportReceiver.java
+++ b/packages/Shell/src/com/android/shell/BugreportReceiver.java
@@ -37,6 +37,7 @@ import android.util.Log;
import android.util.Patterns;
import com.google.android.collect.Lists;
+import libcore.io.Streams;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
@@ -191,20 +192,17 @@ public class BugreportReceiver extends BroadcastReceiver {
* original in case of failure).
*/
private static File zipBugreport(File bugreportFile) {
- byte[] bytes = read(bugreportFile);
- if (bytes == null) {
- // Could not read bugreport, return original.
- return bugreportFile;
- }
String bugreportPath = bugreportFile.getAbsolutePath();
String zippedPath = bugreportPath.replace(".txt", ".zip");
Log.v(TAG, "zipping " + bugreportPath + " as " + zippedPath);
File bugreportZippedFile = new File(zippedPath);
- try (ZipOutputStream zos = new ZipOutputStream(
+ try (InputStream is = new FileInputStream(bugreportFile);
+ ZipOutputStream zos = new ZipOutputStream(
new BufferedOutputStream(new FileOutputStream(bugreportZippedFile)))) {
ZipEntry entry = new ZipEntry("bugreport.txt");
zos.putNextEntry(entry);
- zos.write(bytes);
+ int totalBytes = Streams.copy(is, zos);
+ Log.v(TAG, "size of original bugreport: " + totalBytes + " bytes");
zos.closeEntry();
// Delete old file;
boolean deleted = bugreportFile.delete();
@@ -220,22 +218,6 @@ public class BugreportReceiver extends BroadcastReceiver {
}
}
- /** Returns the content of file, or {@code null} in case of error. */
- private static byte[] read(File file) {
- try (ByteArrayOutputStream output = new ByteArrayOutputStream();
- InputStream input = new FileInputStream(file)) {
- byte[] buffer = new byte[4096];
- int read = 0;
- while ((read = input.read(buffer)) != -1) {
- output.write(buffer, 0, read);
- }
- return output.toByteArray();
- } catch (IOException e) {
- Log.e(TAG, "IOException reading " + file.getAbsolutePath(), e);
- return null;
- }
- }
-
/**
* Find the best matching {@link Account} based on build properties.
*/