<commit_before>package com.axibase.tsd.client;

import com.axibase.tsd.network.PlainCommand;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.Socket;

class TcpClient {
    private static final Logger log = LoggerFactory.getLogger(TcpClient.class);
    private TcpClientConfiguration clientConfiguration;
    private Socket socket;
    private PrintWriter writer;

    TcpClient(TcpClientConfiguration clientConfiguration) {
        this.clientConfiguration = clientConfiguration;
    }

    public void send(PlainCommand command) {
        if (writer == null) {
            try {
                socket = recreateSocket();
                writer = recreateWriter(socket);
            } catch (IOException e) {
                throw new AtsdClientException("Error while connecting to ATSD", e);
            }
        }

        try {
            if (!writer.checkError()) {
                writer.println(command.compose());
                if (clientConfiguration.isAutoflush()) {
                    writer.flush();
                }
                return;
            } else {
                log.warn("Error while sending commands to ATSD. Trying to reconnect");
            }
        } catch (Exception e) {
            log.warn("Error while sending commands to ATSD. Trying to reconnect", e);
        }

        try {
            socket = recreateSocket();
            writer = recreateWriter(socket);
            writer.println(command.compose());
            if (clientConfiguration.isAutoflush()) {
                writer.flush();
            }
        } catch (Exception e) {
            throw new AtsdClientException("Error while sending command to ATSD", e);
        }

        if (writer.checkError()) {
            throw new AtsdClientException("Error while sending command to ATSD");
        }
    }

    public void close() {
        if (writer != null) {
            writer.close();
        }

        if (socket != null) {
            try {
                socket.close();
            } catch (IOException e) {
                log.warn("Error while closing tcp stream", e);
            }
        }
    }

    private Socket recreateSocket() throws IOException {
        if (socket != null) {
            socket.close();
            socket = null;
        }

        return new Socket(
                clientConfiguration.getServerName(),
                clientConfiguration.getPort());
    }

    private PrintWriter recreateWriter(Socket socket) throws IOException {
        if (writer != null) {
            writer.close();
            writer = null;
        }

        writer = new PrintWriter(
                socket.getOutputStream(),
                clientConfiguration.isAutoflush());

        return writer;
    }
}<commit_msg>explicitly set encoding to UTF8 in TcpClient<commit_after>package com.axibase.tsd.client;

import com.axibase.tsd.network.PlainCommand;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.Socket;

class TcpClient {
    private static final Logger log = LoggerFactory.getLogger(TcpClient.class);
    private TcpClientConfiguration clientConfiguration;
    private Socket socket;
    private PrintWriter writer;

    TcpClient(TcpClientConfiguration clientConfiguration) {
        this.clientConfiguration = clientConfiguration;
    }

    public void send(PlainCommand command) {
        if (writer == null) {
            try {
                socket = recreateSocket();
                writer = recreateWriter(socket);
            } catch (IOException e) {
                throw new AtsdClientException("Error while connecting to ATSD", e);
            }
        }

        try {
            if (!writer.checkError()) {
                writer.println(command.compose());
                if (clientConfiguration.isAutoflush()) {
                    writer.flush();
                }
                return;
            } else {
                log.warn("Error while sending commands to ATSD. Trying to reconnect");
            }
        } catch (Exception e) {
            log.warn("Error while sending commands to ATSD. Trying to reconnect", e);
        }

        try {
            socket = recreateSocket();
            writer = recreateWriter(socket);
            writer.println(command.compose());
            if (clientConfiguration.isAutoflush()) {
                writer.flush();
            }
        } catch (Exception e) {
            throw new AtsdClientException("Error while sending command to ATSD", e);
        }

        if (writer.checkError()) {
            throw new AtsdClientException("Error while sending command to ATSD");
        }
    }

    public void close() {
        if (writer != null) {
            writer.close();
        }

        if (socket != null) {
            try {
                socket.close();
            } catch (IOException e) {
                log.warn("Error while closing tcp stream", e);
            }
        }
    }

    private Socket recreateSocket() throws IOException {
        if (socket != null) {
            socket.close();
            socket = null;
        }

        return new Socket(
                clientConfiguration.getServerName(),
                clientConfiguration.getPort());
    }

    private PrintWriter recreateWriter(Socket socket) throws IOException {
        if (writer != null) {
            writer.close();
            writer = null;
        }

        writer = new PrintWriter(
                    new OutputStreamWriter(socket.getOutputStream(), "UTF8"),
                clientConfiguration.isAutoflush());

        return writer;
    }
}
{'fraction_non_alphanumeric': 0.09355509355509356, 'fraction_numerical': 0.0010395010395010396, 'mean_word_length': 1.7243983010854176, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3309070', 'n_tokens_mistral': 1471, 'n_tokens_neox': 1376, 'n_words': 362}