You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.5 KiB
62 lines
1.5 KiB
3 years ago
|
package com.fr.plugin.oauth.utils;
|
||
|
|
||
|
import javax.servlet.ServletOutputStream;
|
||
|
import javax.servlet.WriteListener;
|
||
|
import javax.servlet.http.HttpServletResponse;
|
||
|
import javax.servlet.http.HttpServletResponseWrapper;
|
||
|
import java.io.ByteArrayOutputStream;
|
||
|
import java.io.IOException;
|
||
|
|
||
|
public class ResponseWrapper extends HttpServletResponseWrapper {
|
||
|
|
||
|
private ByteArrayOutputStream buffer;
|
||
|
private ServletOutputStream out;
|
||
|
|
||
|
public ResponseWrapper(HttpServletResponse httpServletResponse) {
|
||
|
super(httpServletResponse);
|
||
|
buffer = new ByteArrayOutputStream();
|
||
|
out = new WrapperOutputStream(buffer);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public ServletOutputStream getOutputStream() throws IOException {
|
||
|
return out;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void flushBuffer() throws IOException {
|
||
|
if (out != null) {
|
||
|
out.flush();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public byte[] getContent() throws IOException {
|
||
|
flushBuffer();
|
||
|
return buffer.toByteArray();
|
||
|
}
|
||
|
|
||
|
class WrapperOutputStream extends ServletOutputStream {
|
||
|
private ByteArrayOutputStream bos;
|
||
|
|
||
|
public WrapperOutputStream(ByteArrayOutputStream bos) {
|
||
|
this.bos = bos;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void write(int b) throws IOException {
|
||
|
bos.write(b);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public boolean isReady() {
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void setWriteListener(WriteListener arg0) {
|
||
|
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|