mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-12 20:19:05 +01:00
Settings in Kotlin
This commit is contained in:
@@ -1,62 +1,55 @@
|
||||
@file:JvmName("IOHandler")
|
||||
package eu.kanade.tachiyomi.data.io
|
||||
|
||||
import android.content.Context
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.util.ToastUtil
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
import java.io.FileOutputStream
|
||||
import java.io.IOException
|
||||
|
||||
/**
|
||||
* Returns temp file location
|
||||
*
|
||||
* @param context context of application
|
||||
* @throws IOException IO exception
|
||||
* @return location of temp file
|
||||
*/
|
||||
@Throws(IOException::class)
|
||||
private fun getTempFilename(context: Context): String {
|
||||
// Get output directory.
|
||||
val outputDir = context.cacheDir
|
||||
* Returns temp file location.
|
||||
*
|
||||
* @param context context of application.
|
||||
* @throws IOException IO exception.
|
||||
* @return location of temp file.
|
||||
*/
|
||||
@Throws(IOException::class)
|
||||
private fun getTempFilename(context: Context): String {
|
||||
// Get output directory.
|
||||
val outputDir = context.cacheDir
|
||||
|
||||
// Create temporary file
|
||||
val outputFile = File.createTempFile("temp_cover", "0", outputDir)
|
||||
// Create temporary file
|
||||
val outputFile = File.createTempFile("temp_cover", "0", outputDir)
|
||||
|
||||
// Return path of temporary file
|
||||
return outputFile.absolutePath
|
||||
// Return path of temporary file
|
||||
return outputFile.absolutePath
|
||||
}
|
||||
|
||||
/**
|
||||
* Download media to temp location and returns file path.
|
||||
*
|
||||
* @param input input stream containing input file.
|
||||
* @param context context of application.
|
||||
* @throws IOException IO exception.
|
||||
* @return location of temp file.
|
||||
*/
|
||||
@Throws(IOException::class)
|
||||
fun downloadMediaAndReturnPath(input: FileInputStream, context: Context): String {
|
||||
var output: FileOutputStream? = null
|
||||
try {
|
||||
// Get temp file name.
|
||||
val tempFilename = getTempFilename(context)
|
||||
|
||||
output = FileOutputStream(tempFilename)
|
||||
|
||||
// Copy input stream to temp location.
|
||||
input.copyTo(output)
|
||||
|
||||
return tempFilename
|
||||
} finally {
|
||||
// Close streams.
|
||||
input.close()
|
||||
output?.close()
|
||||
}
|
||||
|
||||
/**
|
||||
* Download media to temp location and returns file path
|
||||
*
|
||||
* @param input input stream containing input file
|
||||
* @param context context of application
|
||||
* @throws IOException IO exception
|
||||
* @return location of temp file
|
||||
*/
|
||||
@Throws(IOException::class)
|
||||
fun downloadMediaAndReturnPath(input: FileInputStream, context: Context): String {
|
||||
var tempFilename = ""
|
||||
var output: FileOutputStream? = null
|
||||
try {
|
||||
// Get temp file name.
|
||||
tempFilename = getTempFilename(context)
|
||||
|
||||
output = FileOutputStream(tempFilename)
|
||||
// Copy input stream to temp location.
|
||||
input.copyTo(output)
|
||||
} catch (e: IOException) {
|
||||
// Show user something went wrong and print stackTrace.
|
||||
ToastUtil.showShort(context, R.string.notification_manga_update_failed)
|
||||
e.printStackTrace()
|
||||
} finally {
|
||||
// Close streams.
|
||||
input.close()
|
||||
output?.close()
|
||||
}
|
||||
|
||||
// Return temp name.
|
||||
return tempFilename
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user