Package org.restlet.engine.application
Class Encoder
- java.lang.Object
-
- org.restlet.Restlet
-
- org.restlet.routing.Filter
-
- org.restlet.engine.application.Encoder
-
- All Implemented Interfaces:
Uniform
public class Encoder extends Filter
Filter compressing entities. The best encoding is automatically selected based on the preferences of the client and on the encoding supported by NRE: GZip, Zip and Deflate.
If theRepresentationhas 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.
-
-
Field Summary
Fields Modifier and Type Field Description private EncoderServiceencoderServiceThe parent encoder service.private booleanencodingRequestIndicates if the request entity should be encoded.private booleanencodingResponseIndicates if the response entity should be encoded.
-
Constructor Summary
Constructors Constructor Description Encoder(Context context, boolean encodingRequest, boolean encodingResponse, EncoderService encoderService)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterHandle(Request request, Response response)Allows filtering after its handling by the target Restlet.intbeforeHandle(Request request, Response response)Allows filtering before its handling by the target Restlet.Representationencode(ClientInfo client, Representation representation)Encodes a given representation if an encoding is supported by the client.EncodinggetBestEncoding(ClientInfo client)Returns the best supported encoding for a given client.EncoderServicegetEncoderService()Returns the parent encoder service.java.util.List<Encoding>getSupportedEncodings()Returns the list of supported encodings.booleanisEncodingRequest()Indicates if the request entity should be encoded.booleanisEncodingResponse()Indicates if the response entity should be encoded.-
Methods inherited from class org.restlet.routing.Filter
doHandle, getNext, handle, hasNext, setNext, setNext, start, stop
-
Methods inherited from class org.restlet.Restlet
createFinder, finalize, getApplication, getAuthor, getContext, getDescription, getFinderClass, getLogger, getName, getOwner, handle, handle, handle, isStarted, isStopped, setAuthor, setContext, setDescription, setFinderClass, setName, setOwner
-
-
-
-
Field Detail
-
encodingRequest
private final boolean encodingRequest
Indicates if the request entity should be encoded.
-
encodingResponse
private final boolean encodingResponse
Indicates if the response entity should be encoded.
-
encoderService
private final EncoderService encoderService
The parent encoder service.
-
-
Constructor Detail
-
Encoder
public Encoder(Context context, boolean encodingRequest, boolean encodingResponse, EncoderService encoderService)
Constructor.- Parameters:
context- The context.encodingRequest- Indicates if the request entities should be encoded.encodingResponse- Indicates if the response entities should be encoded.encoderService- The parent encoder service.
-
-
Method Detail
-
afterHandle
public void afterHandle(Request request, Response response)
Allows filtering after its handling by the target Restlet. Does nothing by default.- Overrides:
afterHandlein classFilter- Parameters:
request- The request to filter.response- The response to filter.
-
beforeHandle
public int beforeHandle(Request request, Response response)
Allows filtering before its handling by the target Restlet. Does nothing by default.- Overrides:
beforeHandlein classFilter- Parameters:
request- The request to filter.response- The response to filter.- Returns:
- The continuation status.
-
encode
public Representation encode(ClientInfo client, Representation representation)
Encodes a given representation if an encoding is supported by the client.- Parameters:
client- The client preferences to use.representation- The representation to encode.- Returns:
- The encoded representation or the original one if no encoding supported by the client.
-
getBestEncoding
public Encoding getBestEncoding(ClientInfo client)
Returns the best supported encoding for a given client.- Parameters:
client- The client preferences to use.- Returns:
- The best supported encoding for the given call.
-
getEncoderService
public EncoderService getEncoderService()
Returns the parent encoder service.- Returns:
- The parent encoder service.
-
getSupportedEncodings
public java.util.List<Encoding> getSupportedEncodings()
Returns the list of supported encodings. By default it callsEncodeRepresentation.getSupportedEncodings()static method.- Returns:
- The list of supported encodings.
-
isEncodingRequest
public boolean isEncodingRequest()
Indicates if the request entity should be encoded.- Returns:
- True if the request entity should be encoded.
-
isEncodingResponse
public boolean isEncodingResponse()
Indicates if the response entity should be encoded.- Returns:
- True if the response entity should be encoded.
-
-