<commit_before>/*
 * Copyright 2014 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * 	http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.nosceon.titanite;

import io.netty.handler.codec.http.HttpResponseStatus;
import org.nosceon.titanite.json.JsonMapperLoader;
import org.nosceon.titanite.service.FileService;
import org.nosceon.titanite.service.PublicResourceService;
import org.nosceon.titanite.service.ResourceService;
import org.nosceon.titanite.service.WebJarResourceService;
import org.nosceon.titanite.view.ViewRendererLoader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.net.URI;
import java.util.concurrent.CompletionStage;
import java.util.function.Function;

/**
 * @author <NAME>
 */
public final class Titanite {

    static final Logger LOG = LoggerFactory.getLogger(Titanite.class);

    public static HttpServerConfig.Default config() {
        return new HttpServerConfig.Default();
    }

    public static HttpServer httpServer() {
        return new HttpServer();
    }

    public static HttpServer httpServer(HttpServerConfig config) {
        return new HttpServer(config);
    }

    public static ErrorFilter errors() {
        return new ErrorFilter();
    }

    public static Function<Request, CompletionStage<Response>> fileService(String directory) {
        return new FileService(new File(directory));
    }

    public static Function<Request, CompletionStage<Response>> fileService(File directory) {
        return new FileService(directory);
    }

    public static Function<Request, CompletionStage<Response>> resourceService(String baseResource) {
        return new ResourceService(baseResource);
    }

    public static Function<Request, CompletionStage<Response>> publicResources() {
        return new PublicResourceService();
    }

    public static Function<Request, CompletionStage<Response>> webJarResources() {
        return new WebJarResourceService();
    }

    public static final class Responses {

        public static Response status(int status) {
            return new Response(HttpResponseStatus.valueOf(status));
        }

        public static Response ok() {
            return new Response(HttpResponseStatus.OK);
        }

        public static Response created(String location) {
            return new Response(HttpResponseStatus.CREATED).location(location);
        }

        public static Response created(URI location) {
            return new Response(HttpResponseStatus.CREATED).location(location);
        }

        public static Response accepted() {
            return new Response(HttpResponseStatus.ACCEPTED);
        }

        public static Response noContent() {
            return new Response(HttpResponseStatus.NO_CONTENT);
        }

        public static Response seeOther(String location) {
            return new Response(HttpResponseStatus.SEE_OTHER).location(location);
        }

        public static Response seeOther(URI location) {
            return new Response(HttpResponseStatus.SEE_OTHER).location(location);
        }

        public static Response temporaryRedirect(String location) {
            return new Response(HttpResponseStatus.TEMPORARY_REDIRECT).location(location);
        }

        public static Response temporaryRedirect(URI location) {
            return new Response(HttpResponseStatus.TEMPORARY_REDIRECT).location(location);
        }

        public static Response notModified() {
            return new Response(HttpResponseStatus.NOT_MODIFIED);
        }

        public static Response badRequest() {
            return new Response(HttpResponseStatus.BAD_REQUEST);
        }

        public static Response unauthorized() {
            return new Response(HttpResponseStatus.UNAUTHORIZED);
        }

        public static Response forbidden() {
            return new Response(HttpResponseStatus.FORBIDDEN);
        }

        public static Response notFound() {
            return new Response(HttpResponseStatus.NOT_FOUND);
        }

        public static Response notAcceptable() {
            return new Response(HttpResponseStatus.NOT_ACCEPTABLE);
        }

        public static Response methodNotAllowed() {
            return new Response(HttpResponseStatus.METHOD_NOT_ALLOWED);
        }

        public static Response conflict() {
            return new Response(HttpResponseStatus.CONFLICT);
        }

        public static Response unsupportedMediaType() {
            return new Response(HttpResponseStatus.UNSUPPORTED_MEDIA_TYPE);
        }

        public static Response notImplemented() {
            return new Response(HttpResponseStatus.NOT_IMPLEMENTED);
        }

    }

    public static final class Json {

        public static <T> BodyReader<T> json(Class<T> type) {
            return JsonMapperLoader.get().in(type);
        }

        public static BodyWriter json(Object value) {
            return JsonMapperLoader.get().out(value);
        }

    }

    public static final class View {

