@Test public void doFilterWithUnknownContentType() throws IOException, ServletException { final byte[] data = { 1, 2, 3 }; doFilter(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { HttpServletResponse response = (HttpServletResponse) invocation.getArguments()[1]; response.setContentLength(data.length); response.getOutputStream().write(data); return null; } }, null, data); }
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletResponse resp = (HttpServletResponse) response; TrimResponseWrapper trimResponse = new TrimResponseWrapper(resp); chain.doFilter(request, trimResponse); Boolean trimmable = trimResponse.isTrimmable(); if ((trimmable != null) && trimmable.booleanValue()) { byte[] data = getTrimmedData(trimResponse); response.setContentLength(data.length); response.getOutputStream().write(data); } }
TrimFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletResponse resp = (HttpServletResponse) response; TrimResponseWrapper trimResponse = new TrimResponseWrapper(resp); chain.doFilter(request, trimResponse); Boolean trimmable = trimResponse.isTrimmable(); if ((trimmable != null) && trimmable.booleanValue()) { byte[] data = getTrimmedData(trimResponse); response.setContentLength(data.length); response.getOutputStream().write(data); } } }
TrimFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletResponse resp = (HttpServletResponse) response; TrimResponseWrapper trimResponse = new TrimResponseWrapper(resp); chain.doFilter(request, trimResponse); Boolean trimmable = trimResponse.isTrimmable(); if ((trimmable != null) && trimmable.booleanValue()) { byte[] data = getTrimmedData(trimResponse); response.setContentLength(data.length); response.getOutputStream().write(data); } }  }
TrimFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletResponse resp = (HttpServletResponse) response; TrimResponseWrapper trimResponse = new TrimResponseWrapper(resp); chain.doFilter(request, trimResponse); Boolean trimmable = trimResponse.isTrimmable(); if ((trimmable != null) && trimmable.booleanValue()) { byte[] data = getTrimmedData(trimResponse); response.setContentLength(data.length); response.getOutputStream().write(data); } }  @Override void init(FilterConfig filterConfig); @Override void destroy(); @Override void doFilter(ServletRequest request, ServletResponse response, FilterChain chain); }
TrimFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletResponse resp = (HttpServletResponse) response; TrimResponseWrapper trimResponse = new TrimResponseWrapper(resp); chain.doFilter(request, trimResponse); Boolean trimmable = trimResponse.isTrimmable(); if ((trimmable != null) && trimmable.booleanValue()) { byte[] data = getTrimmedData(trimResponse); response.setContentLength(data.length); response.getOutputStream().write(data); } }  @Override void init(FilterConfig filterConfig); @Override void destroy(); @Override void doFilter(ServletRequest request, ServletResponse response, FilterChain chain);  }