<commit_before>/**
 * 
 */
package nl.idgis.downloadtool.downloader;

import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpEntity;
import org.apache.http.StatusLine;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import nl.idgis.downloadtool.domain.AdditionalData;

/**
 * This class represents a file as the source of the download.<br>
 * It is constructed with a url that represents the source and then provides an
 * inputstream from that url.<br>
 * 
 * @author Rob
 * 
 */
public class DownloadFile implements DownloadSource {
	private static final Log log = LogFactory.getLog(DownloadFile.class);
	
	private final URI uri;
	private HttpEntity entity;
	private CloseableHttpResponse response; 
	private final CloseableHttpClient httpclient;
	private final HttpGet httpGet;
	

	/**
	 * Constructor that builds a file download request.
	 * @param additionalData containing all information for the building the request
	 * @throws MalformedURLException
	 * @throws UnsupportedEncodingException
	 * @throws URISyntaxException 
	 */
	public DownloadFile(AdditionalData additionalData) throws MalformedURLException,
			UnsupportedEncodingException, URISyntaxException {
		String serviceUrl = additionalData.getUrl();
		uri = new URL(serviceUrl).toURI();
		httpGet = new HttpGet(uri);

		// no authentication foreseen<commit_msg>Replace spaces in additional data url<commit_after>/**
 * 
 */
package nl.idgis.downloadtool.downloader;

import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpEntity;
import org.apache.http.StatusLine;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import nl.idgis.downloadtool.domain.AdditionalData;

/**
 * This class represents a file as the source of the download.<br>
 * It is constructed with a url that represents the source and then provides an
 * inputstream from that url.<br>
 * 
 * @author Rob
 * 
 */
public class DownloadFile implements DownloadSource {
	private static final Log log = LogFactory.getLog(DownloadFile.class);
	
	private final URI uri;
	private HttpEntity entity;
	private CloseableHttpResponse response; 
	private final CloseableHttpClient httpclient;
	private final HttpGet httpGet;
	

	/**
	 * Constructor that builds a file download request.
	 * @param additionalData containing all information for the building the request
	 * @throws MalformedURLException
	 * @throws UnsupportedEncodingException
	 * @throws URISyntaxException 
	 */
	public DownloadFile(AdditionalData additionalData) throws MalformedURLException,
			UnsupportedEncodingException, URISyntaxException {
		String serviceUrl = additionalData.getUrl();
		uri = new URL(serviceUrl.replace(" ", "%20")).toURI();
		httpGet = new HttpGet(uri);

		// no authentication foreseen
{'fraction_non_alphanumeric': 0.08790401567091087, 'fraction_numerical': 0.0004897159647404506, 'mean_word_length': 5.372854914196568, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6348402', 'n_tokens_mistral': 1164, 'n_tokens_neox': 1124, 'n_words': 299}