diff --git a/src/api-impl-jni/android_content_res_AssetManager.c b/src/api-impl-jni/android_content_res_AssetManager.c index e9ef4315..ea647d62 100644 --- a/src/api-impl-jni/android_content_res_AssetManager.c +++ b/src/api-impl-jni/android_content_res_AssetManager.c @@ -80,7 +80,7 @@ JNIEXPORT jint JNICALL Java_android_content_res_AssetManager_readAssetChar(JNIEn struct Asset *asset = _PTR(_asset); ret = Asset_read(asset, &byte, 1); - return (ret == 1) ? byte : ret; + return (ret == 1) ? byte : -1; } JNIEXPORT jlong JNICALL Java_android_content_res_AssetManager_seekAsset(JNIEnv *env, jobject this, jlong _asset, jlong offset, jint whence) diff --git a/src/api-impl/android/content/res/AssetManager.java b/src/api-impl/android/content/res/AssetManager.java index a0235174..e959e630 100644 --- a/src/api-impl/android/content/res/AssetManager.java +++ b/src/api-impl/android/content/res/AssetManager.java @@ -556,10 +556,10 @@ public final class AssetManager { seekAsset(mAsset, mMarkPos, -1); } public final int read(byte[] b) throws IOException { - return readAsset(mAsset, b, 0, b.length); + return readAsset_internal(mAsset, b, 0, b.length); } public final int read(byte[] b, int off, int len) throws IOException { - return readAsset(mAsset, b, off, len); + return readAsset_internal(mAsset, b, off, len); } public final long skip(long n) throws IOException { long pos = seekAsset(mAsset, 0, 0); @@ -581,6 +581,15 @@ public final class AssetManager { private long mMarkPos; } + private int readAsset_internal(long asset, byte[] b, long offset, long length) throws IOException { + int ret = readAsset(asset, b, offset, length); + if(ret < 0) + throw new IOException(); + if(ret == 0) + ret = -1; + return ret; + } + /** * Add an additional set of assets to the asset manager. This can be * either a directory or ZIP file. Not for use by applications. Returns