users@jersey.java.net

Re: [Jersey] Is returned InputStream closed?

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 25 Sep 2008 08:25:13 +0200

On Sep 24, 2008, at 10:56 PM, Zach Cox wrote:

> If I have a method that returns an InputStream:
>
> @GET
> public InputStream getSomething()
> {
> InputStream stream = ...;
> return stream;
> }
>
> Is that InputStream eventually closed by Jersey?

Yes, the message body writer for an input stream does this:

     public void writeTo(
             InputStream t,
             Class<?> type,
             Type genericType,
             Annotation annotations[],
             MediaType mediaType,
             MultivaluedMap<String, Object> httpHeaders,
             OutputStream entityStream) throws IOException {
         try {
             writeTo(t, entityStream);
         } finally {
             t.close();
         }
     }

Paul.

> If not, is there any
> way I can explicitly close it after Jersey is done with it?
>
> Thanks,
> Zach
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>