⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gzipresponsestream.java.svn-base

📁 EasyJWeb是基于java技术
💻 SVN-BASE
字号:
package com.easyjf.web;import java.io.ByteArrayOutputStream;import java.io.IOException;import java.util.zip.GZIPOutputStream;import javax.servlet.ServletOutputStream;import javax.servlet.http.HttpServletResponse;/** * for the gzipfilter *  * @author wlr *  */public class GZIPResponseStream extends ServletOutputStream {	protected ByteArrayOutputStream baos = null;	protected GZIPOutputStream gzipstream = null;	protected boolean closed = false;	protected HttpServletResponse response = null;	protected ServletOutputStream output = null;	public GZIPResponseStream(HttpServletResponse response) throws IOException {		super();		closed = false;		this.response = response;		this.output = response.getOutputStream();		baos = new ByteArrayOutputStream();		gzipstream = new GZIPOutputStream(baos);	}	public void close() throws IOException {		if (closed) {			throw new IOException("This output stream has already been closed");		}		gzipstream.finish();		byte[] bytes = baos.toByteArray();		response.addHeader("content-length", Integer.toString(bytes.length));		response.addHeader("content-encoding", "gzip");		output.write(bytes);		output.flush();		output.close();		closed = true;	}	public void flush() throws IOException {		if (closed) {			throw new IOException("Cannot flush a closed output stream");		}		gzipstream.flush();	}	public void write(int b) throws IOException {		if (closed) {			throw new IOException("Cannot write to a closed output stream");		}		gzipstream.write((byte) b);	}	public void write(byte b[]) throws IOException {		write(b, 0, b.length);	}	public void write(byte b[], int off, int len) throws IOException {		// System.out.println("等待");		if (closed) {			throw new IOException("Cannot write to a closed output stream");		}		gzipstream.write(b, off, len);	}	public boolean closed() {		return (this.closed);	}	public void reset() {	}}

⌨️ 快捷键说明

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