OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.base; | 5 package org.chromium.base; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.content.res.AssetFileDescriptor; | 8 import android.content.res.AssetFileDescriptor; |
9 import android.content.res.AssetManager; | 9 import android.content.res.AssetManager; |
10 import android.util.Log; | 10 import android.util.Log; |
(...skipping 15 matching lines...) Expand all Loading... |
26 @CalledByNative | 26 @CalledByNative |
27 public static long[] open(Context context, String fileName) { | 27 public static long[] open(Context context, String fileName) { |
28 AssetFileDescriptor afd = null; | 28 AssetFileDescriptor afd = null; |
29 try { | 29 try { |
30 AssetManager manager = context.getAssets(); | 30 AssetManager manager = context.getAssets(); |
31 afd = manager.openNonAssetFd(fileName); | 31 afd = manager.openNonAssetFd(fileName); |
32 return new long[] { afd.getParcelFileDescriptor().detachFd(), | 32 return new long[] { afd.getParcelFileDescriptor().detachFd(), |
33 afd.getStartOffset(), | 33 afd.getStartOffset(), |
34 afd.getLength() }; | 34 afd.getLength() }; |
35 } catch (IOException e) { | 35 } catch (IOException e) { |
| 36 // TODO(michaelbai): Remove dump assets once crbug.com/547235 fixed. |
| 37 try { |
| 38 String[] assets = context.getAssets().list(""); |
| 39 StringBuffer sb = new StringBuffer("Dump assets(" + assets.lengt
h + "):\n"); |
| 40 for (String asset : assets) { |
| 41 sb.append(asset); |
| 42 sb.append("\n"); |
| 43 } |
| 44 Log.e(LOGTAG, sb.toString()); |
| 45 } catch (IOException ioe) { |
| 46 Log.e(LOGTAG, "Error while list assets: " + ioe); |
| 47 } |
| 48 |
36 Log.e(LOGTAG, "Error while loading asset " + fileName + ": " + e); | 49 Log.e(LOGTAG, "Error while loading asset " + fileName + ": " + e); |
37 return new long[] {-1, -1, -1}; | 50 return new long[] {-1, -1, -1}; |
38 } finally { | 51 } finally { |
39 try { | 52 try { |
40 if (afd != null) { | 53 if (afd != null) { |
41 afd.close(); | 54 afd.close(); |
42 } | 55 } |
43 } catch (IOException e2) { | 56 } catch (IOException e2) { |
44 Log.e(LOGTAG, "Unable to close AssetFileDescriptor", e2); | 57 Log.e(LOGTAG, "Unable to close AssetFileDescriptor", e2); |
45 } | 58 } |
46 } | 59 } |
47 } | 60 } |
48 } | 61 } |
OLD | NEW |