aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/app/src/main/java/com/wireguard/config
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-04-28 18:35:12 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2018-04-28 21:55:42 +0200
commitf07ab636f68c42ad6fcd0aaf748d2c3dfff2f7dc (patch)
tree3acea9bf30819b58a0f48af93e2b0b5d33aba4ec /app/src/main/java/com/wireguard/config
parentconfig: Minor cleanup (diff)
downloadwireguard-android-f07ab636f68c42ad6fcd0aaf748d2c3dfff2f7dc.tar.xz
wireguard-android-f07ab636f68c42ad6fcd0aaf748d2c3dfff2f7dc.zip
Allow importing from zip file
Diffstat (limited to 'app/src/main/java/com/wireguard/config')
-rw-r--r--app/src/main/java/com/wireguard/config/Config.java54
1 files changed, 27 insertions, 27 deletions
diff --git a/app/src/main/java/com/wireguard/config/Config.java b/app/src/main/java/com/wireguard/config/Config.java
index e4731a0c..b38d2a13 100644
--- a/app/src/main/java/com/wireguard/config/Config.java
+++ b/app/src/main/java/com/wireguard/config/Config.java
@@ -97,36 +97,36 @@ public class Config implements Parcelable {
in.readTypedList(peers, Peer.CREATOR);
}
- public static Config from(final InputStream stream)
- throws IOException {
+ public static Config from(final InputStream stream) throws IOException {
+ return from(new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8)));
+ }
+
+ public static Config from(final BufferedReader reader) throws IOException {
final Config config = new Config();
- try (BufferedReader reader = new BufferedReader(
- new InputStreamReader(stream, StandardCharsets.UTF_8))) {
- Peer currentPeer = null;
- String line;
- boolean inInterfaceSection = false;
- while ((line = reader.readLine()) != null) {
- if (line.isEmpty() || line.startsWith("#"))
- continue;
- if ("[Interface]".equals(line)) {
- currentPeer = null;
- inInterfaceSection = true;
- } else if ("[Peer]".equals(line)) {
- currentPeer = new Peer();
- config.peers.add(currentPeer);
- inInterfaceSection = false;
- } else if (inInterfaceSection) {
- config.interfaceSection.parse(line);
- } else if (currentPeer != null) {
- currentPeer.parse(line);
- } else {
- throw new IllegalArgumentException("Invalid configuration line: " + line);
- }
- }
- if (!inInterfaceSection && currentPeer == null) {
- throw new IllegalArgumentException("Could not find any config information");
+ Peer currentPeer = null;
+ String line;
+ boolean inInterfaceSection = false;
+ while ((line = reader.readLine()) != null) {
+ if (line.isEmpty() || line.startsWith("#"))
+ continue;
+ if ("[Interface]".equals(line)) {
+ currentPeer = null;
+ inInterfaceSection = true;
+ } else if ("[Peer]".equals(line)) {
+ currentPeer = new Peer();
+ config.peers.add(currentPeer);
+ inInterfaceSection = false;
+ } else if (inInterfaceSection) {
+ config.interfaceSection.parse(line);
+ } else if (currentPeer != null) {
+ currentPeer.parse(line);
+ } else {
+ throw new IllegalArgumentException("Invalid configuration line: " + line);
}
}
+ if (!inInterfaceSection && currentPeer == null) {
+ throw new IllegalArgumentException("Could not find any config information");
+ }
return config;
}