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

a8.shared.ops.ReaderOps.scala Maven / Gradle / Ivy

There is a newer version: 1.0.0-20230212_1012_master
Show newest version
package a8.shared.ops

import java.io.{IOException, Reader, StringWriter}
import scala.util.Try

class ReaderOps(private val reader: Reader) extends AnyVal {
  def readFully(): String = {
    val writer = new StringWriter
    try {
      val buffer = new Array[Char](8192)
      var readCount = 0
      while (readCount >= 0 ) {
        readCount = reader.read(buffer)
        if (readCount >= 0)
          writer.write(buffer, 0, readCount)
      }
      writer.toString
    } finally {
      Try(writer.close())
      Try(reader.close())
    }
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy