Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.yammer.dropwizard.jetty;
  
  
 
 // TODO: 10/12/11 <coda> -- write tests for BiDiGzipHandler
 
A Jetty org.eclipse.jetty.server.Handler which both compresses response entities to requests with gzip as an acceptable content-encoding and decompresses request entities with gzip as the given content-encoding.
 
 @SuppressWarnings("IOResourceOpenedButNotSafelyClosed")
 public class BiDiGzipHandler extends GzipHandler {
     private static final String GZIP_ENCODING = "gzip";
 
     private static class GzipServletInputStream extends ServletInputStream {
         private final GZIPInputStream input;
 
         private GzipServletInputStream(HttpServletRequest requestint bufferSizethrows IOException {
             this. = new GZIPInputStream(request.getInputStream(), bufferSize);
         }
 
         @Override
         public void close() throws IOException {
             .close();
         }
 
         @Override
         public int read(byte[] bint offint lenthrows IOException {
             return .read(bofflen);
         }
 
         @Override
         public int available() throws IOException {
             return .available();
         }
 
         @Override
         public void mark(int readlimit) {
             .mark(readlimit);
         }
 
         @Override
         public boolean markSupported() {
             return .markSupported();
         }
 
         @Override
         public int read() throws IOException {
             return .read();
         }
 
         @Override
         public void reset() throws IOException {
             .reset();
         }
 
         @Override
         public long skip(long nthrows IOException {
             return .skip(n);
         }
 
         @Override
         public int read(byte[] bthrows IOException {
             return .read(b);
         }
     }
 
     private static class GzipServletRequest extends HttpServletRequestWrapper {
         private final ServletInputStream input;
         private final BufferedReader reader;
 
         private GzipServletRequest(HttpServletRequest requestint bufferSizethrows IOException {
             super(request);
             this. = new GzipServletInputStream(requestbufferSize);
             this. = new BufferedReader(new InputStreamReader());
         }
 
         @Override
         public ServletInputStream getInputStream() throws IOException {
             return ;
         }
 
         @Override
         public BufferedReader getReader() throws IOException {
             return ;
        }
    }

    
Creates a new BiDiGzipHandler which forwards requests to the given handler.

Parameters:
underlying the underlying handler
    public BiDiGzipHandler(Handler underlying) {
        setHandler(underlying);
    }
    @Override
    public void handle(String target,
                       Request baseRequest,
                       HttpServletRequest request,
                       HttpServletResponse responsethrows IOExceptionServletException {
            super.handle(target,
                         baseRequest,
                         new GzipServletRequest(request, getBufferSize()),
                         response);
        } else {
            super.handle(targetbaseRequestrequestresponse);
        }
    }
New to GrepCode? Check out our FAQ X