<commit_before>package com.yandex.money.api.net;

import com.yandex.money.api.utils.HttpHeaders;
import com.yandex.money.api.utils.MimeTypes;
import com.yandex.money.api.utils.Streams;
import com.yandex.money.api.utils.Strings;

import org.joda.time.DateTime;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.net.HttpURLConnection;
import java.net.ProtocolException;
import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.util.Map;

/**
 * @author <NAME> (<EMAIL>)
 */
public class PostRequestBodyBuffer extends ByteArrayOutputStream {

    private static final Charset REQUEST_CHARSET_UTF8 = Charset.forName("UTF-8");

    private static final byte[] POST_PARAM_DELIMITER = "&".getBytes(REQUEST_CHARSET_UTF8);
    private static final byte[] POST_PARAM_NV_DELIMITER = "=".getBytes(REQUEST_CHARSET_UTF8);

    private String contentType = MimeTypes.Application.X_WWW_FORM_URLENCODED;

    /**
     * Adds not null int parameter to buffer.
     *
     * @param name name of parameter
     * @param value its value
     */
    public PostRequestBodyBuffer addParam(String name, int value) {
        return addParam(name, Integer.toString(value));
    }

    /**
     * Adds not null String parameter to buffer.
     *
     * @param name name of parameter
     * @param value its value
     */
    public PostRequestBodyBuffer addParam(String name, String value) {
        try {
            return addParamWithoutURLEncoding(
                    URLEncoder.encode(name, REQUEST_CHARSET_UTF8.name())
                            .getBytes(REQUEST_CHARSET_UTF8),
                    URLEncoder.encode(value, REQUEST_CHARSET_UTF8.name())
                            .replace("+", "%20")
                            .getBytes(REQUEST_CHARSET_UTF8));
        } catch (UnsupportedEncodingException e) {
            throw new IllegalStateException(e.getMessage(), e);
        }
    }

    /**
     * Adds map of name-value pairs to buffer.
     *
     * @param params name-value pairs
     */
    public PostRequestBodyBuffer addParams(Map<String, String> params) {
        if (params == null) {
            throw new NullPointerException("params is null");
        }
<commit_msg>Replace null values with empty strings when adding params.<commit_after>package com.yandex.money.api.net;

import com.yandex.money.api.utils.HttpHeaders;
import com.yandex.money.api.utils.MimeTypes;
import com.yandex.money.api.utils.Streams;
import com.yandex.money.api.utils.Strings;

import org.joda.time.DateTime;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.net.HttpURLConnection;
import java.net.ProtocolException;
import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.util.Map;

/**
 * @author <NAME> (<EMAIL>)
 */
public class PostRequestBodyBuffer extends ByteArrayOutputStream {

    private static final Charset REQUEST_CHARSET_UTF8 = Charset.forName("UTF-8");

    private static final byte[] POST_PARAM_DELIMITER = "&".getBytes(REQUEST_CHARSET_UTF8);
    private static final byte[] POST_PARAM_NV_DELIMITER = "=".getBytes(REQUEST_CHARSET_UTF8);

    private String contentType = MimeTypes.Application.X_WWW_FORM_URLENCODED;

    /**
     * Adds not null int parameter to buffer.
     *
     * @param name name of parameter
     * @param value its value
     */
    public PostRequestBodyBuffer addParam(String name, int value) {
        return addParam(name, Integer.toString(value));
    }

    /**
     * Adds not null String parameter to buffer.
     *
     * @param name name of parameter
     * @param value its value
     */
    public PostRequestBodyBuffer addParam(String name, String value) {
        if (value == null) {
            value = "";
        }
        try {
            return addParamWithoutURLEncoding(
                    URLEncoder.encode(name, REQUEST_CHARSET_UTF8.name())
                            .getBytes(REQUEST_CHARSET_UTF8),
                    URLEncoder.encode(value, REQUEST_CHARSET_UTF8.name())
                            .replace("+", "%20")
                            .getBytes(REQUEST_CHARSET_UTF8));
        } catch (UnsupportedEncodingException e) {
            throw new IllegalStateException(e.getMessage(), e);
        }
    }

    /**
     * Adds map of name-value pairs to buffer.
     *
     * @param params name-value pairs
     */
    public PostRequestBodyBuffer addParams(Map<String, String> params) {
        if (params == null) {
            throw new NullPointerException("params is null");
        }

{'fraction_non_alphanumeric': 0.09929225645295588, 'fraction_numerical': 0.004163197335553705, 'mean_word_length': 2.816521048451152, 'pattern_counts': {'":': 0, '<': 9, '<?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': '3956174', 'n_tokens_mistral': 1434, 'n_tokens_neox': 1395, 'n_words': 318}