<commit_before>package mapper_wrapper;

import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.model.ObjectMetadata;
import com.amazonaws.services.s3.model.S3Object;
import com.amazonaws.services.s3.model.S3ObjectInputStream;
import com.amazonaws.util.StringInputStream;
import mapper_logic.MapperLogic;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.List;

public class MapperWrapper implements RequestHandler<MapperWrapperInfo, String> {

    @Override
    public String handleRequest(MapperWrapperInfo mapperWrapperInfo, Context context) {

        try {
            AmazonS3 s3Client = AmazonS3ClientBuilder.standard().build();
            List<String> batch = mapperWrapperInfo.getBatch();


            for (String key : batch) {
                String processResult = processKey(mapperWrapperInfo, s3Client, key);
                storeResult(mapperWrapperInfo, s3Client, processResult, key);

            }

        } catch (Exception e) {
            e.printStackTrace();
        }
        return "OK";
    }

    private void storeResult(MapperWrapperInfo mapperWrapperInfo, AmazonS3 s3Client, String result, String key) throws UnsupportedEncodingException {
        ObjectMetadata metadata = new ObjectMetadata();
        metadata.setContentType("text/plain");
        metadata.setContentLength(result.getBytes().length);
        s3Client.putObject(mapperWrapperInfo.getOutputBucket(),
                key + "-" + mapperWrapperInfo.getId(),
                new StringInputStream(result),
                metadata);
    }

    private String processKey(MapperWrapperInfo mapperWrapperInfo, AmazonS3 s3Client, String key) throws IOException {
        S3Object object = s3Client.getObject(mapperWrapperInfo.getInputBucket(), key);
        S3ObjectInputStream objectContentRawStream = object.getObjectContent();
        BufferedReader objectBufferedReader = new BufferedReader(new InputStreamReader(objectContentRawStream));


        String result = MapperLogic.mapResultCalculator(objectBufferedReader);

        objectBufferedReader.close();
        objectContentRawStream.close();
        object.close();

        return result;
    }

}
<commit_msg>Changed map output content type to application/json<commit_after>package mapper_wrapper;

import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.model.ObjectMetadata;
import com.amazonaws.services.s3.model.S3Object;
import com.amazonaws.services.s3.model.S3ObjectInputStream;
import com.amazonaws.util.StringInputStream;
import mapper_logic.MapperLogic;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.List;

public class MapperWrapper implements RequestHandler<MapperWrapperInfo, String> {

    @Override
    public String handleRequest(MapperWrapperInfo mapperWrapperInfo, Context context) {

        try {
            AmazonS3 s3Client = AmazonS3ClientBuilder.standard().build();
            List<String> batch = mapperWrapperInfo.getBatch();


            for (String key : batch) {
                String processResult = processKey(mapperWrapperInfo, s3Client, key);
                storeResult(mapperWrapperInfo, s3Client, processResult, key);

            }

        } catch (Exception e) {
            e.printStackTrace();
        }
        return "OK";
    }

    private void storeResult(MapperWrapperInfo mapperWrapperInfo, AmazonS3 s3Client, String result, String key) throws UnsupportedEncodingException {
        ObjectMetadata metadata = new ObjectMetadata();
        metadata.setContentType("application/json");
        metadata.setContentLength(result.getBytes().length);
        s3Client.putObject(mapperWrapperInfo.getOutputBucket(),
                key + "-" + mapperWrapperInfo.getId(),
                new StringInputStream(result),
                metadata);
    }

    private String processKey(MapperWrapperInfo mapperWrapperInfo, AmazonS3 s3Client, String key) throws IOException {
        S3Object object = s3Client.getObject(mapperWrapperInfo.getInputBucket(), key);
        S3ObjectInputStream objectContentRawStream = object.getObjectContent();
        BufferedReader objectBufferedReader = new BufferedReader(new InputStreamReader(objectContentRawStream));


        String result = MapperLogic.mapResultCalculator(objectBufferedReader);

        objectBufferedReader.close();
        objectContentRawStream.close();
        object.close();

        return result;
    }

}

{'fraction_non_alphanumeric': 0.0851792186870721, 'fraction_numerical': 0.008860249697946033, 'mean_word_length': 3.668233082706767, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4150757', 'n_tokens_mistral': 1299, 'n_tokens_neox': 1276, 'n_words': 252}