@Singleton @Internal @Requires(bean=ByteBufferFactory.class) public class TextStreamCodec extends Object implements MediaTypeCodec
MediaTypeCodec
that will encode Event
objects in order to support Server Sent Events.Modifier and Type | Field and Description |
---|---|
static String |
CONFIGURATION_QUALIFIER |
Modifier | Constructor and Description |
---|---|
|
TextStreamCodec(ApplicationConfiguration applicationConfiguration,
ByteBufferFactory byteBufferFactory,
BeanProvider<MediaTypeCodecRegistry> codecRegistryProvider,
CodecConfiguration codecConfiguration) |
protected |
TextStreamCodec(Charset defaultCharset,
ByteBufferFactory byteBufferFactory,
BeanProvider<MediaTypeCodecRegistry> codecRegistryProvider,
CodecConfiguration codecConfiguration) |
Modifier and Type | Method and Description |
---|---|
<T> T |
decode(Argument<T> type,
InputStream inputStream)
Decode the given type from the given
InputStream . |
<T> T |
decode(Class<T> type,
InputStream inputStream)
Decode the given type from the given
InputStream . |
<T> byte[] |
encode(T object)
Encode the given type returning the object as a byte[].
|
<T,B> ByteBuffer<B> |
encode(T object,
ByteBufferFactory<?,B> allocator)
Encode the given type returning the object as a
ByteBuffer . |
<T> void |
encode(T object,
OutputStream outputStream)
Encode the given type to the given
OutputStream . |
Collection<MediaType> |
getMediaTypes() |
protected void |
writeAttribute(ByteBuffer eventData,
byte[] attribute,
String value) |
public static final String CONFIGURATION_QUALIFIER
@Inject public TextStreamCodec(ApplicationConfiguration applicationConfiguration, ByteBufferFactory byteBufferFactory, BeanProvider<MediaTypeCodecRegistry> codecRegistryProvider, @Named(value="text-stream") @Nullable CodecConfiguration codecConfiguration)
applicationConfiguration
- The application configurationbyteBufferFactory
- A byte buffer factorycodecRegistryProvider
- A media type codec registrycodecConfiguration
- The configuration for the codecprotected TextStreamCodec(Charset defaultCharset, ByteBufferFactory byteBufferFactory, BeanProvider<MediaTypeCodecRegistry> codecRegistryProvider, @Named(value="text-stream") @Nullable CodecConfiguration codecConfiguration)
defaultCharset
- The default charsetbyteBufferFactory
- A byte buffer factorycodecRegistryProvider
- A media type codec registrycodecConfiguration
- The configuration for the codecpublic Collection<MediaType> getMediaTypes()
getMediaTypes
in interface MediaTypeCodec
public <T> T decode(Argument<T> type, InputStream inputStream)
MediaTypeCodec
InputStream
.decode
in interface MediaTypeCodec
T
- The generic typetype
- The typeinputStream
- The input streampublic <T> T decode(Class<T> type, InputStream inputStream)
MediaTypeCodec
InputStream
.decode
in interface MediaTypeCodec
T
- The generic typetype
- The typeinputStream
- The input streampublic <T> void encode(T object, OutputStream outputStream)
MediaTypeCodec
OutputStream
.encode
in interface MediaTypeCodec
T
- The generic typeobject
- The object to encodeoutputStream
- The output streampublic <T> byte[] encode(T object)
MediaTypeCodec
encode
in interface MediaTypeCodec
T
- The generic typeobject
- The object to encodepublic <T,B> ByteBuffer<B> encode(T object, ByteBufferFactory<?,B> allocator)
MediaTypeCodec
ByteBuffer
.encode
in interface MediaTypeCodec
T
- The generic typeB
- The buffer typeobject
- The object to encodeallocator
- The allocatorprotected void writeAttribute(ByteBuffer eventData, byte[] attribute, String value)
eventData
- The byte bufferattribute
- The attributevalue
- The value