Class AssetUtil

  • All Implemented Interfaces:

    
    public class AssetUtil
    
                        

    A helper class to deal with assets, mainly to copy the assets to a place where the C++ core can reach it.

    • Constructor Detail

      • AssetUtil

        AssetUtil()
    • Method Detail

      • readFile

         static String readFile(String path, String fileName)

        Read the text of the given file within the assets.

        Parameters:
        fileName - the file name of the file to read (full path within the assets folder)
        Returns:

        the text of the file

      • getAnylineAssetsJson

         static JSONObject getAnylineAssetsJson(Context context, String fileName)

        Get the json object from the assets with the given file name.

        Parameters:
        context - the context
        fileName - the name of the json file in the assets folder to read
        Returns:

        the json object from the assets with the given file name.

      • copyAnylineAssets

         static void copyAnylineAssets(Context context, JSONObject json, String mapJsonName, File dirToCopyTo, boolean isForceCopy)

        Copy the assets of the given map listed in the given json object (must be a map with filename relative to assets as the key and the md5 sum of the file as value) to the given directory. The file will only be copied if it does not exist in the target location, or the saved md5 for that file is different to the one in the given json object, or if the isForcedCopy flag is true.

        Parameters:
        context - the context
        json - the json file containing a map with asset paths and md5 sums
        mapJsonName - the name of the map within the json object
        dirToCopyTo - the dir to copy the assets to
        isForceCopy - true if files should be copied regardless of the hashes
      • copyAssetFile

         static void copyAssetFile(Context context, String pathInAssets, File dirToCopyTo, boolean isForceCopy)

        Copy the asset file specified by path to given directory.

        Md5 sum will be calculated and stored to the target dir with .md5 ending. Calculating this takes time, prefer auto generating the anyline_assets.json or providing the md5 with copyAssetFile.

        If isForceCopy is false, this will not copy anything if the same .md5 file is in the target dir.

        Parameters:
        context - the context
        pathInAssets - Path to asset, relative to app's assets directory.
        dirToCopyTo - the target directory
        isForceCopy - if true the file will always be copied (an md5 will be calculated and checked otherwise)
      • copyAssetFile

         static void copyAssetFile(Context context, String pathInAssets, File dirToCopyTo, String md5Hash)

        Copy the asset file specified by path to given directory.

        The file will only be copied if it does not exist in the target location, or the saved md5 for that file is different to the one given. (The file will always be copied if the given hash is null)

        Parameters:
        context - the context
        pathInAssets - Path to asset, relative to app's assets directory.
        dirToCopyTo - the target directory
        md5Hash - the md5 checksum for the file to copy
      • copyAssetFileWithoutPath

         static void copyAssetFileWithoutPath(Context context, String pathInAssets, File dirToCopyTo, boolean isForceCopy)

        Copy the asset file specified by path directly to the given directory (without the relative path of the asset).

        Md5 sum will be calculated and stored to the target dir with .md5 ending. Calculating this takes time, prefer auto generating the anyline_assets.json or providing the md5 with copyAssetFileWithoutPath.

        If isForceCopy is false, this will not copy anything if the same .md5 file is in the target dir.

        Parameters:
        context - the context
        pathInAssets - Path to asset, relative to app's assets directory.
        dirToCopyTo - the target directory
        isForceCopy - if true the file will always be copied (an md5 will be calculated and checked otherwise)
      • copyAssetFileWithoutPath

         static void copyAssetFileWithoutPath(Context context, String pathInAssets, File dirToCopyTo, String md5Hash)

        Copy the asset file specified by path directly to the given directory (without the relative path of the asset).

        The file will only be copied if it does not exist in the target location, or the saved md5 for that file is different to the one given. (The file will always be copied if the given hash is null)

        Parameters:
        context - the context
        pathInAssets - Path to asset, relative to app's assets directory.
        dirToCopyTo - the target directory
        md5Hash - the md5 checksum for the file to copy
      • copyDirectory

         static void copyDirectory(File sourceDir, File destDir)

        Copy a whole directory to another location.

        Parameters:
        sourceDir - a File object represents the source directory
        destDir - a File object represents the destination directory
      • deleteDirectory

         static boolean deleteDirectory(File directoryToBeDeleted)

        Deletes a directory recursively

        Parameters:
        directoryToBeDeleted - folder to be deleted recursively
        Returns:

        success of the operation