com.baulsupp.oksocial.output.ResponseExtractor.kt Maven / Gradle / Ivy
The newest version!
package com.baulsupp.oksocial.output
import okio.BufferedSource
import okio.buffer
import okio.source
import java.io.ByteArrayInputStream
import java.io.File
import java.nio.file.Files
object ToStringResponseExtractor : ResponseExtractor {
override fun mimeType(response: Any): String = "text/plain"
override fun source(response: Any): BufferedSource =
ByteArrayInputStream(response.toString().toByteArray()).source().buffer()
override fun filename(response: Any): String? = null
}
object FileResponseExtractor : ResponseExtractor {
override fun mimeType(response: File): String? {
return Files.probeContentType(response.toPath())
}
override fun source(response: File): BufferedSource {
return response.source().buffer()
}
override fun filename(response: File): String {
return response.name
}
}
interface ResponseExtractor {
fun mimeType(response: R): String?
fun source(response: R): BufferedSource
fun filename(response: R): String?
}