AssetManager: fix up AssetInputStream

This commit is contained in:
Mis012
2024-06-13 20:37:35 +02:00
parent 2efa545e73
commit 4fd7e2cbb1
2 changed files with 12 additions and 3 deletions

View File

@@ -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)

View File

@@ -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