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 Details

  • Constructor Details

  • Method Details

    • getMediaTypes

      public Collection<MediaType> getMediaTypes()
      Specified by:
      getMediaTypes in interface MediaTypeCodec
      Returns:
      The media type of the codec
    • decode

      public <T> T decode(Argument<T> type, InputStream inputStream)
      Description copied from interface: MediaTypeCodec
      Decode the given type from the given InputStream.
      Specified by:
      decode in interface MediaTypeCodec
      Type Parameters:
      T - The generic type
      Parameters:
      type - The type
      inputStream - The input stream
      Returns:
      The decoded result
    • decode

      public <T> T decode(Class<T> type, InputStream inputStream)
      Description copied from interface: MediaTypeCodec
      Decode the given type from the given InputStream.
      Specified by:
      decode in interface MediaTypeCodec
      Type Parameters:
      T - The generic type
      Parameters:
      type - The type
      inputStream - The input stream
      Returns:
      The decoded result
    • encode

      public <T> void encode(T object, OutputStream outputStream)
      Description copied from interface: MediaTypeCodec
      Encode the given type to the given OutputStream.
      Specified by:
      encode in interface MediaTypeCodec
      Type Parameters:
      T - The generic type
      Parameters:
      object - The object to encode
      outputStream - The output stream
    • encode

      public <T> byte[] encode(T object)
      Description copied from interface: MediaTypeCodec
      Encode the given type returning the object as a byte[].
      Specified by:
      encode in interface MediaTypeCodec
      Type Parameters:
      T - The generic type
      Parameters:
      object - The object to encode
      Returns:
      The decoded result
    • encode

      public <T, B> ByteBuffer<B> encode(T object, ByteBufferFactory<?,B> allocator)
      Description copied from interface: MediaTypeCodec
      Encode the given type returning the object as a ByteBuffer.
      Specified by:
      encode in interface MediaTypeCodec
      Type Parameters:
      T - The generic type
      B - The buffer type
      Parameters:
      object - The object to encode
      allocator - The allocator
      Returns:
      The decoded result
    • writeAttribute

      protected void writeAttribute(ByteBuffer eventData, byte[] attribute, String value)
      Parameters:
      eventData - The byte buffer
      attribute - The attribute
      value - The value