From 30c530a109b545f27e0ef7f0fa574c2930b992be Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 13 Feb 2021 22:48:17 +0100 Subject: [PATCH] ScriptReader -> kt --- .../plugins/aps/loop/ScriptReader.java | 41 ------------------- .../plugins/aps/loop/ScriptReader.kt | 25 +++++++++++ 2 files changed, 25 insertions(+), 41 deletions(-) delete mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/ScriptReader.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/ScriptReader.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/ScriptReader.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/ScriptReader.java deleted file mode 100644 index e3a64dbece..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/ScriptReader.java +++ /dev/null @@ -1,41 +0,0 @@ -package info.nightscout.androidaps.plugins.aps.loop; - -import android.content.Context; -import android.content.res.AssetManager; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; - -public class ScriptReader { - - private final Context mContext; - - public ScriptReader(Context context) { - mContext = context; - } - - public byte[] readFile(String fileName) throws IOException { - - AssetManager assetManager = mContext.getAssets(); - InputStream is = assetManager.open(fileName); - ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - - int nRead; - byte[] data = new byte[16384]; - - while ((nRead = is.read(data, 0, data.length)) != -1) { - buffer.write(data, 0, nRead); - } - - buffer.flush(); - - byte[] bytes = buffer.toByteArray(); - is.close(); - buffer.close(); - - - return bytes; - - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/ScriptReader.kt b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/ScriptReader.kt new file mode 100644 index 0000000000..000cd55900 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/ScriptReader.kt @@ -0,0 +1,25 @@ +package info.nightscout.androidaps.plugins.aps.loop + +import android.content.Context +import java.io.ByteArrayOutputStream +import java.io.IOException + +class ScriptReader(private val context: Context) { + + @Throws(IOException::class) + fun readFile(fileName: String): ByteArray { + val assetManager = context.assets + val `is` = assetManager.open(fileName) + val buffer = ByteArrayOutputStream() + var nRead: Int + val data = ByteArray(16384) + while (`is`.read(data, 0, data.size).also { nRead = it } != -1) { + buffer.write(data, 0, nRead) + } + buffer.flush() + val bytes = buffer.toByteArray() + `is`.close() + buffer.close() + return bytes + } +} \ No newline at end of file