users@jersey.java.net

Re: [Jersey] How to find out content-length *before* unmarshalling?

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Tue, 29 Dec 2009 11:29:25 +0100

On Dec 28, 2009, at 12:01 PM, Markus Karg wrote:

> Tatu and Moises,
>
> thank you for your ideas. It seems the idea of using a counting "dev/
> null Stream" would be the most efficient one, since keeping the once
> streamed result for a later request might clutter RAM with possibly
> never requested String.
>

There is a Jersey specific solution: use a ContainerResponseFilter and
adapt the ContainerResponseWriter declared on the ContainerResponse to
write to a ByteArrayOutputStream the contents of which are written to
the adapted ContainerResponseWriter on finish.

Why do you need to know the length? for logging purposes or do you
want to set the Content-Length response header?

Paul.