KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > killingar > servlet > filter > GenericResponseWrapper


1 /* Copyright 2000-2005 Anders Hovmöller
2  *
3  * The person or persons who have associated their work with
4  * this document (the "Dedicator") hereby dedicate the entire
5  * copyright in the work of authorship identified below (the
6  * "Work") to the public domain.
7  *
8  * Dedicator makes this dedication for the benefit of the
9  * public at large and to the detriment of Dedicator's heirs
10  * and successors. Dedicator intends this dedication to be an
11  * overt act of relinquishment in perpetuity of all present
12  * and future rights under copyright law, whether vested or
13  * contingent, in the Work. Dedicator understands that such
14  * relinquishment of all rights includes the relinquishment of
15  * all rights to enforce (by lawsuit or otherwise) those
16  * copyrights in the Work.
17  *
18  * Dedicator recognizes that, once placed in the public
19  * domain, the Work may be freely reproduced, distributed,
20  * transmitted, used, modified, built upon, or otherwise
21  * exploited by anyone for any purpose, commercial or non-
22  * commercial, and in any way, including by methods that have
23  * not yet been invented or conceived.
24  */

25
26 package net.killingar.servlet.filter;
27
28
29 import javax.servlet.ServletOutputStream JavaDoc;
30 import javax.servlet.http.HttpServletResponse JavaDoc;
31 import javax.servlet.http.HttpServletResponseWrapper JavaDoc;
32 import java.io.ByteArrayOutputStream JavaDoc;
33 import java.io.PrintWriter JavaDoc;
34
35
36 public class GenericResponseWrapper extends HttpServletResponseWrapper JavaDoc
37 {
38     private ByteArrayOutputStream JavaDoc output;
39     private int contentLength;
40     private String JavaDoc contentType;
41
42
43     /** @link dependency */
44
45
46     /*#FilterServletOutputStream lnkFilterServletOutputStream;*/
47
48
49     public byte[] getData()
50     {
51         return output.toByteArray();
52     }
53
54
55     public GenericResponseWrapper(HttpServletResponse JavaDoc response)
56     {
57         super(response);
58         output = new ByteArrayOutputStream JavaDoc();
59     }
60
61
62     public ServletOutputStream JavaDoc getOutputStream()
63     {
64         return new FilterServletOutputStream(output);
65     }
66
67
68     public void setContentLength(int length)
69     {
70         this.contentLength = length;
71         super.setContentLength(length);
72     }
73
74
75     public int getContentLength()
76     {
77         return contentLength;
78     }
79
80
81     public void setContentType(String JavaDoc type)
82     {
83         this.contentType = type;
84         super.setContentType(type);
85     }
86
87
88     public String JavaDoc getContentType()
89     {
90         return contentType;
91     }
92
93
94     public PrintWriter JavaDoc getWriter()
95     {
96         return new PrintWriter JavaDoc(getOutputStream(), true);
97     }
98 }
99
100
101
Popular Tags