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

sttp.client4.internal.SttpFileExtensions.scala Maven / Gradle / Ivy

There is a newer version: 4.0.0-M17
Show newest version
package sttp.client4.internal

import java.nio.file.Files
import java.nio.file.Path

import scala.io.Source

trait SttpFileExtensions { self: SttpFile =>
  def toPath: Path = underlying.asInstanceOf[Path]
  def toFile: java.io.File = toPath.toFile

  def readAsString: String = {
    val s = Source.fromFile(toFile, "UTF-8");
    try s.getLines().mkString("\n")
    finally s.close()
  }

  def readAsByteArray: Array[Byte] = Files.readAllBytes(toPath)
}

trait SttpFileCompanionExtensions {
  def fromPath(path: Path): SttpFile =
    new SttpFile(path) {
      val name: String = path.getFileName.toString
      def size: Long = Files.size(path)
    }
  def fromFile(file: java.io.File): SttpFile = fromPath(file.toPath)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy