package com.xyzshell.andinfo.libs

import java.io.RandomAccessFile

typealias ReadFileCallback = (line:String, index: Int) -> Boolean

class ReadFile {
    fun read(path: String, callback: ReadFileCallback) {
        try {
            val randomAccessFile = RandomAccessFile(path,"r")
            var i = 0

            randomAccessFile.use {
                while (true) {
                    val line = randomAccessFile.readLine()
                    if(line == null) {
                        break
                    }
                    if(callback(line, i)){
                        break
                    }
                    i++
                }
            }

        } catch (e:Throwable) {
            e.printStackTrace()
        }
    }
}