<commit_before>package com.beust.kobalt.api

import com.beust.kobalt.Args
import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.kobaltLog
import java.io.File
import java.io.FileInputStream
import java.io.FileOutputStream
import java.io.IOException
import java.net.URL
import java.util.jar.JarInputStream

/**
 * Base class for templates that decompress a jar file.
 */
interface InputStreamJarTemplate : ITemplate {
    val inputStream: JarInputStream

    override fun generateTemplate(args: Args, classLoader: ClassLoader) {
        extractFile(inputStream, File("."))
    }

    private fun extractFile(ins: JarInputStream, destDir: File) {
        var entry = ins.nextEntry
        while (entry != null) {
            val f = File(destDir.path + File.separator + entry.name)
            if (entry.isDirectory) {
                f.mkdir()
                entry = ins.nextEntry
                continue
            }

            kobaltLog(2, "  Extracting: $entry to ${f.absolutePath}")
            FileOutputStream(f).use { fos ->
                KFiles.copy(ins, fos)
            }
            entry = ins.nextEntry
        }
    }
}

abstract class ResourceJarTemplate(val jarName: String, val classLoader: ClassLoader) : InputStreamJarTemplate {
    override val inputStream = JarInputStream(classLoader.getResource(jarName).openConnection().inputStream)
}

abstract class FileJarTemplate(val fileName: String, val classLoader: ClassLoader) : InputStreamJarTemplate {
    override val inputStream = JarInputStream(FileInputStream(File(fileName)))
}

abstract class HttpJarTemplate(val url: String, val classLoader: ClassLoader) : InputStreamJarTemplate {
    override val inputStream : JarInputStream
        get() {
            try {
                val result = URL(url).openConnection().inputStream
                return JarInputStream(result)
            } catch(ex: IOException) {
                throw IllegalArgumentException("Couldn't connect to $url")
            }
        }
}
<commit_msg>Refactor.<commit_after>package com.beust.kobalt.api

import com.beust.kobalt.Args
import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.kobaltLog
import java.io.*
import java.net.URL
import java.util.jar.JarInputStream

/**
 * Base class for templates that decompress a jar file.
 */
interface InputStreamJarTemplate : ITemplate {
    val inputStream: InputStream

    override fun generateTemplate(args: Args, classLoader: ClassLoader) {
        extractFile(File("."))
    }

    private fun extractFile(destDir: File) {
        val ins = JarInputStream(inputStream)
        var entry = ins.nextEntry
        while (entry != null) {
            val f = File(destDir.path + File.separator + entry.name)
            if (entry.isDirectory) {
                f.mkdir()
                entry = ins.nextEntry
                continue
            }

            kobaltLog(2, "  Extracting: $entry to ${f.absolutePath}")
            FileOutputStream(f).use { fos ->
                KFiles.copy(ins, fos)
            }
            entry = ins.nextEntry
        }
    }
}

abstract class ResourceJarTemplate(jarName: String, val classLoader: ClassLoader) : InputStreamJarTemplate {
    override val inputStream : InputStream = classLoader.getResource(jarName).openConnection().inputStream
}

abstract class FileJarTemplate(val fileName: String, val classLoader: ClassLoader) : InputStreamJarTemplate {
    override val inputStream = FileInputStream(File(fileName))
}

abstract class HttpJarTemplate(val url: String, val classLoader: ClassLoader) : InputStreamJarTemplate {
    override val inputStream : InputStream
        get() {
            try {
                return URL(url).openConnection().inputStream
            } catch(ex: IOException) {
                throw IllegalArgumentException("Couldn't connect to $url")
            }
        }
}

{'fraction_non_alphanumeric': 0.09093257556187032, 'fraction_numerical': 0.0005166623611469904, 'mean_word_length': 2.6186915887850466, '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': '6545511', 'n_tokens_mistral': 1069, 'n_tokens_neox': 1051, 'n_words': 251}