Example usage for android.content.res AssetManager list

List of usage examples for android.content.res AssetManager list

Introduction

In this page you can find the example usage for android.content.res AssetManager list.

Prototype

public @Nullable String[] list(@NonNull String path) throws IOException 

Source Link

Document

Return a String array of all the assets at the given path.

Usage

From source file:Main.java

public static boolean exists(AssetManager assetManager, String source) {
    try {/*from ww w .  ja  v a2s .  co  m*/
        String[] s = assetManager.list(source);
        if (s == null || s.length == 0) {
            return false;
        }

        return true;
    } catch (IOException e) {
        return false;
    }
}

From source file:ee.ioc.phon.android.inimesed.MyFileUtils.java

public static void copyAssets(Context context, File baseDir) throws IOException {
    AssetManager assetManager = context.getAssets();
    String[] files = assetManager.list("hmm");

    for (String fromFile : files) {
        File toFile = new File(baseDir.getAbsolutePath() + "/" + fromFile);
        Log.i(LOG_TAG, "Copying: " + fromFile + " to " + toFile);
        InputStream in = assetManager.open("hmm/" + fromFile);
        FileUtils.copyInputStreamToFile(in, toFile);
    }// w  ww .j  ava  2  s.com
}

From source file:Main.java

public static boolean copyAssetsToInternalStorage(File assetFile, File storageFile, AssetManager assetManager) {
    try {//www  .j a v  a2 s.  co  m
        String[] assets = assetManager.list(assetFile.getPath());
        if (assets.length == 0) {
            //                return copyFile(assetManager.openFd(assetFile.getPath()).getFileDescriptor(), storageFile); //Fail!!!
            return copyFile(assetFile, storageFile, assetManager);
        } else {
            storageFile.mkdir();
            for (String file : assets) {
                copyAssetsToInternalStorage(new File(assetFile, file), new File(storageFile, file),
                        assetManager);
            }
        }
        return true;
    } catch (IOException ex) {
        return false;
    }
}

From source file:Main.java

private static void addFolderEntriesToManifest(ArrayList<String> manifestEntries, String path,
        AssetManager assetManager) throws IOException, NoSuchAlgorithmException {
    String[] fileList = assetManager.list(path);
    if (fileList.length > 0) {
        // This is a folder, recursively add folder entries to the manifest.
        for (String pathInFolder : fileList) {
            addFolderEntriesToManifest(manifestEntries, path + "/" + pathInFolder, assetManager);
        }//from   ww  w  . j  a v a 2s  .c  o m
    } else {
        // This is a file, compute a hash and create a manifest entry for it.
        manifestEntries.add(path + ":" + computeHash(assetManager.open(path)));
    }
}

From source file:Main.java

public static String findAsset(AssetManager mgr, String path, String stop) {
    String files[] = null;/*from w w w  .  j ava2 s .c  o m*/
    try {
        files = mgr.list(path);
    } catch (IOException e) {
        return null;
    }
    if (files != null) {
        for (String file : files) {
            String subPath = path;
            if (subPath.length() > 0) {
                subPath += "/" + file;
            } else {
                subPath += file;
            }
            if (file.indexOf(stop) != -1) {
                return subPath;
            } else {
                String resp = findAsset(mgr, subPath, stop);
                if (resp != null) {
                    return resp;
                }
            }
        }
    }
    return null;
}

From source file:Main.java

public static boolean copyAssetFolder(AssetManager assetManager, String fromAssetPath, String toPath) {
    try {/*from w  w w.  j  av  a 2 s . co  m*/
        String[] files = assetManager.list(fromAssetPath);
        new File(toPath).mkdirs();
        boolean res = true;
        for (String file : files)
            if (file.contains("."))
                res &= copyAsset(assetManager, fromAssetPath + "/" + file, toPath + "/" + file);
            else
                res &= copyAssetFolder(assetManager, fromAssetPath + "/" + file, toPath + "/" + file);
        return res;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}

From source file:Main.java

private static void copyAsset(AssetManager am, File rep, boolean force) {
    try {/*from  w w w  . j  a va  2  s.  c om*/
        String assets[] = am.list("");
        for (int i = 0; i < assets.length; i++) {
            boolean hp48 = assets[i].equals("hp48");
            boolean hp48s = assets[i].equals("hp48s");
            boolean ram = assets[i].equals("ram");
            boolean rom = assets[i].equals("rom");
            boolean rams = assets[i].equals("rams");
            boolean roms = assets[i].equals("roms");
            int required = 0;
            if (ram)
                required = 131072;
            else if (rams)
                required = 32768;
            else if (rom)
                required = 524288;
            else if (roms)
                required = 262144;
            //boolean SKUNK = assets[i].equals("SKUNK");
            if (hp48 || rom || ram || hp48s || roms || rams) {
                File fout = new File(rep, assets[i]);
                if (!fout.exists() || fout.length() == 0 || (required > 0 && fout.length() != required)
                        || force) {
                    Log.i("x48", "Overwriting " + assets[i]);
                    FileOutputStream out = new FileOutputStream(fout);
                    InputStream in = am.open(assets[i]);
                    byte buffer[] = new byte[8192];
                    int n = -1;
                    while ((n = in.read(buffer)) > -1) {
                        out.write(buffer, 0, n);
                    }
                    out.close();
                    in.close();
                }
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.slimroms.themecore.AssetUtils.java

public static boolean copyAssetFolder(AssetManager am, String assetPath, String path, Cipher cipher) {
    try {/*w  w w.j  av  a2 s . co m*/
        String[] files = am.list(assetPath);
        if (!new File(path).exists() && !new File(path).mkdirs()) {
            throw new RuntimeException("cannot create directory: " + path);
        }
        boolean res = true;
        for (String file : files) {
            if (am.list(assetPath + "/" + file).length == 0) {
                res &= copyAsset(am, assetPath + "/" + file, path + "/" + file, cipher);
            } else {
                res &= copyAssetFolder(am, assetPath + "/" + file, path + "/" + file, cipher);
            }
        }
        return res;
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    }
}

From source file:Main.java

public static boolean copyAssetFolder2(AssetManager assetManager, String fromAssetPath, String toPath) {
    try {//w  ww. ja  va2s.co m
        String[] files = assetManager.list(fromAssetPath);
        new File(toPath).mkdirs();
        boolean res = true;
        for (String file : files)
            if (file.contains("."))
                res &= copyAsset(assetManager, fromAssetPath + File.separator + file,
                        toPath + File.separator + file);
            else
                res &= copyAssetFolder2(assetManager, fromAssetPath + File.separator + file,
                        toPath + File.separator + file);
        return res;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}

From source file:Main.java

public static String[] List(AssetManager am, String uri) {
    uri = RemoveLastPathSeperator(uri);//  www .ja v a  2s  .  c  o  m
    if (IsFolder(am, uri)) {
        try {
            return am.list(uri);
        } catch (IOException e) {
            return null;
        }
    } else {
        return null;
    }
}