KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > filters > gzip > ByteArrayServletOutputStream


1 /*
2  * Generator Runtime Servlet Framework
3  * Copyright (C) 2004 Rick Knowles
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public License
7  * Version 2 as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License Version 2 for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * Version 2 along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  */

18 package filters.gzip;
19
20 import java.io.ByteArrayOutputStream JavaDoc;
21 import java.io.IOException JavaDoc;
22
23 import javax.servlet.ServletOutputStream JavaDoc;
24
25 /**
26  * Acts as a simple byte array based output stream for servlet responses.
27  *
28  * @author <a HREF="mailto:rick_knowles@hotmail.com">Rick Knowles</a>
29  * @version $Id: ByteArrayServletOutputStream.java,v 1.1 2005/08/24 06:43:34 rickknowles Exp $
30  */

31 public class ByteArrayServletOutputStream extends ServletOutputStream JavaDoc {
32     
33     private ByteArrayOutputStream JavaDoc bodyStream;
34     
35     public ByteArrayServletOutputStream() {
36         this.bodyStream = new ByteArrayOutputStream JavaDoc();
37     }
38     
39     public byte[] getContent() {
40         return this.bodyStream.toByteArray();
41     }
42     
43     public void write(int b) throws IOException JavaDoc {
44         this.bodyStream.write(b);
45     }
46
47     public void flush() throws IOException JavaDoc {
48         this.bodyStream.flush();
49     }
50 }
51
Popular Tags