Remove unneeded class

This commit is contained in:
len
2016-03-30 17:19:02 +02:00
parent e04596c668
commit 723c0e99a5
5 changed files with 32 additions and 85 deletions

View File

@@ -12,6 +12,7 @@ import com.bumptech.glide.signature.StringSignature
import eu.kanade.tachiyomi.util.DiskUtils
import java.io.File
import java.io.IOException
import java.io.InputStream
/**
* Class used to create cover cache.
@@ -64,19 +65,32 @@ class CoverCache(private val context: Context) {
}
/**
* Copy the cover from Glide's cache to this cache.
* Copy the given file to this cache.
* @param thumbnailUrl url of thumbnail.
* @param sourceFile the source file of the cover image.
* @throws IOException exception returned
* @throws IOException if there's any error.
*/
@Throws(IOException::class)
fun copyToLocalCache(thumbnailUrl: String, sourceFile: File) {
// Get destination file.
val destFile = File(cacheDir, DiskUtils.hashKeyForDisk(thumbnailUrl))
val destFile = getCoverFromCache(thumbnailUrl)
sourceFile.copyTo(destFile, overwrite = true)
}
/**
* Copy the given stream to this cache.
* @param thumbnailUrl url of the thumbnail.
* @param inputStream the stream to copy.
* @throws IOException if there's any error.
*/
@Throws(IOException::class)
fun copyToLocalCache(thumbnailUrl: String, inputStream: InputStream) {
// Get destination file.
val destFile = getCoverFromCache(thumbnailUrl)
destFile.outputStream().use { inputStream.copyTo(it) }
}
/**
* Returns the cover from cache.

View File

@@ -1,55 +0,0 @@
package eu.kanade.tachiyomi.data.io
import android.content.Context
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
// Create temporary file
val outputFile = File.createTempFile("temp_cover", "0", outputDir)
// 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()
}
}