Chromium Code Reviews| Index: android_webview/java/src/org/chromium/android_webview/AwAssets.java |
| diff --git a/android_webview/java/src/org/chromium/android_webview/AwAssets.java b/android_webview/java/src/org/chromium/android_webview/AwAssets.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9859555aa0abd5bd4966dcd146fc2b60767d0a75 |
| --- /dev/null |
| +++ b/android_webview/java/src/org/chromium/android_webview/AwAssets.java |
| @@ -0,0 +1,38 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package org.chromium.android_webview; |
| + |
| +import android.content.Context; |
| +import android.content.res.AssetFileDescriptor; |
| +import android.content.res.AssetManager; |
| +import android.util.Log; |
| + |
| +import org.chromium.base.CalledByNative; |
| +import org.chromium.base.JNINamespace; |
| + |
| +import java.io.IOException; |
| + |
| +/** |
| + * A utility class to retrieve references to uncompressed assets insides the apk. A reference is |
| + * defined as tuple (file descriptor, offset, size) enabling direct mapping without deflation. |
| + */ |
| +@JNINamespace("android_webview") |
| +public class AwAssets { |
| + private static final String LOGTAG = "AwAssets"; |
| + |
| + @CalledByNative |
| + public static long[] OpenAsset(Context context, String fileName) { |
|
mkosiba (inactive)
2014/07/18 05:49:05
nit: openAsset (lower case 'o')
Primiano Tucci (use gerrit)
2014/07/18 17:03:30
Done.
|
| + try { |
| + AssetManager manager = context.getApplicationContext().getResources().getAssets(); |
|
mkosiba (inactive)
2014/07/18 05:49:05
why not just context.getAssets() ?
Primiano Tucci (use gerrit)
2014/07/18 17:03:30
Done.
|
| + AssetFileDescriptor afd = manager.openFd(fileName); |
| + return new long[] { afd.getParcelFileDescriptor().detachFd(), |
| + afd.getStartOffset(), |
| + afd.getLength() }; |
| + } catch (IOException e) { |
| + Log.e(LOGTAG, "Error while loading asset " + fileName + ": " + e.getMessage()); |
| + return new long[] {-1, -1, -1}; |
| + } |
| + } |
| +} |