org.yelong.support.servlet.wrapper.PrintWriterWrapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of yelong-support Show documentation
Show all versions of yelong-support Show documentation
对各种开源框架的包装、支持、拓展。这里也包含的yelong-core与orm框架的整合。
默认对所有依赖为 scope 为 provided 。您需要针对自己的需要进行再次依赖
/**
*
*/
package org.yelong.support.servlet.wrapper;
import java.io.OutputStream;
import java.io.PrintWriter;
/**
* PrintWriter包装器
* 内部使用 {@link StringBuilder}来存储数据
*
* @author PengFei
*/
public class PrintWriterWrapper extends PrintWriter{
private StringBuilder stringBuilder;
public PrintWriterWrapper(OutputStream out) {
super(out);
stringBuilder = new StringBuilder();
}
public void write(char[] buf, int off, int len) {
super.write(buf, off, len);
char[] dest = new char[len];
System.arraycopy(buf, off, dest, 0, len);
stringBuilder.append(dest);
}
@Override
public void write(char[] buf) {
super.write(buf);
}
@Override
public void write(int c) {
super.write(c);
}
@Override
public void write(String s, int off, int len) {
super.write(s, off, len);
stringBuilder.append(s);
}
@Override
public void write(String s) {
super.write(s);
}
public String getContent(){
return stringBuilder.toString();
}
/**
* 重置打印的内容
*/
public void reset() {
stringBuilder.setLength(0);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy