Class EncoderEmbedder<E>
java.lang.Object
org.jboss.netty.handler.codec.embedder.EncoderEmbedder<E>
- All Implemented Interfaces:
CodecEmbedder<E>
A helper that wraps an encoder so that it can be used without doing actual
I/O in unit tests or higher level codecs. For example, you can encode a
String into a Base64-encoded ChannelBuffer with
Base64Encoder and StringEncoder without setting up the
ChannelPipeline and other mock objects by yourself:
String data = "foobar";EncoderEmbedder<ChannelBuffer> embedder = newEncoderEmbedder<>( newBase64Encoder(), newStringEncoder()); embedder.offer(data);ChannelBufferencoded = embedder.poll(); assert encoded.toString(CharsetUtil.US_ASCII).equals("Zm9vYmFy");
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionEncoderEmbedder(ChannelBufferFactory bufferFactory, ChannelDownstreamHandler... handlers) Creates a new embedder whose pipeline is composed of the specified handlers.EncoderEmbedder(ChannelDownstreamHandler... handlers) Creates a new embedder whose pipeline is composed of the specified handlers. -
Method Summary
Modifier and TypeMethodDescriptionbooleanfinish()Signals the pipeline that the encoding or decoding has been finished and no more data will be offered.protected final ChannelReturns the virtualChannelwhich will be used as a mock during encoding and decoding.Returns theChannelPipelinethat handles the input.protected final booleanisEmpty()Returnstrueif and only if the produce queue is empty and thereforeCodecEmbedder.poll()will returnnull.booleanOffers an input object to the pipeline of this embedder.final Epeek()Reads an encoded or decoded output from the head of the product queue.final Epoll()Consumes an encoded or decoded output from the product queue.final Object[]pollAll()Consumes all encoded or decoded output from the product queue.final <T> T[]pollAll(T[] a) Consumes all encoded or decoded output from the product queue.final intsize()Returns the number of encoded or decoded output in the product queue.
-
Constructor Details
-
EncoderEmbedder
Creates a new embedder whose pipeline is composed of the specified handlers. -
EncoderEmbedder
Creates a new embedder whose pipeline is composed of the specified handlers.- Parameters:
bufferFactory- theChannelBufferFactoryto be used when creating a new buffer.
-
-
Method Details
-
offer
Description copied from interface:CodecEmbedderOffers an input object to the pipeline of this embedder.- Returns:
trueif and only if there is something to read in the product queue (seeCodecEmbedder.poll()andCodecEmbedder.peek())
-
finish
public boolean finish()Description copied from interface:CodecEmbedderSignals the pipeline that the encoding or decoding has been finished and no more data will be offered.- Specified by:
finishin interfaceCodecEmbedder<E>- Returns:
trueif and only if there is something to read in the product queue (seeCodecEmbedder.poll()andCodecEmbedder.peek())
-
getChannel
Returns the virtualChannelwhich will be used as a mock during encoding and decoding. -
isEmpty
protected final boolean isEmpty()Returnstrueif and only if the produce queue is empty and thereforeCodecEmbedder.poll()will returnnull. -
poll
Description copied from interface:CodecEmbedderConsumes an encoded or decoded output from the product queue. The output object is generated by the offered input objects.- Specified by:
pollin interfaceCodecEmbedder<E>- Returns:
- an encoded or decoded object.
nullif and only if there is no output object left in the product queue.
-
peek
Description copied from interface:CodecEmbedderReads an encoded or decoded output from the head of the product queue. The difference fromCodecEmbedder.poll()is that it does not remove the retrieved object from the product queue.- Specified by:
peekin interfaceCodecEmbedder<E>- Returns:
- an encoded or decoded object.
nullif and only if there is no output object left in the product queue.
-
pollAll
Description copied from interface:CodecEmbedderConsumes all encoded or decoded output from the product queue. The output object is generated by the offered input objects. The behavior of this method is identical withCollection.toArray()except that the product queue is cleared.- Specified by:
pollAllin interfaceCodecEmbedder<E>- Returns:
- an array of all encoded or decoded objects. An empty array is returned if and only if there is no output object left in the product queue.
-
pollAll
public final <T> T[] pollAll(T[] a) Description copied from interface:CodecEmbedderConsumes all encoded or decoded output from the product queue. The output object is generated by the offered input objects. The behavior of this method is identical withCollection.toArray(Object[])except that the product queue is cleared.- Specified by:
pollAllin interfaceCodecEmbedder<E>- Returns:
- an array of all encoded or decoded objects. An empty array is returned if and only if there is no output object left in the product queue.
-
size
public final int size()Description copied from interface:CodecEmbedderReturns the number of encoded or decoded output in the product queue.- Specified by:
sizein interfaceCodecEmbedder<E>
-
getPipeline
Description copied from interface:CodecEmbedderReturns theChannelPipelinethat handles the input.- Specified by:
getPipelinein interfaceCodecEmbedder<E>
-