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 Summary
Constructors Constructor Description AssetUtil()
-
Method Summary
Modifier and Type Method Description static String
readFile(String path, String fileName)
Read the text of the given file within the assets. static JSONObject
getAnylineAssetsJson(Context context, String fileName)
Get the json object from the assets with the given file name. 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. static void
copyAssetFile(Context context, String pathInAssets, File dirToCopyTo, boolean isForceCopy)
Copy the asset file specified by path to given directory. static void
copyAssetFile(Context context, String pathInAssets, File dirToCopyTo, boolean isForceCopy, String pathPrefix)
static void
copyAllAssetFiles(Context context, Array<String> assetPaths)
static void
copyAssetFile(Context context, String pathInAssets, File dirToCopyTo, String shaHash)
Copy the asset file specified by path to given directory. static void
copyAssetFile(Context context, String pathInAssets, File dirToCopyTo, String shaHash, String pathPrefix)
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). 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). static String
getAssetPathForPlugin(ScanController.PluginType pluginType)
static void
copyDirectory(File sourceDir, File destDir)
Copy a whole directory to another location. static boolean
deleteDirectory(File directoryToBeDeleted)
Deletes a directory recursively static boolean
fileExists(String path, String fileName)
static boolean
assetExists(Context context, String path)
-
-
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 contextfileName
- 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 contextjson
- the json file containing a map with asset paths and sha sumsmapJsonName
- the name of the map within the json objectdirToCopyTo
- the dir to copy the assets toisForceCopy
- 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 contextpathInAssets
- Path to asset, relative to app's assets directory.dirToCopyTo
- the target directoryisForceCopy
- 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, boolean isForceCopy, String pathPrefix)
-
copyAllAssetFiles
static void copyAllAssetFiles(Context context, Array<String> assetPaths)
-
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 contextpathInAssets
- Path to asset, relative to app's assets directory.dirToCopyTo
- the target directoryshaHash
- the sha checksum for the file to copy
-
copyAssetFile
static void copyAssetFile(Context context, String pathInAssets, File dirToCopyTo, String shaHash, String pathPrefix)
-
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 contextpathInAssets
- Path to asset, relative to app's assets directory.dirToCopyTo
- the target directoryisForceCopy
- 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 contextpathInAssets
- Path to asset, relative to app's assets directory.dirToCopyTo
- the target directoryshaHash
- the SHA checksum for the file to copy
-
getAssetPathForPlugin
static String getAssetPathForPlugin(ScanController.PluginType pluginType)
-
copyDirectory
static void copyDirectory(File sourceDir, File destDir)
Copy a whole directory to another location.
- Parameters:
sourceDir
- a File object represents the source directorydestDir
- 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
-
fileExists
static boolean fileExists(String path, String fileName)
-
assetExists
static boolean assetExists(Context context, String path)
-
-
-
-