bytearrayresponsewrapper.java

来自「一个用java编写的功能强大的OA系统」· Java 代码 · 共 72 行

JAVA
72
字号
package com.redmoon.oa;import javax.servlet.http.*;import java.io.ByteArrayOutputStream;import java.io.*;import javax.servlet.*;public class ByteArrayResponseWrapper extends HttpServletResponseWrapper {  private ByteArrayOutputStream output;  private int contentLength;  private String contentType;  public ByteArrayResponseWrapper(HttpServletResponse response) {    super(response);    output=new ByteArrayOutputStream();  }  public byte[] getData() {    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;  }}class FilterServletOutputStream extends ServletOutputStream {  private DataOutputStream stream;  public FilterServletOutputStream(OutputStream output) {    stream = new DataOutputStream(output);  }  public void write(int b) throws IOException  {    stream.write(b);  }  public void write(byte[] b) throws IOException  {    stream.write(b);  }  public void write(byte[] b, int off, int len) throws IOException  {    stream.write(b,off,len);  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?