All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mayabot.nlp.resources.UseLines.kt Maven / Gradle / Ivy

There is a newer version: 4.0.0
Show newest version
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))
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy