<commit_before>package io.youi.http

import java.io.File
import java.net.{HttpURLConnection, JarURLConnection, URL}

import io.youi.net.ContentType
import sun.net.www.protocol.file.FileURLConnection

sealed trait Content extends RequestContent {
  def length: Long
  def lastModified: Long
  def contentType: ContentType
}

case class StringContent(value: String, contentType: ContentType, lastModified: Long = System.currentTimeMillis()) extends Content {
  override def length: Long = value.getBytes("UTF-8").length

  override def toString: String = s"StringContent(${value.take(100)}, contentType: $contentType)"
}

case class FileContent(file: File, contentType: ContentType) extends Content {
  override def length: Long = file.length()

  override def lastModified: Long = file.lastModified()

  override def toString: String = s"FileContent(file: ${file.getAbsolutePath}, contentType: $contentType)"
}

case class URLContent(url: URL, contentType: ContentType) extends Content {
  private lazy val (contentLength, contentModified) = {<commit_msg>Added assertion that FileContent must be exist and be a file, not a directory.<commit_after>package io.youi.http

import java.io.File
import java.net.{HttpURLConnection, JarURLConnection, URL}

import io.youi.net.ContentType
import sun.net.www.protocol.file.FileURLConnection

sealed trait Content extends RequestContent {
  def length: Long
  def lastModified: Long
  def contentType: ContentType
}

case class StringContent(value: String, contentType: ContentType, lastModified: Long = System.currentTimeMillis()) extends Content {
  override def length: Long = value.getBytes("UTF-8").length

  override def toString: String = s"StringContent(${value.take(100)}, contentType: $contentType)"
}

case class FileContent(file: File, contentType: ContentType) extends Content {
  assert(file.isFile, s"Cannot send back ${file.getAbsolutePath} as it is not a file reference!")

  override def length: Long = file.length()

  override def lastModified: Long = file.lastModified()

  override def toString: String = s"FileContent(file: ${file.getAbsolutePath}, contentType: $contentType)"
}

case class URLContent(url: URL, contentType: ContentType) extends Content {
  private lazy val (contentLength, contentModified) = {
{'fraction_non_alphanumeric': 0.09815140845070422, 'fraction_numerical': 0.0035211267605633804, 'mean_word_length': 5.8053892215568865, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7244785', 'n_tokens_mistral': 636, 'n_tokens_neox': 629, 'n_words': 201}