summaryrefslogtreecommitdiff
path: root/app/src/main/java/se/leap/bitmaskclient/base/utils
diff options
context:
space:
mode:
authorcyBerta <cyberta@riseup.net>2021-02-25 19:58:37 +0100
committercyBerta <cyberta@riseup.net>2021-02-25 20:15:09 +0100
commitb07f5effd54670f8bbf34cdd3f95735ae07e4c85 (patch)
treeb2b3daa491006928d98889a4837bc6c15ef61dba /app/src/main/java/se/leap/bitmaskclient/base/utils
parent2b1dcf4f6b4ed7405a14c5dfb50ef16dfa416fbf (diff)
ensure the private api and the preshipped certificate will be used to setup the provider in custom builds
Diffstat (limited to 'app/src/main/java/se/leap/bitmaskclient/base/utils')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/utils/InputStreamHelper.java26
1 files changed, 26 insertions, 0 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/base/utils/InputStreamHelper.java b/app/src/main/java/se/leap/bitmaskclient/base/utils/InputStreamHelper.java
index 77189dff..8a526499 100644
--- a/app/src/main/java/se/leap/bitmaskclient/base/utils/InputStreamHelper.java
+++ b/app/src/main/java/se/leap/bitmaskclient/base/utils/InputStreamHelper.java
@@ -1,7 +1,11 @@
package se.leap.bitmaskclient.base.utils;
+import org.json.JSONException;
+import org.json.JSONObject;
+
import java.io.FileInputStream;
import java.io.FileNotFoundException;
+import java.io.IOException;
import java.io.InputStream;
/**
@@ -18,4 +22,26 @@ public class InputStreamHelper {
java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A");
return s.hasNext() ? s.next() : "";
}
+
+ public static String extractKeyFromInputStream(InputStream inputStream, String key) {
+ String value = "";
+
+ JSONObject fileContents = inputStreamToJson(inputStream);
+ if (fileContents != null)
+ value = fileContents.optString(key);
+ return value;
+ }
+
+ public static JSONObject inputStreamToJson(InputStream inputStream) {
+ JSONObject json = null;
+ try {
+ byte[] bytes = new byte[inputStream.available()];
+ if (inputStream.read(bytes) > 0)
+ json = new JSONObject(new String(bytes));
+ inputStream.reset();
+ } catch (IOException | JSONException e) {
+ e.printStackTrace();
+ }
+ return json;
+ }
}