<commit_before>package org.lightmare.rest.utils;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import javax.ws.rs.core.MediaType;
import javax.ws.rs.ext.MessageBodyReader;

import org.glassfish.jersey.message.MessageBodyWorkers;
import org.glassfish.jersey.server.model.Parameter;
import org.lightmare.utils.ObjectUtils;

/**
 * Utility class to extract parameters from REST request
 * 
 * @author levan
 * 
 */
public class RequestUtils {

    private static final int EMPRTY_LENGTH = 0;

    public static Object[] getEmptyArray() {

	return new Object[EMPRTY_LENGTH];
    }

    public static InputStream textToStream(String text) {

	return new ByteArrayInputStream(text.getBytes());
    }

    public static List<InputStream> textsToStreams(Collection<String> params) {

	List<InputStream> streams = new ArrayList<InputStream>();
	if (ObjectUtils.available(params)) {
	    InputStream stream;
	    for (String param : params) {
		stream = textToStream(param);
		streams.add(stream);
	    }
	}

	return streams;
    }

    /**
     * Gets appropriated {@link MessageBodyReader} for passed
     * {@link MessageBodyWorkers} {@link Parameter} and {@link MediaType}
     * arguments
     * 
     * @param workers
     * @param parameter
     * @param mediaType
     * @return {@link MessageBodyReader}<commit_msg>added comments to RequestUtils.textsToStreams method <commit_after>package org.lightmare.rest.utils;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import javax.ws.rs.core.MediaType;
import javax.ws.rs.ext.MessageBodyReader;

import org.glassfish.jersey.message.MessageBodyWorkers;
import org.glassfish.jersey.server.model.Parameter;
import org.lightmare.utils.ObjectUtils;

/**
 * Utility class to extract parameters from REST request
 * 
 * @author levan
 * 
 */
public class RequestUtils {

    private static final int EMPRTY_LENGTH = 0;

    public static Object[] getEmptyArray() {

	return new Object[EMPRTY_LENGTH];
    }

    public static InputStream textToStream(String text) {

	return new ByteArrayInputStream(text.getBytes());
    }

    /**
     * Converts {@link Collection} of {@link String}s to {@link List} of
     * {@link InputStream}s for reading appropriate parameters
     * 
     * @param params
     * @return {@link List}<InputStream>
     */
    public static List<InputStream> textsToStreams(Collection<String> params) {

	List<InputStream> streams = new ArrayList<InputStream>();
	if (ObjectUtils.available(params)) {
	    InputStream stream;
	    for (String param : params) {
		stream = textToStream(param);
		streams.add(stream);
	    }
	}

	return streams;
    }

    /**
     * Gets appropriated {@link MessageBodyReader} for passed
     * {@link MessageBodyWorkers} {@link Parameter} and {@link MediaType}
     * arguments
     * 
     * @param workers
     * @param parameter
     * @param mediaType
     * @return {@link MessageBodyReader}
{'fraction_non_alphanumeric': 0.10478654592496765, 'fraction_numerical': 0.000646830530401035, 'mean_word_length': 3.7879256965944275, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '4624061', 'n_tokens_mistral': 924, 'n_tokens_neox': 876, 'n_words': 227}