Package com.castlabs.android.downloader
Class ContainerUtils
java.lang.Object
com.castlabs.android.downloader.ContainerUtils
Helper class that provides utilities to handle zip containers that contain DASH content. The
zip always needs to contain a file named
meta.json
. That file is a json
file that must at least have an entry "manifest"
that points to the Manifest of the
content within the zip file-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Uri
getManifestUrl
(File zipFile) Reads the zip filesmeta.json
file and returns aUri
to that Manifest.static Uri
getManifestUrl
(File zipFile, JSONObject metadata) Takes the zip filesmeta.json
content and returns aUri
to that Manifest.static JSONObject
readMetaData
(File zipSource) Take a zip file and looks for a "meta.json" entry.splitEntryPath
(Uri uri) Takes a zip file URI of the formzip:/path/to/file.zip/entry/path.txt
and returns a pair where the first element is the path to the zip file and the second entry is the path to the entry.
-
Constructor Details
-
ContainerUtils
public ContainerUtils()
-
-
Method Details
-
readMetaData
@Nullable public static JSONObject readMetaData(@NonNull File zipSource) throws IOException, JSONException Take a zip file and looks for a "meta.json" entry.- Parameters:
zipSource
- The- Returns:
- The parsed entry or null if no such entry exists
- Throws:
IOException
- In case an error occurs while reading the entryJSONException
- In case an error occurs while parsing the entry
-
getManifestUrl
Reads the zip filesmeta.json
file and returns aUri
to that Manifest. The uri constructed here can be passed to thePlayerController
to open the content in the zip.- Parameters:
zipFile
- The zip file- Returns:
- The Uri to the Manifest in the ZIP
- Throws:
IOException
- In case an error occurred while reading data or no meta-data was found or the meta entries are not validJSONException
- In case an error occurred while parsing the meta-data
-
getManifestUrl
public static Uri getManifestUrl(@NonNull File zipFile, @NonNull JSONObject metadata) throws IOException, JSONException Takes the zip filesmeta.json
content and returns aUri
to that Manifest. The uri constructed here can be passed to thePlayerController
to open the content in the zip.- Parameters:
zipFile
- The zip filemetadata
- The ZIP meta-data- Returns:
- The Uri to the Manifest in the ZIP
- Throws:
IOException
- In case an error occurred while reading data or no meta-data was found or the meta entries are not validJSONException
- In case an error occurred while parsing the meta-data
-
splitEntryPath
Takes a zip file URI of the formzip:/path/to/file.zip/entry/path.txt
and returns a pair where the first element is the path to the zip file and the second entry is the path to the entry. In the example above, this method returns/path/to/file.zip, entry/path.txt
. The method returns null if no zip file could be found. The method checks for the existence of the zip file but not the existence of the entry within the zip.- Parameters:
uri
- The URI- Returns:
- Pair of zip and entry path or null
-