diff options
author | Samuel Holland <samuel@sholland.org> | 2017-08-13 07:23:16 -0500 |
---|---|---|
committer | Samuel Holland <samuel@sholland.org> | 2017-08-13 07:23:16 -0500 |
commit | c72d30a1af8114ef506a137e3e7274ac33d82bd1 (patch) | |
tree | 1a7c7bbb6fe36c545a3c55011e5495c7105d7142 /app/src/main/java/com | |
parent | f84d178e4693dac9231a46244dd6a346c7615157 (diff) |
Profile: Add function to copy config from another profile
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'app/src/main/java/com')
-rw-r--r-- | app/src/main/java/com/wireguard/config/Profile.java | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/app/src/main/java/com/wireguard/config/Profile.java b/app/src/main/java/com/wireguard/config/Profile.java index e04cab3e..a0388427 100644 --- a/app/src/main/java/com/wireguard/config/Profile.java +++ b/app/src/main/java/com/wireguard/config/Profile.java @@ -32,15 +32,15 @@ public class Profile extends BaseObservable implements Copyable<Profile>, Observ public Profile(String name) { super(); + if (!isNameValid(name)) + throw new IllegalArgumentException(); this.name = name; } private Profile(Profile original) throws IOException { this(original.getName()); - final byte configBytes[] = original.toString().getBytes(StandardCharsets.UTF_8); - final ByteArrayInputStream configStream = new ByteArrayInputStream(configBytes); - parseFrom(configStream); + parseFrom(original); } public Profile copy() { @@ -90,6 +90,13 @@ public class Profile extends BaseObservable implements Copyable<Profile>, Observ } } + public void parseFrom(Profile profile) + throws IOException { + final byte configBytes[] = profile.toString().getBytes(StandardCharsets.UTF_8); + final ByteArrayInputStream configStream = new ByteArrayInputStream(configBytes); + parseFrom(configStream); + } + public void setIsConnected(boolean isConnected) { this.isConnected = isConnected; notifyPropertyChanged(BR.isConnected); |