<commit_before>package org.javarosa.services.transport.download;

import java.io.DataInputStream;
import java.io.IOException;
import java.util.Date;

import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;

import org.javarosa.services.transport.impl.TransportMessageStatus;
import org.javarosa.services.transport.listeners.IGetTransportMessage;
import org.javarosa.services.transport.listeners.IGetTransporter;
import org.javarosa.services.transport.util.StreamsUtil;

public class HttpGetTransporter implements IGetTransporter {

	private Date downloadWatchDate;
	private HttpGetTransportMessage message;
	
	public HttpGetTransporter() {
		
	}
	
	public IGetTransportMessage get() {
		
		byte[] data = null;
		HttpConnection conn = null;
		try{
			conn = getConnection(message.geDestinationURL());
			
			if(conn.getResponseCode() == HttpConnection.HTTP_OK){
				data = readFromConnection(conn);
				
				message = setMessageDetail(message, data);
			}
			
			conn.close();
			
		}catch(Exception e){
			System.out.println("Connection to the server has failed: " + e.getMessage());
			message.setFailureReason(e.getMessage());
		}
		finally{
			if(conn != null)
				try{
					conn.close();
				}
			catch(IOException e){
				e.printStackTrace();
			}
		}
		
		return message;
	}

	private HttpGetTransportMessage setMessageDetail(HttpGetTransportMessage message, byte[] data) {
		
		HttpGetTransportMessage downloadedMessage = message;
		
		downloadedMessage.setContent(data);
		downloadedMessage.setDownloadedDate(downloadWatchDate.getTime());
		downloadedMessage.setStatus(TransportMessageStatus.DOWNLOADED);
		
		return downloadedMessage;
	}

	private byte[] readFromConnection(HttpConnection conn) throws Exception {
		
		byte[] data = null;
		DataInputStream in = null;
		try{
			in = conn.openDataInputStream();
			System.out.println("Reading from URL: " + conn.getURL());
			
			data = StreamsUtil.readFromStream(in);
			
		}
		catch(Exception e){
			e.printStackTrace();
			throw e;
		}
		finally{
			if(in != null){
				in.close();
			}
		}
		
		return data;
		<commit_msg>Method name change - setContent() to setReturnedData()<commit_after>package org.javarosa.services.transport.download;

import java.io.DataInputStream;
import java.io.IOException;
import java.util.Date;

import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;

import org.javarosa.services.transport.impl.TransportMessageStatus;
import org.javarosa.services.transport.listeners.IGetTransportMessage;
import org.javarosa.services.transport.listeners.IGetTransporter;
import org.javarosa.services.transport.util.StreamsUtil;

public class HttpGetTransporter implements IGetTransporter {

	private Date downloadWatchDate;
	private HttpGetTransportMessage message;
	
	public HttpGetTransporter() {
		
	}
	
	public IGetTransportMessage get() {
		
		byte[] data = null;
		HttpConnection conn = null;
		try{
			conn = getConnection(message.geDestinationURL());
			
			if(conn.getResponseCode() == HttpConnection.HTTP_OK){
				data = readFromConnection(conn);
				
				message = setMessageDetail(message, data);
			}
			
			conn.close();
			
		}catch(Exception e){
			System.out.println("Connection to the server has failed: " + e.getMessage());
			message.setFailureReason(e.getMessage());
		}
		finally{
			if(conn != null)
				try{
					conn.close();
				}
			catch(IOException e){
				e.printStackTrace();
			}
		}
		
		return message;
	}

	private HttpGetTransportMessage setMessageDetail(HttpGetTransportMessage message, byte[] data) {
		
		HttpGetTransportMessage downloadedMessage = message;
		
		downloadedMessage.setReturnedContent(data);
		downloadedMessage.setDownloadedDate(downloadWatchDate.getTime());
		downloadedMessage.setStatus(TransportMessageStatus.DOWNLOADED);
		
		return downloadedMessage;
	}

	private byte[] readFromConnection(HttpConnection conn) throws Exception {
		
		byte[] data = null;
		DataInputStream in = null;
		try{
			in = conn.openDataInputStream();
			System.out.println("Reading from URL: " + conn.getURL());
			
			data = StreamsUtil.readFromStream(in);
			
		}
		catch(Exception e){
			e.printStackTrace();
			throw e;
		}
		finally{
			if(in != null){
				in.close();
			}
		}
		
		return data;
		
{'fraction_non_alphanumeric': 0.1064327485380117, 'fraction_numerical': 0.0, 'mean_word_length': 4.240196078431373, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5017727', 'n_tokens_mistral': 1503, 'n_tokens_neox': 1245, 'n_words': 243}