use of org.robolectric.res.android.AssetDir in project robolectric by robolectric.
the class ShadowArscAssetManager method list.
@Implementation
protected final String[] list(String path) throws IOException {
CppAssetManager am = assetManagerForJavaObject();
String fileName8 = path;
if (fileName8 == null) {
return null;
}
AssetDir dir = am.openDir(fileName8);
if (dir == null) {
throw new FileNotFoundException(fileName8);
}
int N = dir.getFileCount();
String[] array = new String[dir.getFileCount()];
for (int i = 0; i < N; i++) {
String8 name = dir.getFileName(i);
array[i] = name.string();
}
return array;
}
use of org.robolectric.res.android.AssetDir in project robolectric by robolectric.
the class ShadowArscAssetManager9 method nativeList.
// static jobjectArray NativeList(JNIEnv* env, jclass /*clazz*/, jlong ptr, jstring path) {
@Implementation(minSdk = P)
@Nullable
protected static String[] nativeList(long ptr, @NonNull String path) throws IOException {
String path_utf8 = path;
if (path_utf8 == null) {
// This will throw NPE.
return null;
}
CppAssetManager2 assetmanager = AssetManagerFromLong(ptr);
AssetDir asset_dir = assetmanager.OpenDir(path_utf8);
if (asset_dir == null) {
throw new FileNotFoundException(path_utf8);
}
int file_count = asset_dir.getFileCount();
// env.NewObjectArray(file_count, g_stringClass, null);
String[] array = new String[file_count];
for (int i = 0; i < file_count; i++) {
String java_string = asset_dir.getFileName(i).string();
// Check for errors creating the strings (if malformed or no memory).
// if (env.ExceptionCheck()) {
// return null;
// }
// env.SetObjectArrayElement(array, i, java_string);
array[i] = java_string;
// If we have a large amount of string in our array, we might overflow the
// local reference table of the VM.
// env.DeleteLocalRef(java_string);
}
return array;
}
use of org.robolectric.res.android.AssetDir in project robolectric by robolectric.
the class ShadowArscAssetManager10 method nativeList.
// static jobjectArray NativeList(JNIEnv* env, jclass /*clazz*/, jlong ptr, jstring path) {
@Implementation(minSdk = P)
@Nullable
protected static String[] nativeList(long ptr, @NonNull String path) throws IOException {
String path_utf8 = path;
if (path_utf8 == null) {
// This will throw NPE.
return null;
}
CppAssetManager2 assetmanager = AssetManagerFromLong(ptr);
AssetDir asset_dir = assetmanager.OpenDir(path_utf8);
if (asset_dir == null) {
throw new FileNotFoundException(path_utf8);
}
int file_count = asset_dir.getFileCount();
// env.NewObjectArray(file_count, g_stringClass, null);
String[] array = new String[file_count];
for (int i = 0; i < file_count; i++) {
String java_string = asset_dir.getFileName(i).string();
// Check for errors creating the strings (if malformed or no memory).
// if (env.ExceptionCheck()) {
// return null;
// }
// env.SetObjectArrayElement(array, i, java_string);
array[i] = java_string;
// If we have a large amount of string in our array, we might overflow the
// local reference table of the VM.
// env.DeleteLocalRef(java_string);
}
return array;
}
Aggregations