<commit_before>package ru.wordmetrix.smartfile

import java.io.File
import ru.wordmetrix.vector._
import java.io.FileOutputStream
import java.io.FileInputStream
import SmartFile._
import java.io.FileWriter
import java.io.File
import java.io.ObjectOutputStream
import java.io.ObjectInputStream
import java.nio.charset.CodingErrorAction
import scala.Array.canBuildFrom
import scala.io.Codec

object SmartFile {

    implicit def fromFile(f: File) = new SmartFile(f)
    implicit def fromString(s : String) = new SmartFile(new File(s))
    implicit def string2Array(s: String): Array[Byte] = s.toArray.map(c => c.toByte)
    implicit def toFile(sf : SmartFile) = sf.file
}

class SmartFile(val file: File) {
    import java.nio.charset.CodingErrorAction
    import scala.io.Codec

    implicit val codec = Codec("UTF-8").onMalformedInput(CodingErrorAction.IGNORE).onUnmappableCharacter(CodingErrorAction.IGNORE)

    def /(f: SmartFile) = new SmartFile(new File(file, f.file.toString))
    def /(f: String) = new SmartFile(new File(file, f))
    def /(f: Int) = new SmartFile(new File(file, f.toString))
    def /(f: File) = new SmartFile(new File(file, f.toString))

    def write(ss: Traversable[String]): Unit =
        write(ss.mkString("\n"))

    def write(a: Array[Byte]) = {
        file.getParentFile().mkdirs() //    path.mkdirs()
        val fn = new FileOutputStream(file)
        fn.write(a)
        fn.close()
    }<commit_msg>Write text in text mode<commit_after>package ru.wordmetrix.smartfile

import java.io.File
import ru.wordmetrix.vector._
import java.io.FileOutputStream
import java.io.FileInputStream
import SmartFile._
import java.io.FileWriter
import java.io.File
import java.io.ObjectOutputStream
import java.io.ObjectInputStream
import java.nio.charset.CodingErrorAction
import scala.Array.canBuildFrom
import scala.io.Codec
import java.io.OutputStreamWriter

object SmartFile {

    implicit def fromFile(f: File) = new SmartFile(f)
    implicit def fromString(s : String) = new SmartFile(new File(s))
    //implicit def string2Array(s: String): Array[Byte] = s.toArray.map(c => c.toByte)
    implicit def toFile(sf : SmartFile) = sf.file
}

class SmartFile(val file: File) {
//    import java.nio.charset.CodingErrorAction
//    import scala.io.Codec

//    implicit val codec = Codec("UTF-8").onMalformedInput(CodingErrorAction.IGNORE).onUnmappableCharacter(CodingErrorAction.IGNORE)

    def /(f: SmartFile) = new SmartFile(new File(file, f.file.toString))
    def /(f: String) = new SmartFile(new File(file, f))
    def /(f: Int) = new SmartFile(new File(file, f.toString))
    def /(f: File) = new SmartFile(new File(file, f.toString))

    def write(ss: Traversable[String]): Unit =
        write(ss.mkString("\n"))

    def write(s : String) : Unit = {
        file.getParentFile().mkdirs() //    path.mkdirs()
        val fn = new OutputStreamWriter(new FileOutputStream(file))
        fn.write(s)
        fn.close()
    }    
        
    def write(a: Array[Byte]) = {
        file.getParentFile().mkdirs() //    path.mkdirs()
        val fn = new FileOutputStream(file)
        fn.write(a)
        fn.close()
    }
{'fraction_non_alphanumeric': 0.12353127977135599, 'fraction_numerical': 0.0012702445220704986, 'mean_word_length': 3.578488372093023, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '6636345', 'n_tokens_mistral': 1041, 'n_tokens_neox': 1025, 'n_words': 237}