Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3833)

Unified Diff: chrome/android/webapk/shell_apk/javatests/dex_optimizer/src/org/chromium/webapk/shell_apk/test/dex_optimizer/DexOptimizerServiceImpl.java

Issue 2006703004: Merge code which extracts assets from APK to file (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/webapk/shell_apk/javatests/dex_optimizer/src/org/chromium/webapk/shell_apk/test/dex_optimizer/DexOptimizerServiceImpl.java
diff --git a/chrome/android/webapk/shell_apk/javatests/dex_optimizer/src/org/chromium/webapk/shell_apk/test/dex_optimizer/DexOptimizerServiceImpl.java b/chrome/android/webapk/shell_apk/javatests/dex_optimizer/src/org/chromium/webapk/shell_apk/test/dex_optimizer/DexOptimizerServiceImpl.java
index 05718d44a7b5f382daa7617f640f99511a5f00bf..4034361d9291c945ebddab55993ad9913025a42d 100644
--- a/chrome/android/webapk/shell_apk/javatests/dex_optimizer/src/org/chromium/webapk/shell_apk/test/dex_optimizer/DexOptimizerServiceImpl.java
+++ b/chrome/android/webapk/shell_apk/javatests/dex_optimizer/src/org/chromium/webapk/shell_apk/test/dex_optimizer/DexOptimizerServiceImpl.java
@@ -13,11 +13,10 @@ import org.chromium.base.FileUtils;
import org.chromium.webapk.lib.client.DexOptimizer;
import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
+/**
+ * Service which extracts a dex file from parent APK and optimizes it.
+ */
public class DexOptimizerServiceImpl extends Service {
private static int sCounter = 0;
@@ -46,7 +45,8 @@ public class DexOptimizerServiceImpl extends Service {
++sCounter;
File dexFile = new File(getDir(DEX_DIR, Context.MODE_PRIVATE), dexName);
- if (!extractAsset(DEX_ASSET_NAME, dexFile)) {
+ if (!FileUtils.extractAsset(
+ DexOptimizerServiceImpl.this, DEX_ASSET_NAME, dexFile)) {
return null;
}
@@ -62,27 +62,6 @@ public class DexOptimizerServiceImpl extends Service {
}
return dexFile.getPath();
}
-
-
- /**
- * Extracts an asset from the app's APK to a file.
- * @param assetName Name of the asset to extract.
- * @param dest File to extract the asset to.
- * @return true on success.
- */
- public boolean extractAsset(String assetName, File dest) {
- try (InputStream inputStream = getAssets().open(assetName);
- OutputStream outputStream = new FileOutputStream(dest)) {
- byte[] buffer = new byte[16 * 1024];
- int c;
- while ((c = inputStream.read(buffer, 0, buffer.length)) != -1) {
- outputStream.write(buffer, 0, c);
- }
- } catch (IOException e) {
- return false;
- }
- return true;
- }
};
}
}

Powered by Google App Engine
This is Rietveld 408576698