Есть вот такой код. Можно ли создать файл без сохранения на устройство?
@RequiresApi(Build.VERSION_CODES.FROYO)
fun toFile(body: ResponseBody): File? {
try {
val filePath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).path
val futureStudioIconFile = File(filePath + File.separator + "${body.hashCode()}.png")
var inputStream: InputStream? = null
var outputStream: OutputStream? = null
try {
val fileReader = ByteArray(4096)
var fileSizeDownloaded: Long = 0
inputStream = body.byteStream()
outputStream = FileOutputStream(futureStudioIconFile)
while (true) {
val read: Int = inputStream.read(fileReader)
if (read == -1) {
break
}
outputStream.write(fileReader, 0, read)
fileSizeDownloaded += read.toLong()
}
outputStream.flush()
return futureStudioIconFile
} catch (e: IOException) {
return null
} finally {
inputStream?.close()
outputStream?.close()
}
} catch (e: IOException) {
return null
}
}