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

org.mattressframework.api.HttpEntityReader 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.InputStream;
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 stream to a Java
 * type.
 * 
 * 

* 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 * MessageBodyReader in that it uses the * framework's {@link MediaType}. *

*/ public interface HttpEntityReader extends Provider { /** * Read a type from the {@link InputStream}. The {@link MediaType} being * requested will be validated by the framework (using * {@link Provider#supportsType(Class)}) to make sure that the * implementation supports it. * * @param type * The type that is to be read from 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 InputStream} of the HTTP entity. * * @throws java.io.IOException * If an IO error arises. */ Object readFrom(Class type, MediaType mediaType, Map httpHeaders, InputStream entityStream) throws IOException; }