summaryrefslogtreecommitdiff
path: root/app/src/main/java/se/leap/bitmaskclient/base/utils/InputStreamHelper.java
diff options
context:
space:
mode:
authorcyberta <cyberta@riseup.net>2021-02-26 08:53:28 +0000
committercyberta <cyberta@riseup.net>2021-02-26 08:53:28 +0000
commit8bb73089566e78a195f21f4746c9db416abf95a4 (patch)
treebba73954ec2754f85060622f60d69a19f00980c3 /app/src/main/java/se/leap/bitmaskclient/base/utils/InputStreamHelper.java
parentc62389eaae3768e236875ee5fd20bde29e381c94 (diff)
parentcb1510c9f3ea27d5cffc0c0e370f8270d454e39b (diff)
Merge branch 'fix_custom_preshipping' into 'master'
ensure the private api and the preshipped certificate will be used to setup... Closes #9029 See merge request leap/bitmask_android!130
Diffstat (limited to 'app/src/main/java/se/leap/bitmaskclient/base/utils/InputStreamHelper.java')
-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;
+ }
}