commit | author | age
|
bc9f6a
|
1 |
/* |
U |
2 |
WebBox - Dein Server. |
|
3 |
Copyright (C) 2017 Ulrich Hilger, http://uhilger.de |
|
4 |
|
|
5 |
This program is free software: you can redistribute it and/or modify |
|
6 |
it under the terms of the GNU Affero General Public License as |
|
7 |
published by the Free Software Foundation, either version 3 of the |
|
8 |
License, or (at your option) any later version. |
|
9 |
|
|
10 |
This program is distributed in the hope that it will be useful, |
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
GNU Affero General Public License for more details. |
|
14 |
|
|
15 |
You should have received a copy of the GNU Affero General Public License |
|
16 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
17 |
*/ |
|
18 |
package de.uhilger.wbx.web; |
|
19 |
|
|
20 |
import java.io.ByteArrayOutputStream; |
|
21 |
import java.io.PrintWriter; |
|
22 |
import javax.servlet.ServletOutputStream; |
|
23 |
import javax.servlet.http.HttpServletResponse; |
|
24 |
import javax.servlet.http.HttpServletResponseWrapper; |
|
25 |
|
|
26 |
/** |
|
27 |
* |
|
28 |
* @author ulrich |
|
29 |
*/ |
|
30 |
public class GenericResponseWrapper extends HttpServletResponseWrapper { |
|
31 |
private ByteArrayOutputStream output; |
|
32 |
private int contentLength; |
|
33 |
private String contentType; |
|
34 |
|
|
35 |
public GenericResponseWrapper(HttpServletResponse response) { |
|
36 |
super(response); |
|
37 |
output=new ByteArrayOutputStream(); |
|
38 |
} |
|
39 |
|
|
40 |
public byte[] getData() { |
|
41 |
return output.toByteArray(); |
|
42 |
} |
|
43 |
|
|
44 |
public ServletOutputStream getOutputStream() { |
2ef1bb
|
45 |
FilterServletOutputStream f = new FilterServletOutputStream(output); |
U |
46 |
return f; |
bc9f6a
|
47 |
} |
U |
48 |
|
|
49 |
public PrintWriter getWriter() { |
2ef1bb
|
50 |
PrintWriter pw = new PrintWriter(getOutputStream(),true); |
U |
51 |
return pw; |
bc9f6a
|
52 |
} |
U |
53 |
|
|
54 |
public void setContentLength(int length) { |
|
55 |
this.contentLength = length; |
|
56 |
super.setContentLength(length); |
|
57 |
} |
|
58 |
|
|
59 |
public int getContentLength() { |
|
60 |
return contentLength; |
|
61 |
} |
|
62 |
|
|
63 |
public void setContentType(String type) { |
|
64 |
this.contentType = type; |
|
65 |
super.setContentType(type); |
|
66 |
} |
|
67 |
|
|
68 |
public String getContentType() { |
|
69 |
return contentType; |
|
70 |
} |
|
71 |
} |