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 sha 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 sha 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 sha 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.

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

        If isForceCopy is false, this will not copy anything if the same .sha 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 SHA will be calculated and checked otherwise)
      • copyAssetFile

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

        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 sha 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
        shaHash - the sha 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).

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

        If isForceCopy is false, this will not copy anything if the same .sha 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 sha will be calculated and checked otherwise)
      • copyAssetFileWithoutPath

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

        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 sha 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
        shaHash - the SHA 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