mirror of
https://github.com/mihonapp/mihon.git
synced 2024-10-31 21:20:59 -04:00
78689e7443
* Migrate to AndroidX (automatic conversion by Android Studio) * AndroidX dependency code updates * Fix source preference reparenting * fixes the androidx prefererences icon spacing issue (cherry picked from commit b76a15d960ec2cdf771be16377db0348b66b3179) * Fix source preference screen heading size/list padding Co-authored-by: Carlos <cargo8005@gmail.com>
40 lines
900 B
Kotlin
40 lines
900 B
Kotlin
package eu.kanade.tachiyomi.util
|
|
|
|
import okio.BufferedSource
|
|
import okio.buffer
|
|
import okio.sink
|
|
import java.io.File
|
|
import java.io.OutputStream
|
|
|
|
/**
|
|
* Saves the given source to a file and closes it. Directories will be created if needed.
|
|
*
|
|
* @param file the file where the source is copied.
|
|
*/
|
|
fun BufferedSource.saveTo(file: File) {
|
|
try {
|
|
// Create parent dirs if needed
|
|
file.parentFile.mkdirs()
|
|
|
|
// Copy to destination
|
|
saveTo(file.outputStream())
|
|
} catch (e: Exception) {
|
|
close()
|
|
file.delete()
|
|
throw e
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Saves the given source to an output stream and closes both resources.
|
|
*
|
|
* @param stream the stream where the source is copied.
|
|
*/
|
|
fun BufferedSource.saveTo(stream: OutputStream) {
|
|
use { input ->
|
|
stream.sink().buffer().use {
|
|
it.writeAll(input)
|
|
it.flush()
|
|
}
|
|
}
|
|
}
|