TunnelManager: convert to kotlin

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jason A. Donenfeld
2020-03-26 23:21:54 -06:00
parent b2bbaf050c
commit 37949ba1ec
6 changed files with 252 additions and 317 deletions
@@ -24,8 +24,9 @@ class FileConfigStore(private val context: Context) : ConfigStore {
override fun create(name: String, config: Config): Config {
Log.d(TAG, "Creating configuration for tunnel $name")
val file = fileFor(name)
if (!file.createNewFile()) throw IOException(context.getString(R.string.config_file_exists_error, file.name))
FileOutputStream(file, false).use { stream -> stream.write(config.toWgQuickString().toByteArray(StandardCharsets.UTF_8)) }
if (!file.createNewFile())
throw IOException(context.getString(R.string.config_file_exists_error, file.name))
FileOutputStream(file, false).use { it.write(config.toWgQuickString().toByteArray(StandardCharsets.UTF_8)) }
return config
}
@@ -33,7 +34,8 @@ class FileConfigStore(private val context: Context) : ConfigStore {
override fun delete(name: String) {
Log.d(TAG, "Deleting configuration for tunnel $name")
val file = fileFor(name)
if (!file.delete()) throw IOException(context.getString(R.string.config_delete_error, file.name))
if (!file.delete())
throw IOException(context.getString(R.string.config_delete_error, file.name))
}
override fun enumerate(): Set<String> {
@@ -68,7 +70,8 @@ class FileConfigStore(private val context: Context) : ConfigStore {
override fun save(name: String, config: Config): Config {
Log.d(TAG, "Saving configuration for tunnel $name")
val file = fileFor(name)
if (!file.isFile) throw FileNotFoundException(context.getString(R.string.config_not_found_error, file.name))
if (!file.isFile)
throw FileNotFoundException(context.getString(R.string.config_not_found_error, file.name))
FileOutputStream(file, false).use { stream -> stream.write(config.toWgQuickString().toByteArray(StandardCharsets.UTF_8)) }
return config
}