Index: GZIPDecodingInterceptor.java =================================================================== --- GZIPDecodingInterceptor.java (revision 1368) +++ GZIPDecodingInterceptor.java (working copy) @@ -31,13 +31,15 @@ if (encoding != null && encoding.toString().equalsIgnoreCase("gzip")) { InputStream old = context.getInputStream(); - context.setInputStream(new GZIPInputStream(old)); + FinishableGZIPInputStream gzipInputStream = new FinishableGZIPInputStream(old); + context.setInputStream(gzipInputStream); try { return context.proceed(); } finally { + gzipInputStream.finish(); context.setInputStream(old); } } @@ -46,4 +48,18 @@ return context.proceed(); } } + + /** extension of {@link GZIPInputStream} which adds a finish method to ends the inflation; necessary to release native code pointers */ + private static class FinishableGZIPInputStream extends GZIPInputStream + { + public FinishableGZIPInputStream(final InputStream is) throws IOException + { + super(is); + } + + void finish() + { + inf.end(); // make sure on finish the inflater's end() is called to release the native code pointer + } + } } Index: GZIPEncodingInterceptor.java =================================================================== --- GZIPEncodingInterceptor.java (revision 1368) +++ GZIPEncodingInterceptor.java (working copy) @@ -30,7 +30,7 @@ if (encoding != null && encoding.toString().equalsIgnoreCase("gzip")) { OutputStream old = context.getOutputStream(); - GZIPOutputStream gzipOutputStream = new GZIPOutputStream(old); + CustomGZIPOutputStream gzipOutputStream = new CustomGZIPOutputStream(old); context.setOutputStream(gzipOutputStream); try { @@ -48,4 +48,20 @@ context.proceed(); } } + + /** extension of {@link GZIPOutputStream} which also ends the deflation on finish; necessary to release native code pointers */ + private static class CustomGZIPOutputStream extends GZIPOutputStream + { + public CustomGZIPOutputStream(OutputStream os) throws IOException + { + super(os); + } + + @Override + public void finish() throws IOException + { + super.finish(); + def.end(); // make sure on finish the deflater's end() is called to release the native code pointer + } + } }