<commit_before>package com.clxcommunications.xms;

import java.io.Closeable;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLEncoder;
import java.nio.CharBuffer;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpException;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.concurrent.FutureCallback;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.nio.IOControl;
import org.apache.http.nio.client.HttpAsyncClient;
import org.apache.http.nio.client.methods.AsyncCharConsumer;
import org.apache.http.nio.protocol.BasicAsyncRequestProducer;
import org.apache.http.nio.protocol.HttpAsyncRequestProducer;
import org.apache.http.nio.protocol.HttpAsyncResponseConsumer;
import org.apache.http.protocol.HttpContext;
import org.immutables.value.Value;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.clxcommunications.xms.api.ApiError;
import com.clxcommunications.xms.api.BatchId;
import com.clxcommunications.xms.api.MtBatchBinarySmsCreate;
import com.clxcommunications.xms.api.MtBatchBinarySmsResult;
import com.clxcommunications.xms.api.MtBatchBinarySmsUpdate;
import com.clxcommunications.xms.api.MtBatchSmsResult;
import com.clxcommunications.xms.api.MtBatchTextSmsCreate;
import com.clxcommunications.xms.api.MtBatchTextSmsResult;
import com.clxcommunications.xms.api.MtBatchTextSmsUpdate;
import com.clxcommunications.xms.api.Page;
import com.clxcommunications.xms.api.PagedBatchResult;
import com.fasterxml.jackson.core.JsonProcessingException;

/**
 * An abstract representation of an XMS connection. This class exposes a number
 * of methods which can be called to interact with the XMS REST API.
 * <p>
 * To instantiate this class it is necessary to use a builder, see
 * {@link #builder()}. The builder can be used to configure the connection as
 * necessary, once the connection is opened with {@link Builder#start()} it is
 * necessary to later close the connection using {@link #close()}.
 */
@Value.Immutable(copy = false)
@ValueStylePackageDirect
public abstract class ApiConnection implements Closeable {

	public static class Builder extends ApiConnectionImpl.Builder {

		/**
		 * Initializes the endpoint host from the given URL.
		 * 
		 * @param url
		 *            the URL containing the host
		 * @return this builder for use in a chained invocation
		 * @see HttpHost#create(String)
		 */
		public Builder endpointHostFromUrl(String url) {
			return this.endpointHost(HttpHost.create(url));
		}

		/**
		 * Initializes the endpoint host from the given hostname, port, and
		 * scheme.
		 * 
		 * @param hostname
		 *            the hostname
		 * @param port
		 *            the port
		 * @param scheme
		 *            the scheme (typically http or https)
		 * @return this builder for use in a chained invocation
		 * @see HttpHost#HttpHost(String, int, String)
		 */
		public Builder endpointHost(String hostname, int port, String scheme) {
			return this.endpointHost(new HttpHost(hostname, port, scheme));
		}

		/**
		 * Builds and starts the defined API connection. This is identical to
		 * calling {@link #build()} and then {@link ApiConnection#start()}.
		 * 
		 * @return an API connection
		 */
		public ApiConnection start() {
			ApiConnection conn = super.build();
<commit_msg>Fix configuration of pretty printing<commit_after>package com.clxcommunications.xms;

import java.io.Closeable;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLEncoder;
import java.nio.CharBuffer;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpException;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.concurrent.FutureCallback;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.nio.IOControl;
import org.apache.http.nio.client.HttpAsyncClient;
import org.apache.http.nio.client.methods.AsyncCharConsumer;
import org.apache.http.nio.protocol.BasicAsyncRequestProducer;
import org.apache.http.nio.protocol.HttpAsyncRequestProducer;
import org.apache.http.nio.protocol.HttpAsyncResponseConsumer;
import org.apache.http.protocol.HttpContext;
import org.immutables.value.Value;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.clxcommunications.xms.api.ApiError;
import com.clxcommunications.xms.api.BatchId;
import com.clxcommunications.xms.api.MtBatchBinarySmsCreate;
import com.clxcommunications.xms.api.MtBatchBinarySmsResult;
import com.clxcommunications.xms.api.MtBatchBinarySmsUpdate;
import com.clxcommunications.xms.api.MtBatchSmsResult;
import com.clxcommunications.xms.api.MtBatchTextSmsCreate;
import com.clxcommunications.xms.api.MtBatchTextSmsResult;
import com.clxcommunications.xms.api.MtBatchTextSmsUpdate;
import com.clxcommunications.xms.api.Page;
import com.clxcommunications.xms.api.PagedBatchResult;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.SerializationFeature;

/**
 * An abstract representation of an XMS connection. This class exposes a number
 * of methods which can be called to interact with the XMS REST API.
 * <p>
 * To instantiate this class it is necessary to use a builder, see
 * {@link #builder()}. The builder can be used to configure the connection as
 * necessary, once the connection is opened with {@link Builder#start()} it is
 * necessary to later close the connection using {@link #close()}.
 */
@Value.Immutable(copy = false)
@ValueStylePackageDirect
public abstract class ApiConnection implements Closeable {

	public static class Builder extends ApiConnectionImpl.Builder {

		/**
		 * Initializes the endpoint host from the given URL.
		 * 
		 * @param url
		 *            the URL containing the host
		 * @return this builder for use in a chained invocation
		 * @see HttpHost#create(String)
		 */
		public Builder endpointHostFromUrl(String url) {
			return this.endpointHost(HttpHost.create(url));
		}

		/**
		 * Initializes the endpoint host from the given hostname, port, and
		 * scheme.
		 * 
		 * @param hostname
		 *            the hostname
		 * @param port
		 *            the port
		 * @param scheme
		 *            the scheme (typically http or https)
		 * @return this builder for use in a chained invocation
		 * @see HttpHost#HttpHost(String, int, String)
		 */
		public Builder endpointHost(String hostname, int port, String scheme) {
			return this.endpointHost(new HttpHost(hostname, port, scheme));
		}

		@Override
		public ApiConnection build() {
			ApiConnection conn = super.build();

			conn.json.configure(SerializationFeature.INDENT_OUTPUT,
			        conn.prettyPrintJson());

			return conn;
		}

		/**
		 * Builds and starts the defined API connection. This is identical to
		 * calling {@link #build()} and then {@link ApiConnection#start()}.
		 * 
		 * @return an API connection
		 */
		public ApiConnection start() {
			ApiConnection conn = build();

{'fraction_non_alphanumeric': 0.09482228508178576, 'fraction_numerical': 0.0004919444102816382, 'mean_word_length': 4.639389736477115, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 3}, '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': '2011935', 'n_tokens_mistral': 2511, 'n_tokens_neox': 2332, 'n_words': 605}