Package org.jaxxy.io

Class CharacterMessageBodyProvider<T>

  • Type Parameters:
    T - the type supported by this provider
    All Implemented Interfaces:
    javax.ws.rs.ext.MessageBodyReader<T>, javax.ws.rs.ext.MessageBodyWriter<T>
    Direct Known Subclasses:
    JsonMessageBodyProvider

    public abstract class CharacterMessageBodyProvider<T>
    extends MessageBodyProvider<T>
    A character stream-based message body provider. This provider takes care of creating Readers and Writers with the proper charset.
    • Constructor Detail

      • CharacterMessageBodyProvider

        public CharacterMessageBodyProvider()
    • Method Detail

      • readFrom

        protected abstract T readFrom​(Class<T> type,
                                      Type genericType,
                                      Annotation[] annotations,
                                      javax.ws.rs.core.MediaType mediaType,
                                      javax.ws.rs.core.MultivaluedMap<String,​String> httpHeaders,
                                      Reader reader)
                               throws IOException
        Reads the HTTP entity from a Reader. This is the character stream equivalent to MessageBodyReader.readFrom(Class, Type, Annotation[], MediaType, MultivaluedMap, InputStream).
        Parameters:
        type - the type that is to be read.
        genericType - the type of instance to be produced.
        annotations - an array of the annotations on the declaration of the artifact that will be initialized with the produced instance.
        mediaType - the media type of the HTTP entity.
        httpHeaders - the read-only HTTP headers associated with HTTP entity.
        reader - the Reader for the HTTP entity. The implementation should NOT close this reader!
        Returns:
        the entity
        Throws:
        IOException
        See Also:
        MessageBodyReader.readFrom(Class, Type, Annotation[], MediaType, MultivaluedMap, InputStream)
      • writeTo

        protected abstract void writeTo​(T t,
                                        Class<?> type,
                                        Type genericType,
                                        Annotation[] annotations,
                                        javax.ws.rs.core.MediaType mediaType,
                                        javax.ws.rs.core.MultivaluedMap<String,​Object> httpHeaders,
                                        Writer writer)
                                 throws IOException
        Writes the HTTP entity to a Writer. This is the character stream equivalent to MessageBodyWriter.writeTo(Object, Class, Type, Annotation[], MediaType, MultivaluedMap, OutputStream).
        Parameters:
        t - the instance to write.
        type - the class of instance that is to be written.
        genericType - the type of instance to be written.
        annotations - an array of the annotations attached to the message entity instance.
        mediaType - the media type of the HTTP entity.
        httpHeaders - a mutable map of the HTTP message headers.
        writer - the Writer for the HTTP entity. The implementation should NOT close this writer!
        Throws:
        IOException
        See Also:
        MessageBodyWriter.writeTo(Object, Class, Type, Annotation[], MediaType, MultivaluedMap, OutputStream)
      • defaultCharset

        protected Charset defaultCharset()
        Returns the default charset to be used by this provider if no other charset is specified. This default implementation returns StandardCharsets.UTF_8.
        Returns:
        the default charset (UTF-8)