<commit_before>/*
 * Copyright 2008 - 2011 <NAME> (heuer[at]semagia.com). All rights reserved.
 *
 * 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 com.semagia.cassa.jaxrs;

import java.util.List;

import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;

import com.semagia.cassa.common.MediaType;
import com.semagia.cassa.common.dm.IWritableRepresentation;

/**
 * {@link Response} related utility functions.
 * 
 * @author <NAME> (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
 */
final class ResponseUtils {

    private ResponseUtils() {
        // noop.
    }

    /**
     * Returns a Not Acceptable reponse with the provided media types.
     *
     * @param supportedMediaTypes The supported media types.
     * @return A Not Acceptable response. 
     */
    public static Response notAcceptable(List<MediaType> supportedMediaTypes) {
        return Response.notAcceptable(MediaTypeUtils.asVariants(supportedMediaTypes)).build();
    }

    /**
     * Returns a response using the provided {@link IWritablRepresentation} instance to 
     * serialize the body of the response.
     *
     * @param builder The builder used to build the response.
     * @param writable A {@link IWritable} instance which is reposible to serialize the response body.
     * @return The reponse.
     */
    public static Response buildStreamingEntity(final ResponseBuilder builder, final IWritableRepresentation writable) {
        builder.entity(new StreamingWritableOutput(writable));
        builder.type(MediaTypeUtils.toJaxRSMediaType(writable.getMediaType()));
        return builder.build();
    }

    /**
     * Returns a HTTP Method Not Allowed (405) response with an "Allow" header
     * set to "GET, HEAD".
     *
     * @return A Method Not Allowed response.
     */
    public static Response methodNotAllowed() {
        return Response.status(405).header("Allow", "GET, HEAD").build();
    }

    public static Response noContent() {
        return Response.noContent().build();
    }

    public static Response accepted() {
        return Response.status(Response.Status.ACCEPTED).build();
    }

    /**
     * Throws a 404 error iff {@code obj} is {@code null}.
     *
     * @param obj The object to check.
     * @throws WebApplicationException If obj is null.
     */
    public static void ensureExists(final Object obj) throws WebApplicationException {
        if (obj == null) {
            throw new WebApplicationException(Response.Status.NOT_FOUND);
        }
    }
}<commit_msg>Removed unused method, added docs<commit_after>/*
 * Copyright 2008 - 2011 <NAME> (heuer[at]semagia.com). All rights reserved.
 *
 * 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 com.semagia.cassa.jaxrs;

import java.util.List;

import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;

import com.semagia.cassa.common.MediaType;
import com.semagia.cassa.common.dm.IWritableRepresentation;

/**
 * {@link Response} related utility functions.
 * 
 * @author <NAME> (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
 */
final class ResponseUtils {

    private ResponseUtils() {
        // noop.
    }

    /**
     * Returns a Not Acceptable reponse with the provided media types.
     *
     * @param supportedMediaTypes The supported media types.
     * @return A Not Acceptable response. 
     */
    public static Response notAcceptable(List<MediaType> supportedMediaTypes) {
        return Response.notAcceptable(MediaTypeUtils.asVariants(supportedMediaTypes)).build();
    }

    /**
     * Returns a response using the provided {@link IWritablRepresentation} instance to 
     * serialize the body of the response.
     *
     * @param builder The builder used to build the response.
     * @param writable A {@link IWritable} instance which is reposible to serialize the response body.
     * @return The reponse.
     */
    public static Response buildStreamingEntity(final ResponseBuilder builder, final IWritableRepresentation writable) {
        builder.entity(new StreamingWritableOutput(writable));
        builder.type(MediaTypeUtils.toJaxRSMediaType(writable.getMediaType()));
        return builder.build();
    }

    /**
     * Returns a HTTP Method Not Allowed (405) response with an "Allow" header
     * set to "GET, HEAD".
     *
     * @return A Method Not Allowed response.
     */
    public static Response methodNotAllowed() {
        return Response.status(405).header("Allow", "GET, HEAD").build();
    }

    /**
     * Returns a HTTP No Content response.
     *
     * @return A No Content response.
     */
    public static Response noContent() {
        return Response.noContent().build();
    }

    /**
     * Returns a HTTP Accepted response.
     *
     * @return A Accepted response.
     */
    public static Response accepted() {
        return Response.status(Response.Status.ACCEPTED).build();
    }

}
{'fraction_non_alphanumeric': 0.0992416749093307, 'fraction_numerical': 0.006429277942631058, 'mean_word_length': 3.1216032608695654, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '3635770', 'n_tokens_mistral': 1708, 'n_tokens_neox': 1644, 'n_words': 546}