Class SourceWrappers


public final class SourceWrappers extends Object
When request's contents are not buffered, Jersey's determines if the entity body input stream that backs a request can be closed by introspecting the return type of the MessageBodyReader. If the return type is a Closeable or a Source then it doesn't close it, otherwise it closes it.

We have MessageBodyReaders that deliver content as RS sources: in that case we do not want Jersey to close the backing input stream because the content has not been consumed yet when exiting the MessageBodyReader.readFrom(Class, Type, Annotation[], MediaType, MultivaluedMap, InputStream) method.

Since RS sources don't implement Closeable nor Source, this class provides wrappers that implement the latter, allowing us to prevent an untimely closure of the entity input stream.

Note that this is only necessary when a user-provided entity input stream is used, which can only happen when a filter or interceptor has replaced the one we've put in place at request creation time. Indeed, the close() method of the entity stream we initially provide (BufferPublisherInputStream) is a no-op so it doesn't matter if it gets called.

See Also:
  • InboundMessageContext.readEntity(Class, Type, Annotation[], PropertiesDelegate)