All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.mattressframework.api.HttpEntityWriter Maven / Gradle / Ivy

/*
 * Copyright 2007-2008, Josh Devins.
 *
 * 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.mattressframework.api;

import java.io.IOException;
import java.io.OutputStream;
import java.util.Map;

import org.mattressframework.api.annotations.SupportsMediaTypes;
import org.mattressframework.api.http.Header;
import org.mattressframework.api.http.MediaType;

/**
 * Contract for a provider that supports the conversion of a Java type to a
 * stream.
 * 
 * 

* Implementing classes should be annotated with {@link SupportsMediaTypes} to * show what type of media they support. Once a bean of this type has been added * to the Spring context, the framework will pick it up automatically, no extra * annotations are needed. *

* *

* This differs from the JSR 311 MessageBodyWriter in that it * uses the framework's {@link MediaType}. *

*/ public interface HttpEntityWriter extends Provider { /** * Called before {@link #writeTo(Object, MediaType, Map, OutputStream)} to * ascertain the length in bytes of the serialized form of * entity. A non-negative return value is used in a HTTP * Content-Length header. * * @param entity * The entity instance that is to be written to the entity * stream. * * @return Length in bytes or -1 if the length cannot be determined in * advance. */ int getSize(Object entity); /** * Write a type to an HTTP response. Implementations should NOT * call {@link OutputStream#flush()} after writing to the * {@link OutputStream}. The framework will be responsible for doing this. * * @param entity * The entity instance that is to be written to the entity * stream. * @param mediaType * The media type of the HTTP entity. * @param httpHeaders * The HTTP headers associated with HTTP entity. * @param entityStream * The {@link OutputStream} of the HTTP entity. * * @throws java.io.IOException * If an IO error arises. */ void writeTo(Object entity, MediaType mediaType, Map httpHeaders, OutputStream entityStream) throws IOException; }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy