com.mayabot.nlp.resources.UseLines.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mynlp Show documentation
Show all versions of mynlp Show documentation
Maya Nlp subproject :mynlp
package com.mayabot.nlp.resources
import com.mayabot.nlp.utils.CharSourceLineReader
import java.io.InputStream
import java.util.function.Consumer
object UseLines {
@JvmOverloads
@JvmStatic
fun forEachLine(inputStream: InputStream,
trim: Boolean = true,
skipBlank: Boolean = true,
consumer: Consumer) {
inputStream.bufferedReader().forEachLine { x ->
var line = x
if (trim) {
line = line.trim()
}
if (skipBlank && line.isBlank()) {
} else {
consumer.accept(line)
}
}
}
@JvmOverloads
@JvmStatic
fun useLines(inputStream: InputStream,
trim: Boolean = true,
skipBlank: Boolean = true,
consumer: Consumer) {
inputStream.bufferedReader().forEachLine { x ->
var line = x
if (trim) {
line = line.trim()
}
if (skipBlank && line.isBlank()) {
} else {
consumer.accept(line)
}
}
}
@JvmStatic
fun lineReader(inputStream: InputStream): CharSourceLineReader {
return CharSourceLineReader(inputStream.bufferedReader(charset = Charsets.UTF_8))
}
}