diff options
author | cyberta <cyberta@riseup.net> | 2024-01-25 23:41:42 +0000 |
---|---|---|
committer | cyberta <cyberta@riseup.net> | 2024-01-25 23:41:42 +0000 |
commit | 5bf3f807a4804c18b7dc88e07e4e34ecf0791713 (patch) | |
tree | a092fd4ab72d1a31daa3cc442331cbb05d034ef0 /app/src/main/java/se/leap/bitmaskclient/base/utils/InputStreamHelper.java | |
parent | ce8106f60d83ee2a788f1920437a0bbd48d6b15f (diff) | |
parent | e84289ab4380ae61cc9f2a86da9a16d1aae45cbd (diff) |
Merge branch 'post_release_work' into 'master'
post release tweaks and fixes
Closes #9150 and #8983
See merge request leap/bitmask_android!264
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.java | 24 |
1 files changed, 23 insertions, 1 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 8e6273a7..6dfe0861 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 @@ -8,14 +8,36 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; +import de.blinkt.openvpn.core.NativeUtils; + /** * Created by cyberta on 18.03.18. */ public class InputStreamHelper { + public interface InputStreamHelperInterface { + InputStream getInputStreamFrom(String filePath) throws FileNotFoundException; + + } + + private static InputStreamHelperInterface instance = new DefaultInputStreamHelper(); + + private static class DefaultInputStreamHelper implements InputStreamHelperInterface { + @Override + public InputStream getInputStreamFrom(String filePath) throws FileNotFoundException { + return new FileInputStream(filePath); + } + } + + public InputStreamHelper(InputStreamHelperInterface helperInterface) { + if (!NativeUtils.isUnitTest()) { + throw new IllegalStateException("InputStreamHelper injected with InputStreamHelperInterface outside of an unit test"); + } + instance = helperInterface; + } //allows us to mock FileInputStream public static InputStream getInputStreamFrom(String filePath) throws FileNotFoundException { - return new FileInputStream(filePath); + return instance.getInputStreamFrom(filePath); } public static String loadInputStreamAsString(InputStream is) { |