diff options
author | fupduck <fupduck@riseup.net> | 2018-02-21 09:26:43 -0800 |
---|---|---|
committer | fupduck <fupduck@riseup.net> | 2018-02-21 09:26:43 -0800 |
commit | 48846a44f70be665e39abe5ce56a85f36c542544 (patch) | |
tree | 99c999adc8e64c3c3366a47c3d2f28d90f45ac15 /app/src/main/java/se/leap/bitmaskclient/ConfigHelper.java | |
parent | 420792c833f0ad6ecf55824fd8d9bb5d7eaa2aed (diff) | |
parent | 8e23cc34861f1b9fe5e04cdcf24563ffedf568b0 (diff) |
Merge branch '#8858_persist_custom_providers' into '0.9.8'
#8858 persist custom providers
See merge request leap/bitmask_android!47
Diffstat (limited to 'app/src/main/java/se/leap/bitmaskclient/ConfigHelper.java')
-rw-r--r-- | app/src/main/java/se/leap/bitmaskclient/ConfigHelper.java | 40 |
1 files changed, 11 insertions, 29 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/ConfigHelper.java b/app/src/main/java/se/leap/bitmaskclient/ConfigHelper.java index a84432e9..a21a9601 100644 --- a/app/src/main/java/se/leap/bitmaskclient/ConfigHelper.java +++ b/app/src/main/java/se/leap/bitmaskclient/ConfigHelper.java @@ -27,6 +27,8 @@ import org.spongycastle.util.encoders.Base64; import java.io.BufferedReader; import java.io.ByteArrayInputStream; +import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -47,9 +49,11 @@ import java.security.interfaces.RSAPrivateKey; import java.security.spec.InvalidKeySpecException; import java.security.spec.PKCS8EncodedKeySpec; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Set; import static android.R.attr.name; import static se.leap.bitmaskclient.Constants.PREFERENCES_APP_VERSION; @@ -125,36 +129,14 @@ public class ConfigHelper { return (X509Certificate) certificate; } + public static String loadInputStreamAsString(java.io.InputStream is) { + java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A"); + return s.hasNext() ? s.next() : ""; + } - public static String loadInputStreamAsString(InputStream inputStream) { - BufferedReader in = null; - try { - StringBuilder buf = new StringBuilder(); - in = new BufferedReader(new InputStreamReader(inputStream)); - - String str; - boolean isFirst = true; - while ( (str = in.readLine()) != null ) { - if (isFirst) - isFirst = false; - else - buf.append('\n'); - buf.append(str); - } - return buf.toString(); - } catch (IOException e) { - Log.e(TAG, "Error opening asset " + name); - } finally { - if (in != null) { - try { - in.close(); - } catch (IOException e) { - Log.e(TAG, "Error closing asset " + name); - } - } - } - - return null; + //allows us to mock FileInputStream + public static InputStream getInputStreamFrom(String filePath) throws FileNotFoundException { + return new FileInputStream(filePath); } protected static RSAPrivateKey parseRsaKeyFromString(String rsaKeyString) { |