Skip to content

Instantly share code, notes, and snippets.

@dvdsmpsn
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dvdsmpsn/3d23cc84e98537e7be43 to your computer and use it in GitHub Desktop.
Save dvdsmpsn/3d23cc84e98537e7be43 to your computer and use it in GitHub Desktop.
Servlet Filter Hokum
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
public class GenericResponseWrapper extends HttpServletResponseWrapper {
private ByteArrayOutputStream output =new ByteArrayOutputStream();
private int contentLength;
private String contentType;
public GenericResponseWrapper(HttpServletResponse response) {
super(response);
}
public byte[] getData() {
try {
output.flush();
output.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
return output.toByteArray();
}
public ServletOutputStream getOutputStream() {
return new FilterServletOutputStream(output);
}
public PrintWriter getWriter() {
return new PrintWriter(getOutputStream(),true);
}
public void setContentLength(int length) {
this.contentLength = length;
super.setContentLength(length);
}
public int getContentLength() {
return contentLength;
}
public void setContentType(String type) {
this.contentType = type;
super.setContentType(type);
}
public String getContentType() {
return contentType;
}
}
console.log('hello');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment