<commit_before>package engineer.carrot.warren.warren

import engineer.carrot.warren.kale.IKale
import engineer.carrot.warren.kale.irc.message.IIrcMessageSerialiser
import engineer.carrot.warren.kale.irc.message.IMessage
import engineer.carrot.warren.warren.ssl.WrappedSSLSocketFactory
import okio.BufferedSink
import okio.BufferedSource
import okio.Okio
import java.io.IOException
import java.net.Socket
import java.util.concurrent.TimeUnit
import javax.net.ssl.SSLSocketFactory

class IrcSocket(val server: String, val port: Int, val kale: IKale, val serialiser: IIrcMessageSerialiser) : IMessageSink, IMessageProcessor {
    lateinit var socket: Socket
    lateinit var source: BufferedSource
    lateinit var sink: BufferedSink

    override fun setUp(): Boolean {
        val socketFactory = WrappedSSLSocketFactory

        socket = try {
            val socket = socketFactory.createSocket(server, port)
            socketFactory.disableDHEKeyExchange(socket)
        } catch (exception: Exception) {
            println("failed to connect using: $server:$port")

            return false
        }

        sink = Okio.buffer(Okio.sink(socket.outputStream))
        source = Okio.buffer(Okio.source(socket.inputStream))

        source.timeout().timeout(5, TimeUnit.SECONDS)

        return true
    }

    override fun tearDown() {
        socket.close()
    }

    override fun process(): Boolean {
        val line = try {
            source.readUtf8LineStrict()
        } catch (exception: IOException) {
            return false
        }

        println(">> $line")

        kale.process(line)
        return true
    }

    override fun <T : IMessage> write(message: T) {<commit_msg>Catch interrupted IO exceptions and bail out cleanly<commit_after>package engineer.carrot.warren.warren

import engineer.carrot.warren.kale.IKale
import engineer.carrot.warren.kale.irc.message.IIrcMessageSerialiser
import engineer.carrot.warren.kale.irc.message.IMessage
import engineer.carrot.warren.warren.ssl.WrappedSSLSocketFactory
import okio.BufferedSink
import okio.BufferedSource
import okio.Okio
import java.io.IOException
import java.io.InterruptedIOException
import java.net.Socket
import java.util.concurrent.TimeUnit
import javax.net.ssl.SSLSocketFactory

class IrcSocket(val server: String, val port: Int, val kale: IKale, val serialiser: IIrcMessageSerialiser) : IMessageSink, IMessageProcessor {
    lateinit var socket: Socket
    lateinit var source: BufferedSource
    lateinit var sink: BufferedSink

    override fun setUp(): Boolean {
        val socketFactory = WrappedSSLSocketFactory

        socket = try {
            val socket = socketFactory.createSocket(server, port)
            socketFactory.disableDHEKeyExchange(socket)
        } catch (exception: Exception) {
            println("failed to connect using: $server:$port")

            return false
        }

        sink = Okio.buffer(Okio.sink(socket.outputStream))
        source = Okio.buffer(Okio.source(socket.inputStream))

        source.timeout().timeout(5, TimeUnit.SECONDS)

        return true
    }

    override fun tearDown() {
        socket.close()
    }

    override fun process(): Boolean {
        val line = try {
            source.readUtf8LineStrict()
        } catch (exception: IOException) {
            return false
        } catch (exception: InterruptedIOException) {
            println("process wait interrupted, bailing out")
            tearDown()
            return false
        }

        println(">> $line")

        kale.process(line)
        return true
    }

    override fun <T : IMessage> write(message: T) {
{'fraction_non_alphanumeric': 0.0858085808580858, 'fraction_numerical': 0.0011001100110011, 'mean_word_length': 2.914962325080732, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '3519900', 'n_tokens_mistral': 1049, 'n_tokens_neox': 1023, 'n_words': 242}