summaryrefslogtreecommitdiffstats
path: root/updater_sample/src/com/example/android/systemupdatersample/util
diff options
context:
space:
mode:
Diffstat (limited to 'updater_sample/src/com/example/android/systemupdatersample/util')
-rw-r--r--updater_sample/src/com/example/android/systemupdatersample/util/FileDownloader.java13
-rw-r--r--updater_sample/src/com/example/android/systemupdatersample/util/UpdateConfigs.java26
2 files changed, 28 insertions, 11 deletions
diff --git a/updater_sample/src/com/example/android/systemupdatersample/util/FileDownloader.java b/updater_sample/src/com/example/android/systemupdatersample/util/FileDownloader.java
index 5c1d71117..ddd0919b8 100644
--- a/updater_sample/src/com/example/android/systemupdatersample/util/FileDownloader.java
+++ b/updater_sample/src/com/example/android/systemupdatersample/util/FileDownloader.java
@@ -38,22 +38,23 @@ public final class FileDownloader {
private String mUrl;
private long mOffset;
private long mSize;
- private File mOut;
+ private File mDestination;
- public FileDownloader(String url, long offset, long size, File out) {
+ public FileDownloader(String url, long offset, long size, File destination) {
this.mUrl = url;
this.mOffset = offset;
this.mSize = size;
- this.mOut = out;
+ this.mDestination = destination;
}
/**
* Downloads the file with given offset and size.
+ * @throws IOException when can't download the file
*/
public void download() throws IOException {
- Log.d("FileDownloader", "downloading " + mOut.getName()
+ Log.d("FileDownloader", "downloading " + mDestination.getName()
+ " from " + mUrl
- + " to " + mOut.getAbsolutePath());
+ + " to " + mDestination.getAbsolutePath());
URL url = new URL(mUrl);
URLConnection connection = url.openConnection();
@@ -61,7 +62,7 @@ public final class FileDownloader {
// download the file
try (InputStream input = connection.getInputStream()) {
- try (OutputStream output = new FileOutputStream(mOut)) {
+ try (OutputStream output = new FileOutputStream(mDestination)) {
long skipped = input.skip(mOffset);
if (skipped != mOffset) {
throw new IOException("Can't download file "
diff --git a/updater_sample/src/com/example/android/systemupdatersample/util/UpdateConfigs.java b/updater_sample/src/com/example/android/systemupdatersample/util/UpdateConfigs.java
index 71d4df8ab..5080cb6d8 100644
--- a/updater_sample/src/com/example/android/systemupdatersample/util/UpdateConfigs.java
+++ b/updater_sample/src/com/example/android/systemupdatersample/util/UpdateConfigs.java
@@ -26,14 +26,16 @@ import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
+import java.util.Optional;
/**
* Utility class for working with json update configurations.
*/
public final class UpdateConfigs {
- private static final String UPDATE_CONFIGS_ROOT = "configs/";
+ public static final String UPDATE_CONFIGS_ROOT = "configs/";
/**
* @param configs update configs
@@ -48,13 +50,12 @@ public final class UpdateConfigs {
* @return configs root directory
*/
public static String getConfigsRoot(Context context) {
- return Paths.get(context.getFilesDir().toString(),
- UPDATE_CONFIGS_ROOT).toString();
+ return Paths
+ .get(context.getFilesDir().toString(), UPDATE_CONFIGS_ROOT)
+ .toString();
}
/**
- * It parses only {@code .json} files.
- *
* @param context application context
* @return list of configs from directory {@link UpdateConfigs#getConfigsRoot}
*/
@@ -80,5 +81,20 @@ public final class UpdateConfigs {
return configs;
}
+ /**
+ * @param filename searches by given filename
+ * @param config searches in {@link UpdateConfig#getStreamingMetadata()}
+ * @return offset and size of {@code filename} in the package zip file
+ * stored as {@link UpdateConfig.PackageFile}.
+ */
+ public static Optional<UpdateConfig.PackageFile> getPropertyFile(
+ final String filename,
+ UpdateConfig config) {
+ return Arrays
+ .stream(config.getStreamingMetadata().getPropertyFiles())
+ .filter(file -> filename.equals(file.getFilename()))
+ .findFirst();
+ }
+
private UpdateConfigs() {}
}