<commit_before>package com.cjbarker.wb.ws;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.HttpVersion;
import org.apache.http.StatusLine;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.conn.params.ConnManagerParams;
import org.apache.http.conn.params.ConnPerRoute;
import org.apache.http.conn.params.ConnPerRouteBean;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicHeader;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.http.params.HttpProtocolParams;

import android.util.Log;

/**
 * Class provides HTTP request/response handling for weather API clients.
 * 
 * @author <NAME>
 */
public class ClientRequest {
	
	// static vars
	private static final String TAG = "HttpClient";
	private static final String DEFAULT_USER_AGENT = "WB/1.0";
	private static final String DEFAULT_ACCEPT_TYPES = "application/json,application/xml";
	public static enum Method { GET };
	
	// predefined headers
	private static final BasicHeader HEADER_CONTENT_TYPE = 
			new BasicHeader("Content-Type", "application/xml");
	private static final BasicHeader HEADER_ACCEPT = 
			new BasicHeader("Accept", "application/xml");
	private static final BasicHeader HEADER_CONNECTION = 
			new BasicHeader("Connection", "Keep-Alive");
	private static final BasicHeader HEADER_CACHE_CONTROL = 
			new BasicHeader("Cache-Control", "no-cache");
	private static final BasicHeader HEADER_PRAGMA = 
			new BasicHeader("Pragma", "no-cache");

	// member vars
	private String baseUri;
	private String userAgent;		 
	private String acceptTypes;
	
	private ClientRequest() {}
	
	/**
	 * Default constructor
	 * @param uri	URI to perform HTTP request on
	 */
	public ClientRequest(String uri) {
		this(uri, DEFAULT_USER_AGENT);
	}
	
	/**
	 * Constructor
	 * @param uri		URI to perform HTTP request on
	 * @param userAgent HTTP user-agent header
	 */
	public ClientRequest(String uri, String userAgent) {
		this(uri, DEFAULT_USER_AGENT, DEFAULT_ACCEPT_TYPES);
	}
	
	/**
	 * Constructor
	 * @param uri			URI to perform HTTP request on
	 * @param userAgent 	HTTP user-agent header
	 * @param acceptTypes	HTTP accept-type header
	 */
	public ClientRequest(String uri, String userAgent, String acceptTypes) {
		this.baseUri = uri;
		this.userAgent = userAgent;
		this.acceptTypes = acceptTypes;
	}
	
	/**
	 * Performs HTTP request and returns the associated response.
	 * 
	 * @param method		HTTP method to execute
	 * @param resource		Resource parameter(s) to append to baseUri
	 * @param payload		Optional request payload to send in HTTP body
	 * @return				Parsed client response
	 * @throws IOException	Occurs if HTTP IOException encountered
	 */
	public ClientResponse sendRequest(Method method, String resource, byte[] payload) throws IOException {
		ClientResponse clientResp = null;
		
		if (resource == null || resource.length() <= 0) {
			resource ="";
		}
	    else {
	    	if (resource.charAt(0) == '/' && resource.length() >= 2) {
	    		resource = resource.substring(1);
	        }
	    	resource = (resource.charAt(resource.length()-1) == '/') ? resource.substring(0, resource.length()-1) : resource;
	    }

	    final String url = this.baseUri + "/" + resource;
	        
	    long beginMS = System.currentTimeMillis();
	    Log.d(TAG, "HTTP ["+ method +"] to "+ url + " at time (ms): " + beginMS);
	    
	    URI uri = URI.create(url);
        <commit_msg>Overloaded for ease of use wrapper<commit_after>package com.cjbarker.wb.ws;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.HttpVersion;
import org.apache.http.StatusLine;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.conn.params.ConnManagerParams;
import org.apache.http.conn.params.ConnPerRoute;
import org.apache.http.conn.params.ConnPerRouteBean;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicHeader;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.http.params.HttpProtocolParams;

import android.util.Log;

/**
 * Class provides HTTP request/response handling for weather API clients.
 * 
 * @author <NAME>
 */
public class ClientRequest {
	
	// static vars
	private static final String TAG = "HttpClient";
	private static final String DEFAULT_USER_AGENT = "WB/1.0";
	private static final String DEFAULT_ACCEPT_TYPES = "application/json,application/xml";
	public static enum Method { GET };
	
	// predefined headers
	private static final BasicHeader HEADER_CONTENT_TYPE = 
			new BasicHeader("Content-Type", "application/xml");
	private static final BasicHeader HEADER_ACCEPT = 
			new BasicHeader("Accept", "application/xml");
	private static final BasicHeader HEADER_CONNECTION = 
			new BasicHeader("Connection", "Keep-Alive");
	private static final BasicHeader HEADER_CACHE_CONTROL = 
			new BasicHeader("Cache-Control", "no-cache");
	private static final BasicHeader HEADER_PRAGMA = 
			new BasicHeader("Pragma", "no-cache");

	// member vars
	private String baseUri;
	private String userAgent;		 
	private String acceptTypes;
	
	private ClientRequest() {}
	
	/**
	 * Default constructor
	 * @param uri	URI to perform HTTP request on
	 */
	public ClientRequest(String uri) {
		this(uri, DEFAULT_USER_AGENT);
	}
	
	/**
	 * Constructor
	 * @param uri		URI to perform HTTP request on
	 * @param userAgent HTTP user-agent header
	 */
	public ClientRequest(String uri, String userAgent) {
		this(uri, DEFAULT_USER_AGENT, DEFAULT_ACCEPT_TYPES);
	}
	
	/**
	 * Constructor
	 * @param uri			URI to perform HTTP request on
	 * @param userAgent 	HTTP user-agent header
	 * @param acceptTypes	HTTP accept-type header
	 */
	public ClientRequest(String uri, String userAgent, String acceptTypes) {
		this.baseUri = uri;
		this.userAgent = userAgent;
		this.acceptTypes = acceptTypes;
	}
	
	public ClientResponse sendRequest(Method method) throws IOException {
		return sendRequest(method, null, null);
	}
	
	public ClientResponse sendRequest(Method method, String resource) throws IOException {
		return sendRequest(method, resource, null);
	}
	
	/**
	 * Performs HTTP request and returns the associated response.
	 * 
	 * @param method		HTTP method to execute
	 * @param resource		Resource parameter(s) to append to baseUri
	 * @param payload		Optional request payload to send in HTTP body
	 * @return				Parsed client response
	 * @throws IOException	Occurs if HTTP IOException encountered
	 */
	public ClientResponse sendRequest(Method method, String resource, byte[] payload) throws IOException {
		ClientResponse clientResp = null;
		
		if (resource == null || resource.length() <= 0) {
			resource ="";
		}
	    else {
	    	if (resource.charAt(0) == '/' && resource.length() >= 2) {
	    		resource = resource.substring(1);
	        }
	    	resource = (resource.charAt(resource.length()-1) == '/') ? resource.substring(0, resource.length()-1) : resource;
	    }

	    final String url = this.baseUri + "/" + resource;
	        
	    long beginMS = System.currentTimeMillis();
	    Log.d(TAG, "HTTP ["+ method +"] to "+ url + " at time (ms): " + beginMS);
	    
	    URI uri = URI.create(url);
        
{'fraction_non_alphanumeric': 0.10655138821237214, 'fraction_numerical': 0.00219191427179737, 'mean_word_length': 4.126716604244694, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, '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': '6876302', 'n_tokens_mistral': 2542, 'n_tokens_neox': 2367, 'n_words': 653}