bytearrayoutputstreamwrapper.java
来自「这个weblogging 设计得比较精巧」· Java 代码 · 共 83 行
JAVA
83 行
package org.roller.presentation.filters;import java.io.ByteArrayOutputStream;import java.io.OutputStream;import javax.servlet.ServletOutputStream;/* * @author llavandowska * * Implementation of ServletOutputStream that allows the filter to hold the * Response content for insertion into the cache. */public class ByteArrayOutputStreamWrapper extends ServletOutputStream{ protected OutputStream intStream; protected ByteArrayOutputStream baStream; protected boolean finallized = false; protected boolean flushOnFinalizeOnly = true; public ByteArrayOutputStreamWrapper(OutputStream outStream) { intStream = outStream; baStream = new ByteArrayOutputStream(); } public ByteArrayOutputStreamWrapper() { intStream = System.out; baStream = new ByteArrayOutputStream(); } public ByteArrayOutputStream getByteArrayStream() { return baStream; } public void setFinallized() { finallized = true; } public boolean isFinallized() { return finallized; } public void write(int i) throws java.io.IOException { baStream.write(i); } public void close() throws java.io.IOException { if (finallized) { processStream(); intStream.close(); } } public void flush() throws java.io.IOException { if (baStream.size() != 0) { if (!flushOnFinalizeOnly || finallized) { processStream(); baStream = new ByteArrayOutputStream(); } } } protected void processStream() throws java.io.IOException { intStream.write(baStream.toByteArray()); intStream.flush(); } public void clear() { baStream = new ByteArrayOutputStream(); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?