WebBox Klassenbibliothek
ulrich
2017-12-28 bc9f6a12a3bd068f1b9f781539c41d8d86b7e409
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() { 
45     return new FilterServletOutputStream(output); 
46   } 
47   
48   public PrintWriter getWriter() { 
49     return new PrintWriter(getOutputStream(),true); 
50   } 
51  
52   public void setContentLength(int length) { 
53     this.contentLength = length;
54     super.setContentLength(length); 
55   } 
56  
57   public int getContentLength() { 
58     return contentLength; 
59   } 
60  
61   public void setContentType(String type) { 
62     this.contentType = type;
63     super.setContentType(type); 
64   } 
65  
66   public String getContentType() { 
67     return contentType; 
68   } 
69