Last active
August 29, 2015 13:57
-
-
Save dvdsmpsn/3d23cc84e98537e7be43 to your computer and use it in GitHub Desktop.
Servlet Filter Hokum
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log('hello'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment