<commit_before>package org.eck.middlewares;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.eck.LocomotiveRequestWrapper;
import org.eck.LocomotiveResponseWrapper;

public class LocomotiveAssetsMiddleware implements LocomotiveMiddleware {

    private String assetsFolder;

    public LocomotiveAssetsMiddleware(String assetsFolder) {
        super();
        this.assetsFolder = assetsFolder;
    }

    @Override
    public void execute(LocomotiveRequestWrapper req,
            LocomotiveResponseWrapper resp) {

        InputStream resourceAsStream = LocomotiveAssetsMiddleware.class
                .getClassLoader().getResourceAsStream(assetsFolder + req.uri());
        if (resourceAsStream != null) {
            BufferedReader reader = new BufferedReader(new InputStreamReader(
                    resourceAsStream));
            StringBuilder out = new StringBuilder();
            String line;
            try {
                while ((line = reader.readLine()) != null) {
                    out.append(line);
                }
                req.processed();
                resp.send(out.toString());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }

}<commit_msg>Reading files async<commit_after>package org.eck.middlewares;

import java.net.URI;
import java.net.URL;
import java.nio.ByteBuffer;
import java.nio.channels.AsynchronousFileChannel;
import java.nio.channels.CompletionHandler;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;

import org.eck.LocomotiveRequestWrapper;
import org.eck.LocomotiveResponseWrapper;

public class LocomotiveAssetsMiddleware implements LocomotiveMiddleware {

    private String assetsFolder;

    public LocomotiveAssetsMiddleware(String assetsFolder) {
        super();
        this.assetsFolder = assetsFolder;
    }

    @Override
    public void execute(LocomotiveRequestWrapper req,
            LocomotiveResponseWrapper resp) {

        try {
            URL resource = LocomotiveAssetsMiddleware.class.getClassLoader()
                    .getResource(assetsFolder + req.uri());

            if (resource != null) {
                req.processed();
                URI uri = resource.toURI();
                Path path = Paths.get(uri);

                final AsynchronousFileChannel channel = AsynchronousFileChannel
                        .open(path);
                final ByteBuffer buffer = ByteBuffer.allocate(100000);

                channel.read(buffer, 0, buffer,
                        new CompletionHandler<Integer, ByteBuffer>() {
                            public void completed(Integer result,
                                    ByteBuffer attachment) {
                                byte[] array = attachment.array();
                                resp.send(new String(Arrays.copyOf(array, result)));
                            }

                            public void failed(Throwable exception,
                                    ByteBuffer attachment) {
                                resp.status(500);
                                resp.send(exception.getMessage());
                            }
                        });

            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

}
{'fraction_non_alphanumeric': 0.07967193907439953, 'fraction_numerical': 0.0029291154071470417, 'mean_word_length': 1.8106995884773662, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5217270', 'n_tokens_mistral': 838, 'n_tokens_neox': 800, 'n_words': 171}