<commit_before>package ca.corefacility.bioinformatics.irida.repositories.remote.impl;

import java.nio.file.Path;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.stereotype.Repository;

import ca.corefacility.bioinformatics.irida.model.RemoteAPI;
import ca.corefacility.bioinformatics.irida.model.remote.RemoteSequenceFile;
import ca.corefacility.bioinformatics.irida.model.remote.resource.ListResourceWrapper;
import ca.corefacility.bioinformatics.irida.model.remote.resource.ResourceWrapper;
import ca.corefacility.bioinformatics.irida.repositories.remote.SequenceFileRemoteRepository;
import ca.corefacility.bioinformatics.irida.repositories.remote.resttemplate.OAuthTokenRestTemplate;
import ca.corefacility.bioinformatics.irida.repositories.remote.resttemplate.SequenceFileMessageConverter;
import ca.corefacility.bioinformatics.irida.service.RemoteAPITokenService;

import com.google.common.collect.Lists;

/**
 * Implementation of {@link SequenceFileRemoteRepository}
 * 
 * @author <NAME> <<EMAIL>>
 *
 */
@Repository
public class SequenceFileRemoteRepositoryImpl extends RemoteRepositoryImpl<RemoteSequenceFile> implements
		SequenceFileRemoteRepository {
	private static final ParameterizedTypeReference<ListResourceWrapper<RemoteSequenceFile>> listTypeReference = new ParameterizedTypeReference<ListResourceWrapper<RemoteSequenceFile>>() {
	};

	private static final ParameterizedTypeReference<ResourceWrapper<RemoteSequenceFile>> objectTypeReference = new ParameterizedTypeReference<ResourceWrapper<RemoteSequenceFile>>() {
	};

	private final Path tempDirectory;

	@Autowired
	public SequenceFileRemoteRepositoryImpl(RemoteAPITokenService tokenService,
			@Qualifier("remoteFilesTempDirectory") Path tempDirectory) {
		super(tokenService, listTypeReference, objectTypeReference);
		this.tempDirectory = tempDirectory;
	}

	public void downloadFile(String url, RemoteAPI api) {
		OAuthTokenRestTemplate restTemplate = new OAuthTokenRestTemplate(getTokenService(), api);

		// add the sequence file message converter
		List<HttpMessageConverter<?>> converters = restTemplate.getMessageConverters();
		converters.add(new SequenceFileMessageConverter(tempDirectory));
		restTemplate.setMessageConverters(converters);

		// add the application/fastq accept header
		HttpHeaders requestHeaders = new HttpHeaders();
		requestHeaders.setAccept(Lists.newArrayList(new MediaType("application", "fastq")));
		HttpEntity<Path> requestEntity = new HttpEntity<Path>(requestHeaders);

		ResponseEntity<Path> exchange = restTemplate.exchange(url, HttpMethod.GET, requestEntity, Path.class);
		System.out.println(exchange);
	}

}<commit_msg>updated function and added comments<commit_after>package ca.corefacility.bioinformatics.irida.repositories.remote.impl;

import java.nio.file.Path;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.security.core.token.TokenService;
import org.springframework.stereotype.Repository;

import ca.corefacility.bioinformatics.irida.model.RemoteAPI;
import ca.corefacility.bioinformatics.irida.model.remote.RemoteSequenceFile;
import ca.corefacility.bioinformatics.irida.model.remote.resource.ListResourceWrapper;
import ca.corefacility.bioinformatics.irida.model.remote.resource.RemoteResource;
import ca.corefacility.bioinformatics.irida.model.remote.resource.ResourceWrapper;
import ca.corefacility.bioinformatics.irida.repositories.remote.SequenceFileRemoteRepository;
import ca.corefacility.bioinformatics.irida.repositories.remote.resttemplate.OAuthTokenRestTemplate;
import ca.corefacility.bioinformatics.irida.repositories.remote.resttemplate.SequenceFileMessageConverter;
import ca.corefacility.bioinformatics.irida.service.RemoteAPITokenService;

import com.google.common.collect.Lists;

/**
 * Implementation of {@link SequenceFileRemoteRepository}
 * 
 * @author <NAME> <<EMAIL>>
 *
 */
@Repository
public class SequenceFileRemoteRepositoryImpl extends RemoteRepositoryImpl<RemoteSequenceFile> implements
		SequenceFileRemoteRepository {
	private static final ParameterizedTypeReference<ListResourceWrapper<RemoteSequenceFile>> listTypeReference = new ParameterizedTypeReference<ListResourceWrapper<RemoteSequenceFile>>() {
	};

	private static final ParameterizedTypeReference<ResourceWrapper<RemoteSequenceFile>> objectTypeReference = new ParameterizedTypeReference<ResourceWrapper<RemoteSequenceFile>>() {
	};

	private final Path tempDirectory;

	/**
	 * Create a new SequenceFileRemoteRepositoryImpl
	 * 
	 * @param tokenService
	 *            The {@link TokenService} storing OAuth2 tokens
	 * @param tempDirectory
	 *            The temporary directory to store downloaded files
	 */
	@Autowired
	public SequenceFileRemoteRepositoryImpl(RemoteAPITokenService tokenService,
			@Qualifier("remoteFilesTempDirectory") Path tempDirectory) {
		super(tokenService, listTypeReference, objectTypeReference);
		this.tempDirectory = tempDirectory;
	}

	/**
	 * {@inheritDoc}
	 */
	public Path downloadRemoteSequenceFile(RemoteSequenceFile sequenceFile, RemoteAPI remoteAPI) {
		OAuthTokenRestTemplate restTemplate = new OAuthTokenRestTemplate(getTokenService(), remoteAPI);

		// get the resource's URI
		String uri = sequenceFile.getHrefForRel(RemoteResource.SELF_REL);

		// add the sequence file message converter
		List<HttpMessageConverter<?>> converters = restTemplate.getMessageConverters();
		converters.add(new SequenceFileMessageConverter(tempDirectory));
		restTemplate.setMessageConverters(converters);

		// add the application/fastq accept header
		HttpHeaders requestHeaders = new HttpHeaders();
		requestHeaders.setAccept(Lists.newArrayList(new MediaType("application", "fastq")));
		HttpEntity<Path> requestEntity = new HttpEntity<Path>(requestHeaders);

		// get the file
		ResponseEntity<Path> exchange = restTemplate.exchange(uri, HttpMethod.GET, requestEntity, Path.class);
		return exchange.getBody();
	}

}
{'fraction_non_alphanumeric': 0.08840345990324, 'fraction_numerical': 0.00014660606949127694, 'mean_word_length': 7.495641344956414, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '836788', 'n_tokens_mistral': 1867, 'n_tokens_neox': 1746, 'n_words': 311}