Profile: Add function to copy config from another profile

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Samuel Holland 2017-08-13 07:23:16 -05:00
parent f84d178e46
commit c72d30a1af

View File

@ -32,15 +32,15 @@ public class Profile extends BaseObservable implements Copyable<Profile>, Observ
public Profile(String name) { public Profile(String name) {
super(); super();
if (!isNameValid(name))
throw new IllegalArgumentException();
this.name = name; this.name = name;
} }
private Profile(Profile original) private Profile(Profile original)
throws IOException { throws IOException {
this(original.getName()); this(original.getName());
final byte configBytes[] = original.toString().getBytes(StandardCharsets.UTF_8); parseFrom(original);
final ByteArrayInputStream configStream = new ByteArrayInputStream(configBytes);
parseFrom(configStream);
} }
public Profile copy() { 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) { public void setIsConnected(boolean isConnected) {
this.isConnected = isConnected; this.isConnected = isConnected;
notifyPropertyChanged(BR.isConnected); notifyPropertyChanged(BR.isConnected);