<commit_before>package uk.ac.ebi.quickgo.annotation.download.http;

import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Map;
import org.springframework.http.MediaType;

/**
 * Hold the definitions of MediaTypes used in downloads, and their components.
 * @author <NAME>
 * Date: 27/04/2017
 * Time: 10:38
 * Created with IntelliJ IDEA.
 */
public class MediaTypeFactory {
    private static final String TEXT_TYPE = "text";
    private static final String APPLICATION_TYPE = "application";
    private static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8");

    public static final String TSV_SUB_TYPE = "tsv";
    public static final String GAF_SUB_TYPE = "gaf";
    public static final String GPAD_SUB_TYPE = "gpad";
    public static final String EXCEL_SUB_TYPE = "vnd.ms-excel";
    public static final String JSON_SUB_TYPE = "json";

    public static final String TSV_MEDIA_TYPE_STRING = TEXT_TYPE + "/" + TSV_SUB_TYPE;
    public static final String GAF_MEDIA_TYPE_STRING = TEXT_TYPE + "/" + GAF_SUB_TYPE;
    public static final String GPAD_MEDIA_TYPE_STRING = TEXT_TYPE + "/" + GPAD_SUB_TYPE;
    public static final String EXCEL_MEDIA_TYPE_STRING = APPLICATION_TYPE + "/" + EXCEL_SUB_TYPE;
    public static final String JSON_MEDIA_TYPE_STRING = APPLICATION_TYPE + "/" + JSON_SUB_TYPE;

    public static final MediaType TSV_MEDIA_TYPE = new MediaType(TEXT_TYPE, TSV_SUB_TYPE, DEFAULT_CHARSET);
    public static final MediaType GAF_MEDIA_TYPE = new MediaType(TEXT_TYPE, GAF_SUB_TYPE, DEFAULT_CHARSET);
    public static final MediaType GPAD_MEDIA_TYPE = new MediaType(TEXT_TYPE, GPAD_SUB_TYPE, DEFAULT_CHARSET);

    public static final MediaType EXCEL_MEDIA_TYPE = new MediaType(APPLICATION_TYPE, EXCEL_SUB_TYPE);
    public static final MediaType JSON_MEDIA_TYPE = new MediaType(APPLICATION_TYPE, JSON_SUB_TYPE);

    public static Map<MediaType, String> MEDIA_TYPE_TO_FILE_EXTENSIONS = new HashMap<>();

    static {
        MEDIA_TYPE_TO_FILE_EXTENSIONS.put(TSV_MEDIA_TYPE, TSV_SUB_TYPE);
        MEDIA_TYPE_TO_FILE_EXTENSIONS.put(GAF_MEDIA_TYPE, GAF_SUB_TYPE);
        MEDIA_TYPE_TO_FILE_EXTENSIONS.put(GPAD_MEDIA_TYPE, GPAD_SUB_TYPE);
        MEDIA_TYPE_TO_FILE_EXTENSIONS.put(EXCEL_MEDIA_TYPE, "xls");
        MEDIA_TYPE_TO_FILE_EXTENSIONS.put(JSON_MEDIA_TYPE, JSON_SUB_TYPE);
    }

}<commit_msg>Add fileExtension method to generate file extension based on media type.<commit_after>package uk.ac.ebi.quickgo.annotation.download.http;

import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Map;
import org.springframework.http.MediaType;

/**
 * Hold the definitions of MediaTypes used in downloads, and their components.
 * @author <NAME>
 * Date: 27/04/2017
 * Time: 10:38
 * Created with IntelliJ IDEA.
 */
public class MediaTypeFactory {
    private static final String TEXT_TYPE = "text";
    private static final String APPLICATION_TYPE = "application";
    private static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8");

    public static final String TSV_SUB_TYPE = "tsv";
    public static final String GAF_SUB_TYPE = "gaf";
    public static final String GPAD_SUB_TYPE = "gpad";
    public static final String EXCEL_SUB_TYPE = "vnd.ms-excel";
    public static final String JSON_SUB_TYPE = "json";

    public static final String TSV_MEDIA_TYPE_STRING = TEXT_TYPE + "/" + TSV_SUB_TYPE;
    public static final String GAF_MEDIA_TYPE_STRING = TEXT_TYPE + "/" + GAF_SUB_TYPE;
    public static final String GPAD_MEDIA_TYPE_STRING = TEXT_TYPE + "/" + GPAD_SUB_TYPE;
    public static final String EXCEL_MEDIA_TYPE_STRING = APPLICATION_TYPE + "/" + EXCEL_SUB_TYPE;
    public static final String JSON_MEDIA_TYPE_STRING = APPLICATION_TYPE + "/" + JSON_SUB_TYPE;

    public static final MediaType TSV_MEDIA_TYPE = new MediaType(TEXT_TYPE, TSV_SUB_TYPE, DEFAULT_CHARSET);
    public static final MediaType GAF_MEDIA_TYPE = new MediaType(TEXT_TYPE, GAF_SUB_TYPE, DEFAULT_CHARSET);
    public static final MediaType GPAD_MEDIA_TYPE = new MediaType(TEXT_TYPE, GPAD_SUB_TYPE, DEFAULT_CHARSET);

    public static final MediaType EXCEL_MEDIA_TYPE = new MediaType(APPLICATION_TYPE, EXCEL_SUB_TYPE);
    public static final MediaType JSON_MEDIA_TYPE = new MediaType(APPLICATION_TYPE, JSON_SUB_TYPE);

    private static Map<MediaType, String> MEDIA_TYPE_TO_FILE_EXTENSIONS = new HashMap<>();

    static {
        MEDIA_TYPE_TO_FILE_EXTENSIONS.put(TSV_MEDIA_TYPE, TSV_SUB_TYPE);
        MEDIA_TYPE_TO_FILE_EXTENSIONS.put(GAF_MEDIA_TYPE, GAF_SUB_TYPE);
        MEDIA_TYPE_TO_FILE_EXTENSIONS.put(GPAD_MEDIA_TYPE, GPAD_SUB_TYPE);
        MEDIA_TYPE_TO_FILE_EXTENSIONS.put(EXCEL_MEDIA_TYPE, "xls");
        MEDIA_TYPE_TO_FILE_EXTENSIONS.put(JSON_MEDIA_TYPE, JSON_SUB_TYPE);
    }

    public static String fileExtension(MediaType mediaType){
        return MEDIA_TYPE_TO_FILE_EXTENSIONS.get(mediaType);
    }

}
{'fraction_non_alphanumeric': 0.07796193984039287, 'fraction_numerical': 0.005320237364436259, 'mean_word_length': 4.875, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1224696', 'n_tokens_mistral': 1672, 'n_tokens_neox': 1601, 'n_words': 373}