org.glassfish.jersey.spi
Class ContentEncoder

java.lang.Object
  extended by org.glassfish.jersey.spi.ContentEncoder
All Implemented Interfaces:
ReaderInterceptor, WriterInterceptor
Direct Known Subclasses:
DeflateEncoder, GZipEncoder

@Priority(value=4000)
@Contract
public abstract class ContentEncoder
extends Object
implements ReaderInterceptor, WriterInterceptor

Standard contract for plugging in content encoding support. Provides a standard way of implementing encoding WriterInterceptor and decoding ReaderInterceptor. Implementing this class ensures the encoding supported by the implementation will be considered during the content negotiation phase when deciding which encoding should be used based on the accepted encodings (and the associated quality parameters) in the request headers.

Author:
Martin Matula (martin.matula at oracle.com)

Constructor Summary
protected ContentEncoder(String... supportedEncodings)
          Initializes this encoder implementation with the list of supported content encodings.
 
Method Summary
 Object aroundReadFrom(ReaderInterceptorContext context)
          Interceptor method wrapping calls to MessageBodyReader.readFrom(java.lang.Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType, javax.ws.rs.core.MultivaluedMap, java.io.InputStream) method.
 void aroundWriteTo(WriterInterceptorContext context)
          Interceptor method wrapping calls to MessageBodyWriter.writeTo(T, java.lang.Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType, javax.ws.rs.core.MultivaluedMap, java.io.OutputStream) method.
abstract  InputStream decode(String contentEncoding, InputStream encodedStream)
          Implementations of this method should take the encoded stream, wrap it and return a stream that can be used to read the decoded entity.
abstract  OutputStream encode(String contentEncoding, OutputStream entityStream)
          Implementations of this method should take the entity stream, wrap it and return a stream that is encoded using the specified encoding.
 Set<String> getSupportedEncodings()
          Returns values of Content-Encoding header supported by this encoder.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ContentEncoder

protected ContentEncoder(String... supportedEncodings)
Initializes this encoder implementation with the list of supported content encodings.

Parameters:
supportedEncodings - Values of Content-Encoding header supported by this encoding provider.
Method Detail

getSupportedEncodings

public final Set<String> getSupportedEncodings()
Returns values of Content-Encoding header supported by this encoder.

Returns:
Set of supported Content-Encoding values.

decode

public abstract InputStream decode(String contentEncoding,
                                   InputStream encodedStream)
                            throws IOException
Implementations of this method should take the encoded stream, wrap it and return a stream that can be used to read the decoded entity.

Parameters:
contentEncoding - Encoding to be used to decode the stream - guaranteed to be one of the supported encoding values.
encodedStream - Encoded input stream.
Returns:
Decoded entity stream.
Throws:
IOException - if an IO error arises.

encode

public abstract OutputStream encode(String contentEncoding,
                                    OutputStream entityStream)
                             throws IOException
Implementations of this method should take the entity stream, wrap it and return a stream that is encoded using the specified encoding.

Parameters:
contentEncoding - Encoding to be used to encode the entity - guaranteed to be one of the supported encoding values.
entityStream - Entity stream to be encoded.
Returns:
Encoded stream.
Throws:
IOException - if an IO error arises.

aroundReadFrom

public final Object aroundReadFrom(ReaderInterceptorContext context)
                            throws IOException,
                                   WebApplicationException
Description copied from interface: ReaderInterceptor
Interceptor method wrapping calls to MessageBodyReader.readFrom(java.lang.Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType, javax.ws.rs.core.MultivaluedMap, java.io.InputStream) method. The parameters of the wrapped method called are available from context. Implementations of this method SHOULD explicitly call ReaderInterceptorContext.proceed() to invoke the next interceptor in the chain, and ultimately the wrapped MessageBodyReader.readFrom(java.lang.Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType, javax.ws.rs.core.MultivaluedMap, java.io.InputStream) method.

Specified by:
aroundReadFrom in interface ReaderInterceptor
Parameters:
context - invocation context.
Returns:
result of next interceptor invoked or the wrapped method if last interceptor in chain.
Throws:
IOException - if an IO error arises or is thrown by the wrapped MessageBodyReader.readFrom method.
WebApplicationException - thrown by the wrapped MessageBodyReader.readFrom method.

aroundWriteTo

public final void aroundWriteTo(WriterInterceptorContext context)
                         throws IOException,
                                WebApplicationException
Description copied from interface: WriterInterceptor
Interceptor method wrapping calls to MessageBodyWriter.writeTo(T, java.lang.Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType, javax.ws.rs.core.MultivaluedMap, java.io.OutputStream) method. The parameters of the wrapped method called are available from context. Implementations of this method SHOULD explicitly call WriterInterceptorContext.proceed() to invoke the next interceptor in the chain, and ultimately the wrapped MessageBodyWriter.writeTo method.

Specified by:
aroundWriteTo in interface WriterInterceptor
Parameters:
context - invocation context.
Throws:
IOException - if an IO error arises or is thrown by the wrapped MessageBodyWriter.writeTo method.
WebApplicationException - thrown by the wrapped MessageBodyWriter.writeTo method.


Copyright © 2007-2014, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.