Index: base/android/java/src/org/chromium/base/FileUtils.java |
diff --git a/base/android/java/src/org/chromium/base/FileUtils.java b/base/android/java/src/org/chromium/base/FileUtils.java |
index fbaec8c69e31044084a0a14920a38f0ca3b391a8..2c0d8f59fac9ae329a3a803d7ce66f7361a3f07d 100644 |
--- a/base/android/java/src/org/chromium/base/FileUtils.java |
+++ b/base/android/java/src/org/chromium/base/FileUtils.java |
@@ -4,7 +4,14 @@ |
package org.chromium.base; |
+import android.content.Context; |
+ |
+import java.io.BufferedOutputStream; |
import java.io.File; |
+import java.io.FileOutputStream; |
+import java.io.IOException; |
+import java.io.InputStream; |
+import java.io.OutputStream; |
/** |
* Helper methods for dealing with Files. |
@@ -28,4 +35,42 @@ public class FileUtils { |
if (!currentFile.delete()) Log.e(TAG, "Failed to delete: " + currentFile); |
} |
+ |
+ /** |
+ * Extracts an asset from the app's APK to a file. |
+ * @param context |
+ * @param assetName Name of the asset to extract. |
+ * @param dest File to extract the asset to. |
+ * @return true on success. |
+ */ |
+ public static boolean extractAsset(Context context, String assetName, File dest) { |
+ InputStream inputStream = null; |
+ OutputStream outputStream = null; |
+ try { |
+ inputStream = context.getAssets().open(assetName); |
+ outputStream = new BufferedOutputStream(new FileOutputStream(dest)); |
+ byte[] buffer = new byte[8192]; |
+ int c; |
+ while ((c = inputStream.read(buffer)) != -1) { |
+ outputStream.write(buffer, 0, c); |
+ } |
+ inputStream.close(); |
+ outputStream.close(); |
+ return true; |
+ } catch (IOException e) { |
+ if (inputStream != null) { |
+ try { |
+ inputStream.close(); |
+ } catch (IOException ex) { |
+ } |
+ } |
+ if (outputStream != null) { |
+ try { |
+ outputStream.close(); |
+ } catch (IOException ex) { |
+ } |
+ } |
+ } |
+ return false; |
+ } |
} |