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.
85 lines
2.1 KiB
85 lines
2.1 KiB
3 years ago
|
package com.fr.plugin.xxxx.xxxx.menu;
|
||
|
|
||
|
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.DataOutputStream;
|
||
|
import java.io.IOException;
|
||
|
import java.io.OutputStream;
|
||
|
|
||
|
|
||
|
/**
|
||
|
* @author fr.open
|
||
|
* @Date 2021/8/1
|
||
|
*/
|
||
|
public class ResponseWrapperImpl extends HttpServletResponseWrapper {
|
||
|
ByteArrayOutputStream output;
|
||
|
FilterServletOutputStream filterOutput;
|
||
|
|
||
|
public ResponseWrapperImpl(HttpServletResponse response) {
|
||
|
super(response);
|
||
|
output = new ByteArrayOutputStream();
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public ServletOutputStream getOutputStream() throws IOException {
|
||
|
if (filterOutput == null) {
|
||
|
filterOutput = new FilterServletOutputStream(output);
|
||
|
}
|
||
|
return filterOutput;
|
||
|
}
|
||
|
|
||
|
public void setContent(ByteArrayOutputStream output){
|
||
|
this.output = output;
|
||
|
this.filterOutput = null;
|
||
|
}
|
||
|
|
||
|
public void clear(){
|
||
|
output = new ByteArrayOutputStream();
|
||
|
filterOutput = new FilterServletOutputStream(output);
|
||
|
}
|
||
|
public ByteArrayOutputStream getOut(){
|
||
|
return output;
|
||
|
}
|
||
|
|
||
|
public byte[] getDataStream() {
|
||
|
return output.toByteArray();
|
||
|
}
|
||
|
|
||
|
class FilterServletOutputStream extends ServletOutputStream {
|
||
|
DataOutputStream output;
|
||
|
|
||
|
public FilterServletOutputStream(OutputStream output) {
|
||
|
this.output = new DataOutputStream(output);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void write(int arg0) throws IOException {
|
||
|
output.write(arg0);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void write(byte[] arg0, int arg1, int arg2) throws IOException {
|
||
|
output.write(arg0, arg1, arg2);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void write(byte[] arg0) throws IOException {
|
||
|
output.write(arg0);
|
||
|
System.out.printf("");
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public boolean isReady() {
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void setWriteListener(WriteListener writeListener) {
|
||
|
|
||
|
}
|
||
|
}
|
||
|
}
|