<commit_before>package com.suse.saltstack.netapi.client.impl;

import com.suse.saltstack.netapi.client.Connection;
import com.suse.saltstack.netapi.config.ClientConfig;

import static com.suse.saltstack.netapi.config.ClientConfig.*;

import com.suse.saltstack.netapi.exception.SaltStackException;
import com.suse.saltstack.netapi.parser.JsonParser;

import java.io.DataOutputStream;
import java.io.IOException;
import java.net.HttpURLConnection;

/**
 * Class representation of a connection to SaltStack for issuing API requests using JDK's
 * HttpURLConnection.
 */
public class JDKConnection<T> implements Connection<T> {

    /** The endpoint. */
    private final String endpoint;

    /** The config object. */
    private final ClientConfig config;

    /** The parser to parse the returned Result */
    private final JsonParser<T> parser;

    /**
     * Init a connection to a given SaltStack API endpoint.
     *
     * @param endpointIn the endpoint
     * @param configIn the config
     */
    public JDKConnection(String endpointIn, JsonParser<T> parserIn, ClientConfig configIn) {
        endpoint = endpointIn;
        config = configIn;
        parser = parserIn;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public T getResult(String data) throws SaltStackException {
        return request("POST", data);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public T getResult() throws SaltStackException {
        return request("GET", null);
    }

    /**
     * Perform HTTP request and parse the result into a given result type.
     *
     * @param method the HTTP method to use
     * @return object of type given by resultType
     * @throws SaltStackException in case of a problem
     */
    private T request(String method, String data)
            throws SaltStackException {
        HttpURLConnection connection = null;
        try {
            // Setup and configure the connection
            connection = RequestFactory.getInstance().initConnection(
                    method, endpoint, config);
            connection.setUseCaches(false);
            connection.setDoInput(true);
            connection.setDoOutput(true);

            // Timeouts may be specified on configuration
            int connect_timeout = config.get(CONNECT_TIMEOUT);
            if (connect_timeout >= 0) connection.setConnectTimeout(connect_timeout);

            int socket_timeout = config.get(SOCKET_TIMEOUT);
            if (socket_timeout >= 0) connection.setReadTimeout(socket_timeout);

            // Send data in case we have some
            if (data != null) {
                connection.setRequestProperty("Content-Type", "application/json");
                connection.setRequestProperty("Content-Length",
                        Integer.toString(data.getBytes().length));

                // Actually write the bytes
                DataOutputStream outputStream = new DataOutputStream(
                        connection.getOutputStream());
                outputStream.writeBytes(data);<commit_msg>Add braces on if Statements<commit_after>package com.suse.saltstack.netapi.client.impl;

import com.suse.saltstack.netapi.client.Connection;
import com.suse.saltstack.netapi.config.ClientConfig;

import static com.suse.saltstack.netapi.config.ClientConfig.*;

import com.suse.saltstack.netapi.exception.SaltStackException;
import com.suse.saltstack.netapi.parser.JsonParser;

import java.io.DataOutputStream;
import java.io.IOException;
import java.net.HttpURLConnection;

/**
 * Class representation of a connection to SaltStack for issuing API requests using JDK's
 * HttpURLConnection.
 */
public class JDKConnection<T> implements Connection<T> {

    /** The endpoint. */
    private final String endpoint;

    /** The config object. */
    private final ClientConfig config;

    /** The parser to parse the returned Result */
    private final JsonParser<T> parser;

    /**
     * Init a connection to a given SaltStack API endpoint.
     *
     * @param endpointIn the endpoint
     * @param configIn the config
     */
    public JDKConnection(String endpointIn, JsonParser<T> parserIn, ClientConfig configIn) {
        endpoint = endpointIn;
        config = configIn;
        parser = parserIn;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public T getResult(String data) throws SaltStackException {
        return request("POST", data);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public T getResult() throws SaltStackException {
        return request("GET", null);
    }

    /**
     * Perform HTTP request and parse the result into a given result type.
     *
     * @param method the HTTP method to use
     * @return object of type given by resultType
     * @throws SaltStackException in case of a problem
     */
    private T request(String method, String data)
            throws SaltStackException {
        HttpURLConnection connection = null;
        try {
            // Setup and configure the connection
            connection = RequestFactory.getInstance().initConnection(
                    method, endpoint, config);
            connection.setUseCaches(false);
            connection.setDoInput(true);
            connection.setDoOutput(true);

            // Timeouts may be specified on configuration
            int connect_timeout = config.get(CONNECT_TIMEOUT);
            if (connect_timeout >= 0) {
                connection.setConnectTimeout(connect_timeout);
            }

            int socket_timeout = config.get(SOCKET_TIMEOUT);
            if (socket_timeout >= 0) {
                connection.setReadTimeout(socket_timeout);
            }

            // Send data in case we have some
            if (data != null) {
                connection.setRequestProperty("Content-Type", "application/json");
                connection.setRequestProperty("Content-Length",
                        Integer.toString(data.getBytes().length));

                // Actually write the bytes
                DataOutputStream outputStream = new DataOutputStream(
                        connection.getOutputStream());
                outputStream.writeBytes(data);
{'fraction_non_alphanumeric': 0.08820678513731825, 'fraction_numerical': 0.0006462035541195477, 'mean_word_length': 2.3812124522119062, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, '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': '3836456', 'n_tokens_mistral': 1581, 'n_tokens_neox': 1518, 'n_words': 433}