I am assuming that by record count you mean the count of lines.
You can use the java.io.BufferedReader
to read the input stream line by line and incrementing a counter variable
import java.io.BufferedReader
import java.io.InputStreamReader
var count = 0
val inputStream: FSDataInputStream = fileSystem.open(dataFile)
val reader: BufferedReader = new BufferedReader(new InputStreamReader(inputStream))
var line: String = reader.readLine()
while(line!=null){
count+=1
line = reader.readLine()
}
Alternatively you can also use reader.lines().count()
to get the count of lines but using this you will not be able to reuse the input stream to get the actual data in lines since inputstream is not reusable.