moved utility functions out from main activity

This commit is contained in:
Juha Heinanen
2018-05-10 16:04:23 +03:00
parent 0747fa9134
commit 5f5db3a56a
3 changed files with 56 additions and 54 deletions
@@ -4,14 +4,27 @@ import android.content.Context
import android.support.v7.app.AlertDialog
import android.util.Log
import android.widget.ImageButton
import java.io.File
import java.io.FileInputStream
import java.io.FileOutputStream
import java.io.OutputStreamWriter
import java.io.*
object Utils {
fun copyAssetToFile(context: Context, asset: String, path: String) {
try {
val `is` = context.assets.open(asset)
val os = FileOutputStream(path)
val buffer = ByteArray(512)
var byteRead: Int = `is`.read(buffer)
while (byteRead != -1) {
os.write(buffer, 0, byteRead)
byteRead = `is`.read(buffer)
}
} catch (e: IOException) {
Log.e("Baresip", "Failed to read asset " + asset + ": " +
e.toString())
}
}
fun getFileContents(file: File): String {
if (!file.exists()) {
Log.e("Baresip", "Failed to find file: " + file.path)