ScriptReader -> kt

This commit is contained in:
Milos Kozak 2021-02-13 22:48:17 +01:00
parent f0ac7c4c25
commit 30c530a109
2 changed files with 25 additions and 41 deletions

View file

@ -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;
}
}

View file

@ -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
}
}