Package io.micronaut.http.server.codec
Class TextStreamCodec
java.lang.Object
io.micronaut.http.server.codec.TextStreamCodec
- All Implemented Interfaces:
MediaTypeCodec
@Singleton
@Internal
@Requires(bean=ByteBufferFactory.class)
public class TextStreamCodec
extends Object
implements MediaTypeCodec
A
MediaTypeCodec that will encode Event objects in order to support Server Sent Events.- Since:
- 1.0
- Author:
- Graeme Rocher
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionTextStreamCodec(ApplicationConfiguration applicationConfiguration, ByteBufferFactory byteBufferFactory, BeanProvider<MediaTypeCodecRegistry> codecRegistryProvider, @Nullable CodecConfiguration codecConfiguration) protectedTextStreamCodec(Charset defaultCharset, ByteBufferFactory byteBufferFactory, BeanProvider<MediaTypeCodecRegistry> codecRegistryProvider, @Nullable CodecConfiguration codecConfiguration) -
Method Summary
Modifier and TypeMethodDescription<T> Tdecode(Argument<T> type, InputStream inputStream) Decode the given type from the givenInputStream.<T> Tdecode(Class<T> type, InputStream inputStream) Decode the given type from the givenInputStream.<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 aByteBuffer.<T> voidencode(T object, OutputStream outputStream) Encode the given type to the givenOutputStream.protected voidwriteAttribute(ByteBuffer eventData, byte[] attribute, String value)
-
Field Details
-
CONFIGURATION_QUALIFIER
- See Also:
-
-
Constructor Details
-
TextStreamCodec
@Inject public TextStreamCodec(ApplicationConfiguration applicationConfiguration, ByteBufferFactory byteBufferFactory, BeanProvider<MediaTypeCodecRegistry> codecRegistryProvider, @Named("text-stream") @Nullable @Nullable CodecConfiguration codecConfiguration) - Parameters:
applicationConfiguration- The application configurationbyteBufferFactory- A byte buffer factorycodecRegistryProvider- A media type codec registrycodecConfiguration- The configuration for the codec
-
TextStreamCodec
protected TextStreamCodec(Charset defaultCharset, ByteBufferFactory byteBufferFactory, BeanProvider<MediaTypeCodecRegistry> codecRegistryProvider, @Named("text-stream") @Nullable @Nullable CodecConfiguration codecConfiguration) - Parameters:
defaultCharset- The default charsetbyteBufferFactory- A byte buffer factorycodecRegistryProvider- A media type codec registrycodecConfiguration- The configuration for the codec
-
-
Method Details
-
getMediaTypes
- Specified by:
getMediaTypesin interfaceMediaTypeCodec- Returns:
- The media type of the codec
-
decode
Description copied from interface:MediaTypeCodecDecode the given type from the givenInputStream.- Specified by:
decodein interfaceMediaTypeCodec- Type Parameters:
T- The generic type- Parameters:
type- The typeinputStream- The input stream- Returns:
- The decoded result
-
decode
Description copied from interface:MediaTypeCodecDecode the given type from the givenInputStream.- Specified by:
decodein interfaceMediaTypeCodec- Type Parameters:
T- The generic type- Parameters:
type- The typeinputStream- The input stream- Returns:
- The decoded result
-
encode
Description copied from interface:MediaTypeCodecEncode the given type to the givenOutputStream.- Specified by:
encodein interfaceMediaTypeCodec- Type Parameters:
T- The generic type- Parameters:
object- The object to encodeoutputStream- The output stream
-
encode
public <T> byte[] encode(T object) Description copied from interface:MediaTypeCodecEncode the given type returning the object as a byte[].- Specified by:
encodein interfaceMediaTypeCodec- Type Parameters:
T- The generic type- Parameters:
object- The object to encode- Returns:
- The decoded result
-
encode
Description copied from interface:MediaTypeCodecEncode the given type returning the object as aByteBuffer.- Specified by:
encodein interfaceMediaTypeCodec- Type Parameters:
T- The generic typeB- The buffer type- Parameters:
object- The object to encodeallocator- The allocator- Returns:
- The decoded result
-
writeAttribute
- Parameters:
eventData- The byte bufferattribute- The attributevalue- The value
-