<commit_before>package examples.simple;

import com.vtence.molecule.WebServer;
import com.vtence.molecule.middlewares.Failsafe;

import java.io.IOException;
import java.nio.charset.Charset;

public class SimpleExample {

    public void run(WebServer server) throws IOException {
               // Capture internal server errors and display a 500 page
        server.add(new Failsafe())
               // The warmup block is executed once at startup
              .warmup(app -> System.out.println("Application ready"))
              .start((request, response) -> {
                  // An unsupported charset will cause an exception, which will cause the FailSafe middleware
                  // to render a 500 page
                  Charset encoding = Charset.forName(request.parameter("encoding"));
                  // The specified charset will be used automatically to encode the response
                  response.contentType("text/html; charset=" + encoding.displayName().toLowerCase());

                  response.done("<html>" +
                          "<body>" +
                          "<p>" +
                          "Les naïfs ægithales hâtifs pondant à Noël où il gèle sont sûrs " +
                          "d'être déçus en voyant leurs drôles d'œufs abîmés." +
                          "</p>" +
                          "</body>" +
                          "</html>");
              });
    }


    public static void main(String[] args) throws IOException {
        SimpleExample example = new SimpleExample();
        // Run the default web server
        WebServer webServer = WebServer.create();
        example.run(webServer);
        System.out.println("Access at " + webServer.uri() + "?encoding=utf-8");
    }
}<commit_msg>Update inline doc for the simple example<commit_after>package examples.simple;

import com.vtence.molecule.WebServer;
import com.vtence.molecule.middlewares.Failsafe;

import java.io.IOException;
import java.nio.charset.Charset;

/**
 * <p>
 *     In this example we run a single application that responds to all incoming requests with an HTML page,
 *     varying the encoding.
 * </p>
 * <p>
 *     We let the user change the output encoding by specifying the desired charset as a request parameter.
 * </p>
 * <p>
 *     There's always the chance that we are thrown an encoding we don't support, so we use the failsafe middleware
 *     to turn internal server errors into a 500 error page.
 * </p>
 */
public class SimpleExample {

    public void run(WebServer server) throws IOException {
        // The failsafe middleware captures internal server errors and renders a default 500 page,
        // showing a stack trace of the exception and its causes.
        server.add(new Failsafe())
               // The optional warmup block is executed once at startup as a boot sequence
              .warmup(app -> System.out.println("Application ready"))
              .start((request, response) -> {
                  // An unsupported charset will cause an exception, which will in turn cause the failsafe middleware
                  // to render a 500 page
                  Charset encoding = Charset.forName(request.parameter("encoding"));
                  // The content-type charset will be used automatically to encode the response
                  response.contentType("text/html; charset=" + encoding.displayName().toLowerCase());

                  // Our HTML page contains characters outside the ISO-8859-1 alphabet.
                  response.done("<html>" +
                          "<body>" +
                          "<p>" +
                          "Les naïfs ægithales hâtifs pondant à Noël où il gèle sont sûrs " +
                          "d'être déçus en voyant leurs drôles d'œufs abîmés." +
                          "</p>" +
                          "</body>" +
                          "</html>");
              });
    }


    public static void main(String[] args) throws IOException {
        SimpleExample example = new SimpleExample();
        // Run the default web server
        WebServer webServer = WebServer.create();
        example.run(webServer);
        System.out.println("Access at " + webServer.uri() + "?encoding=utf-8");
    }
}
{'fraction_non_alphanumeric': 0.09328621908127209, 'fraction_numerical': 0.005182567726737338, 'mean_word_length': 1.8825526137135098, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 25, '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': '5210097', 'n_tokens_mistral': 1094, 'n_tokens_neox': 1034, 'n_words': 365}