        public static BodyWriter view(Object view) {
            return ViewRendererLoader.get().apply(view);
        }<commit_msg>renamed to Support classes<commit_after>/*
 * Copyright 2014 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * 	http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.nosceon.titanite;

import io.netty.handler.codec.http.HttpResponseStatus;
import org.nosceon.titanite.json.JsonMapperLoader;
import org.nosceon.titanite.service.FileService;
import org.nosceon.titanite.service.PublicResourceService;
import org.nosceon.titanite.service.ResourceService;
import org.nosceon.titanite.service.WebJarResourceService;
import org.nosceon.titanite.view.ViewRendererLoader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.net.URI;
import java.util.concurrent.CompletionStage;
import java.util.function.Function;

/**
 * @author <NAME>
 */
public final class Titanite {

    static final Logger LOG = LoggerFactory.getLogger(Titanite.class);

    public static HttpServerConfig.Default config() {
        return new HttpServerConfig.Default();
    }

    public static HttpServer httpServer() {
        return new HttpServer();
    }

    public static HttpServer httpServer(HttpServerConfig config) {
        return new HttpServer(config);
    }

    public static ErrorFilter errors() {
        return new ErrorFilter();
    }

    public static Function<Request, CompletionStage<Response>> fileService(String directory) {
        return new FileService(new File(directory));
    }

    public static Function<Request, CompletionStage<Response>> fileService(File directory) {
        return new FileService(directory);
    }

    public static Function<Request, CompletionStage<Response>> resourceService(String baseResource) {
        return new ResourceService(baseResource);
    }

    public static Function<Request, CompletionStage<Response>> publicResources() {
        return new PublicResourceService();
    }

    public static Function<Request, CompletionStage<Response>> webJarResources() {
        return new WebJarResourceService();
    }

    public static final class Responses {

        public static Response status(int status) {
            return new Response(HttpResponseStatus.valueOf(status));
        }

        public static Response ok() {
            return new Response(HttpResponseStatus.OK);
        }

        public static Response created(String location) {
            return new Response(HttpResponseStatus.CREATED).location(location);
        }

        public static Response created(URI location) {
            return new Response(HttpResponseStatus.CREATED).location(location);
        }

        public static Response accepted() {
            return new Response(HttpResponseStatus.ACCEPTED);
        }

        public static Response noContent() {
            return new Response(HttpResponseStatus.NO_CONTENT);
        }

        public static Response seeOther(String location) {
            return new Response(HttpResponseStatus.SEE_OTHER).location(location);
        }

        public static Response seeOther(URI location) {
            return new Response(HttpResponseStatus.SEE_OTHER).location(location);
        }

        public static Response temporaryRedirect(String location) {
            return new Response(HttpResponseStatus.TEMPORARY_REDIRECT).location(location);
        }

        public static Response temporaryRedirect(URI location) {
            return new Response(HttpResponseStatus.TEMPORARY_REDIRECT).location(location);
        }

        public static Response notModified() {
            return new Response(HttpResponseStatus.NOT_MODIFIED);
        }

        public static Response badRequest() {
            return new Response(HttpResponseStatus.BAD_REQUEST);
        }

        public static Response unauthorized() {
            return new Response(HttpResponseStatus.UNAUTHORIZED);
        }

        public static Response forbidden() {
            return new Response(HttpResponseStatus.FORBIDDEN);
        }

        public static Response notFound() {
            return new Response(HttpResponseStatus.NOT_FOUND);
        }

        public static Response notAcceptable() {
            return new Response(HttpResponseStatus.NOT_ACCEPTABLE);
        }

        public static Response methodNotAllowed() {
            return new Response(HttpResponseStatus.METHOD_NOT_ALLOWED);
        }

        public static Response conflict() {
            return new Response(HttpResponseStatus.CONFLICT);
        }

        public static Response unsupportedMediaType() {
            return new Response(HttpResponseStatus.UNSUPPORTED_MEDIA_TYPE);
        }

        public static Response notImplemented() {
            return new Response(HttpResponseStatus.NOT_IMPLEMENTED);
        }

    }

    public static final class JsonSupport {

        public static <T> BodyReader<T> json(Class<T> type) {
            return JsonMapperLoader.get().in(type);
        }

        public static BodyWriter json(Object value) {
            return JsonMapperLoader.get().out(value);
        }

    }

    public static final class ViewSupport {

        public static BodyWriter render(Object view) {
            return ViewRendererLoader.get().apply(view);
        }
{'fraction_non_alphanumeric': 0.0771613131581276, 'fraction_numerical': 0.0017697548889478807, 'mean_word_length': 2.927032661570535, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4662636', 'n_tokens_mistral': 2817, 'n_tokens_neox': 2723, 'n_words': 767}