users@jax-rs-spec.java.net

[jax-rs-spec users] [jsr339-experts] Re: Re: Gzipping Interceptors

From: Markus KARG <markus_at_headcrashing.eu>
Date: Mon, 29 Oct 2012 20:13:31 +0100

 

+1

 

 

From: Santiago Pericas-Geertsen [mailto:Santiago.PericasGeertsen_at_oracle.com]

Sent: Montag, 29. Oktober 2012 15:29
To: jsr339-experts_at_jax-rs-spec.java.net
Subject: [jsr339-experts] Re: [jax-rs-spec users] Re: Gzipping Interceptors

 

 

On Oct 29, 2012, at 3:30 AM, Jan Algermissen <jan.algermissen_at_nordsc.com>
wrote:






On Oct 27, 2012, at 4:41 PM, Marek Potociar <
<mailto:marek.potociar_at_oracle.com> marek.potociar_at_oracle.com> wrote:




The examples in the spec illustrate JAX-RS APIs not any particular feature
implemented with these APIs. So I think we should keep the examples
simplistic in the spec. The features you're talking about will be most
likely provided by more skilled developers anyway.


After mulling this over, I disagree. The examples also bother to show
finishing the gzip OS and restoring the original OS.

 

 It's certainly not the intent of the spec samples to be 100% precise;
conciseness is a more important goal IMO. However, it wouldn't affect
conciseness much to write:

 

    @Override
    Object aroundReadFrom(ReaderInterceptorContext ctx) ... {
       if (isGzipped(ctx)) {
            InputStream old = ctx.getInputStream();
            ctx.setInputStream(new GZIPInputStream(old));
            try {
                return ctx.proceed();
            } finally {
                ctx.setInputStream(old);
            }
        } else {
            return ctx.proceed();
        }
    }
 
    @Override
    void aroundWriteTo(WriterInterceptorContext ctx) ... {
        OutputStream old = ctx.getOutputStream();
        GZIPOutputStream gzipOutputStream = new GZIPOutputStream(old);
        ctx.setOutputStream(gzipOutputStream);
        updateHeaders(ctx);
        try {
            ctx.proceed();
        } finally {
            gzipOutputStream.finish();
            ctx.setOutputStream(old);
        }
    }

 

 Could we move on from this discussion with this simple change?

 

-- Santiago