Search in sources :

Example 1 with AssetDir

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;
}
Also used : CppAssetManager(org.robolectric.res.android.CppAssetManager) AssetDir(org.robolectric.res.android.AssetDir) FileNotFoundException(java.io.FileNotFoundException) String8(org.robolectric.res.android.String8) Implementation(org.robolectric.annotation.Implementation)

Example 2 with AssetDir

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;
}
Also used : CppAssetManager2(org.robolectric.res.android.CppAssetManager2) AssetDir(org.robolectric.res.android.AssetDir) FileNotFoundException(java.io.FileNotFoundException) Implementation(org.robolectric.annotation.Implementation) Nullable(android.annotation.Nullable)

Example 3 with AssetDir

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;
}
Also used : CppAssetManager2(org.robolectric.res.android.CppAssetManager2) AssetDir(org.robolectric.res.android.AssetDir) FileNotFoundException(java.io.FileNotFoundException) Implementation(org.robolectric.annotation.Implementation) Nullable(android.annotation.Nullable)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)3 Implementation (org.robolectric.annotation.Implementation)3 AssetDir (org.robolectric.res.android.AssetDir)3 Nullable (android.annotation.Nullable)2 CppAssetManager2 (org.robolectric.res.android.CppAssetManager2)2 CppAssetManager (org.robolectric.res.android.CppAssetManager)1 String8 (org.robolectric.res.android.String8)1