/*************************************************************************** * Copyright (c) junmix 2009. All rights reserved. * Program Name : GZIPResponseWrapper.java * Description : GZIP用レスポンスラッパークラス * Version : 1.00 * * Change Record * ------------- ----- --------------- ------------------------------------- * Date Ver. Editor Description * ------------- ----- --------------- ------------------------------------- * 2009-xx-xx 1.00 junmix 新規作成 * **************************************************************************/ package com.junmix.filter; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.PrintWriter; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponseWrapper; /** *

* [概 要] GZIP用レスポンスラッパークラス。 *

*

* [詳 細] XXX。 *

*

* [備 考] *

*

* [環 境] JDK 1.5.0_11 *

*

* Copyright(c) junmix 2009 *

*

* $Revision$ *

* * @author junmix * @since 1.00 */ public class GZIPResponseWrapper extends HttpServletResponseWrapper implements GZIPFilterConst { /** * Servletがクライアントに返すレスポンス内容を含むHttpServletResponse。 * * @since 1.00 */ protected HttpServletResponse originalResponse = null; /** * 出力ストリーム。 * * @since 1.00 */ protected ServletOutputStream servletOutputStream = null; /** * 出力ストリームへのライター。 * * @since 1.00 */ protected PrintWriter writer = null; /** *

* [概 要] コンストラクタ。 *

*

* [詳 細] *

*

* [備 考] *

* * @param response * Servletがクライアントに返すレスポンス内容を含むHttpServletResponse * @since 1.00 */ public GZIPResponseWrapper(HttpServletResponse response) { super(response); this.originalResponse = response; } /** *

* [概 要] ライター取得処理。 *

*

* [詳 細] 出力ストリームへShift_JISで書き込むライターを返す。 *

*

* [備 考] *

* * @throws IOException * 入出力エラー発生時 * @since 1.00 */ public PrintWriter getWriter() throws IOException { if (this.writer != null) { return this.writer; } if (this.servletOutputStream != null) { throw new IllegalStateException(EXCEPTION_MESSAGE_STREAM_ALREADY_OPENED); } this.servletOutputStream = this.createOutputStream(); this.writer = new PrintWriter(new OutputStreamWriter(this.servletOutputStream, RESPONSE_CHARSET_NAME)); return this.writer; } /** *

* [概 要] GZIP用ストリーム作成処理。 *

*

* [詳 細] GZIP用の出力ストリームを返す。 *

*

* [備 考] *

* * @throws IOException * 入出力エラー発生時 * @since 1.00 */ public ServletOutputStream createOutputStream() throws IOException { return new GZIPResponseStream(this.originalResponse); } /** *

* [概 要] 終了処理。 *

*

* [詳 細] クローズ時に残りのバッファがある場合は、書き出してから終了する。 *

*

* [備 考] *

* * @since 1.00 */ public void finishResponse() { try { if (this.writer != null) { this.writer.close(); } else { if (this.servletOutputStream != null) { this.servletOutputStream.close(); } } } catch (IOException ex) { ex.printStackTrace(); } } /** *

* [概 要] ストリームのフラッシュ処理。 *

*

* [詳 細] ストリームのフラッシュを行う。 *

*

* [備 考] *

* * @throws IOException * 入出力エラー発生時 * @since 1.00 */ public void flushBuffer() throws IOException { this.servletOutputStream.flush(); } /** *

* [概 要] 出力ストリーム取得処理。 *

*

* [詳 細] GZip用の出力ストリームを返す。 *

*

* [備 考] *

* * @throws IOException * 入出力エラー発生時 * @since 1.00 */ public ServletOutputStream getOutputStream() throws IOException { if (this.writer != null) { throw new IllegalStateException(EXCEPTION_MESSAGE_WRITER_ALREADY_OPENED); } if (this.servletOutputStream == null) { this.servletOutputStream = this.createOutputStream(); } return this.servletOutputStream; } /** *

* [概 要] メッセージボディ部の出力長設定処理。 *

*

* [詳 細] 何も行わない。 *

*

* [備 考] *

* * @param length * メッセージボディ部の出力長 * @since 1.00 */ public void setContentLength(int length) { // do nothing } }