<commit_before>package de.saumya.mojo.proxy;

import java.io.FileNotFoundException;
import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ControllerServlet extends HttpServlet {

    private static final long serialVersionUID = -1377408089637782007L;

    private ControllerService controller;

    @Override
    public void init() throws ServletException {
        super.init();
        this.controller = (ControllerService) getServletContext().getAttribute(ControllerService.class.getName());
    }

    @Override
    protected void doGet(final HttpServletRequest req,
            final HttpServletResponse resp) throws ServletException,
            IOException {
        final String[] parts = req.getPathInfo().substring(1).split("/");
        // System.out.println(Arrays.toString(parts));
        try {
            switch (parts.length) {
            case 4: // {releases|prereleases}/rubygems/#{name}/maven-metadata.xml
                if (parts[3].equals("maven-metadata.xml")) {
                    resp.setContentType("application/xml");
                    resp.setCharacterEncoding("utf-8");
                    resp.setHeader("Vary", "Accept");
                    this.controller.writeMetaData(parts[2],
                                                  resp.getWriter(),
                                                  "prereleases".equals(parts[0]));
                }
                else if (parts[3].equals("maven-metadata.xml.sha1")) {
                    resp.setContentType("text/plain");
                    resp.setCharacterEncoding("ASCII");
                    this.controller.writeMetaDataSHA1(parts[2],
                                                      resp.getWriter(),
                                                      "prereleases".equals(parts[0]));
                }
                else {
                    notFound(resp);
                }
                break;
            case 5:// {releases|prereleases}/rubygems/#{name}/#{version}/#{name}-#{version}.{gem|pom}
                if (parts[4].endsWith(".gem")) {
                    resp.sendRedirect(this.controller.getGemLocation(parts[2],
                                                                     parts[3]));
                }
                else if (parts[4].endsWith(".gem.sha1")) {
                    resp.setContentType("text/plain");
                    resp.setCharacterEncoding("ASCII");
                    this.controller.writeGemSHA1(parts[2],
                                                 parts[3],
                                                 resp.getWriter());
                }
                else if (parts[4].endsWith(".pom")) {
                    resp.setContentType("application/xml");
                    resp.setCharacterEncoding("UTF-8");
                    this.controller.writePom(parts[2],
                                             parts[3],
                                             resp.getWriter());
                }
                else if (parts[4].endsWith(".pom.sha1")) {
                    resp.setContentType("text/plain");
                    resp.setCharacterEncoding("ASCII");
                    this.controller.writePomSHA1(parts[2],
                                                 parts[3],
                                                 resp.getWriter());
                }
                else {
                    notFound(resp);
                }
                break;
            default:
                notFound(resp);
            }
        }
        catch (final FileNotFoundException e) {
            notFound(resp);
        }
    }

    private void notFound(final HttpServletResponse resp) throws IOException {
        resp.sendError(HttpServletResponse.SC_NOT_FOUND);
    }

    @Override
    protected void doHead(final HttpServletRequest req,
            final HttpServletResponse resp) throws ServletException,
            IOException {
        // TODO Auto-generated method stub
        super.doHead(req, resp);
    }

    @Override
    protected long getLastModified(final HttpServletRequest req) {
        // TODO Auto-generated method stub
        return super.getLastModified(req);
    }

}<commit_msg>cleanup<commit_after>package de.saumya.mojo.proxy;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Arrays;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ControllerServlet extends HttpServlet {

    private static final long serialVersionUID = -1377408089637782007L;

    private ControllerService controller;

    @Override
    public void init() throws ServletException {
        super.init();
        this.controller = (ControllerService) getServletContext().getAttribute(ControllerService.class.getName());
    }

    @Override
    protected void doGet(final HttpServletRequest req,
            final HttpServletResponse resp) throws ServletException,
            IOException {
        final String[] parts = req.getPathInfo().substring(1).split("/");
        //System.out.println(Arrays.toString(parts));
        try {
            switch (parts.length) {
            case 4: // {releases|prereleases}/rubygems/#{name}/maven-metadata.xml
                if (parts[3].equals("maven-metadata.xml")) {
                    resp.setContentType("application/xml");
                    resp.setCharacterEncoding("utf-8");
                    resp.setHeader("Vary", "Accept");
                    this.controller.writeMetaData(parts[2],
                                                  resp.getWriter(),
                                                  "prereleases".equals(parts[0]));
                }
                else if (parts[3].equals("maven-metadata.xml.sha1")) {
                    resp.setContentType("text/plain");
                    resp.setCharacterEncoding("ASCII");
                    this.controller.writeMetaDataSHA1(parts[2],
                                                      resp.getWriter(),
                                                      "prereleases".equals(parts[0]));
                }
                else {
                    notFound(resp);
                }
                break;
            case 5:// {releases|prereleases}/rubygems/#{name}/#{version}/#{name}-#{version}.{gem|pom}
                if (parts[4].endsWith(".gem")) {
                    resp.sendRedirect(this.controller.getGemLocation(parts[2],
                                                                     parts[3]));
                }
                else if (parts[4].endsWith(".gem.sha1")) {
                    resp.setContentType("text/plain");
                    resp.setCharacterEncoding("ASCII");
                    this.controller.writeGemSHA1(parts[2],
                                                 parts[3],
                                                 resp.getWriter());
                }
                else if (parts[4].endsWith(".pom")) {
                    resp.setContentType("application/xml");
                    resp.setCharacterEncoding("UTF-8");
                    this.controller.writePom(parts[2],
                                             parts[3],
                                             resp.getWriter());
                }
                else if (parts[4].endsWith(".pom.sha1")) {
                    resp.setContentType("text/plain");
                    resp.setCharacterEncoding("ASCII");
                    this.controller.writePomSHA1(parts[2],
                                                 parts[3],
                                                 resp.getWriter());
                }
                else {
                    notFound(resp);
                }
                break;
            default:
                notFound(resp);
            }
        }
        catch (final FileNotFoundException e) {
            notFound(resp);
        }
    }

    private void notFound(final HttpServletResponse resp) throws IOException {
        resp.sendError(HttpServletResponse.SC_NOT_FOUND);
    }
}
{'fraction_non_alphanumeric': 0.10371796414390566, 'fraction_numerical': 0.011550956563590422, 'mean_word_length': 1.3108145676953016, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 46, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7059885', 'n_tokens_mistral': 1931, 'n_tokens_neox': 1808, 'n_words': 292}