public class Encoder extends Filter
If the Representation
has an unknown size,
it will always be a candidate for encoding. Candidate representations need to
respect media type criteria by the lists of accepted and ignored media types.
Concurrency note: instances of this class or its subclasses can be invoked by
several threads at the same time and therefore must be thread-safe. You
should be especially careful when storing state in member variables.
Modifier and Type | Field and Description |
---|---|
static int |
ENCODE_ALL_SIZES
Indicates if the encoding should always occur, regardless of the size.
|
Constructor and Description |
---|
Encoder(Context context)
Constructor using the default media types and with
ENCODE_ALL_SIZES setting. |
Encoder(Context context,
boolean encodingInput,
boolean encodingOutput,
long minimumSize,
java.util.List<MediaType> acceptedMediaTypes,
java.util.List<MediaType> ignoredMediaTypes)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
afterHandle(Request request,
Response response)
Allows filtering after its handling by the target Restlet.
|
int |
beforeHandle(Request request,
Response response)
Allows filtering before its handling by the target Restlet.
|
boolean |
canEncode(Representation representation)
Indicates if a representation can be encoded.
|
Representation |
encode(ClientInfo client,
Representation representation)
Encodes a given representation if an encoding is supported by the client.
|
java.util.List<MediaType> |
getAcceptedMediaTypes()
Returns the media types that should be encoded.
|
Encoding |
getBestEncoding(ClientInfo client)
Returns the best supported encoding for a given client.
|
static java.util.List<MediaType> |
getDefaultAcceptedMediaTypes()
Returns the list of default encoded media types.
|
static java.util.List<MediaType> |
getDefaultIgnoredMediaTypes()
Returns the list of default ignored media types.
|
java.util.List<MediaType> |
getIgnoredMediaTypes()
Returns the media types that should be ignored.
|
long |
getMinimumSize()
Returns the minimum size a representation must have before compression is
done.
|
java.util.List<Encoding> |
getSupportedEncodings()
Returns the list of supported encodings.
|
boolean |
isEncodeRequest()
Deprecated.
Use
isEncodingRequest() instead. |
boolean |
isEncodeResponse()
Deprecated.
Use
isEncodingResponse() instead. |
boolean |
isEncodingRequest()
Indicates if the request entity should be encoded.
|
boolean |
isEncodingResponse()
Indicates if the response entity should be encoded.
|
void |
setEncodeRequest(boolean encodingRequest)
Deprecated.
Use
setEncodingRequest(boolean) instead. |
void |
setEncodeResponse(boolean encodingResponse)
Deprecated.
Use
setEncodingResponse(boolean) instead. |
void |
setEncodingRequest(boolean encodingRequest)
Indicates if the request entity should be encoded.
|
void |
setEncodingResponse(boolean encodingResponse)
Indicates if the response entity should be encoded.
|
void |
setMinimumSize(long mininumSize)
Sets the minimum size a representation must have before compression is
done.
|
doHandle, getNext, handle, hasNext, setNext, setNext, start, stop
finalize, getApplication, getAuthor, getContext, getDescription, getLogger, getName, getOwner, isStarted, isStopped, setAuthor, setContext, setDescription, setName, setOwner
public static final int ENCODE_ALL_SIZES
public Encoder(Context context)
ENCODE_ALL_SIZES
setting. This constructor will only encode
response entities after call handling.context
- The context.public Encoder(Context context, boolean encodingInput, boolean encodingOutput, long minimumSize, java.util.List<MediaType> acceptedMediaTypes, java.util.List<MediaType> ignoredMediaTypes)
context
- The context.encodingInput
- Indicates if the request entities should be encoded.encodingOutput
- Indicates if the response entities should be encoded.minimumSize
- The minimal size of the representation where compression
should be used.acceptedMediaTypes
- The media types that should be encoded.ignoredMediaTypes
- The media types that should be ignored.public static java.util.List<MediaType> getDefaultAcceptedMediaTypes()
public static java.util.List<MediaType> getDefaultIgnoredMediaTypes()
public void afterHandle(Request request, Response response)
afterHandle
in class Filter
request
- The request to filter.response
- The response to filter.public int beforeHandle(Request request, Response response)
beforeHandle
in class Filter
request
- The request to filter.response
- The response to filter.public boolean canEncode(Representation representation)
representation
- The representation to test.public Representation encode(ClientInfo client, Representation representation)
client
- The client preferences to use.representation
- The representation to encode.public java.util.List<MediaType> getAcceptedMediaTypes()
public Encoding getBestEncoding(ClientInfo client)
client
- The client preferences to use.public java.util.List<MediaType> getIgnoredMediaTypes()
public long getMinimumSize()
public java.util.List<Encoding> getSupportedEncodings()
EncodeRepresentation.getSupportedEncodings()
static method.@Deprecated public boolean isEncodeRequest()
isEncodingRequest()
instead.@Deprecated public boolean isEncodeResponse()
isEncodingResponse()
instead.public boolean isEncodingRequest()
public boolean isEncodingResponse()
@Deprecated public void setEncodeRequest(boolean encodingRequest)
setEncodingRequest(boolean)
instead.encodingRequest
- True if the request entity should be encoded.@Deprecated public void setEncodeResponse(boolean encodingResponse)
setEncodingResponse(boolean)
instead.encodingResponse
- True if the response entity should be encoded.public void setEncodingRequest(boolean encodingRequest)
encodingRequest
- True if the request entity should be encoded.public void setEncodingResponse(boolean encodingResponse)
encodingResponse
- True if the response entity should be encoded.public void setMinimumSize(long mininumSize)
mininumSize
- The minimum size a representation must have before compression
is done.Copyright © 2005-2012. All Rights Reserved.