1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.web.includeservletasstring

File BufferedResponse.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart0.png
83% of files have more coverage

Code metrics

6
12
4
1
77
42
7
0.58
3
4
1.75

Classes

Class Line # Actions
BufferedResponse 30 12 0% 7 22
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software 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 GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package com.xpn.xwiki.web.includeservletasstring;
21   
22    import java.io.IOException;
23    import java.io.OutputStreamWriter;
24    import java.io.PrintWriter;
25   
26    import javax.servlet.ServletOutputStream;
27    import javax.servlet.http.HttpServletResponse;
28    import javax.servlet.http.HttpServletResponseWrapper;
29   
 
30    public class BufferedResponse extends HttpServletResponseWrapper
31    {
32    protected HttpServletResponse internalResponse;
33   
34    protected BufferOutputStream outputStream;
35   
36    protected PrintWriter writer;
37   
38    /** Creates a new instance of BufferedResponse */
 
39  0 toggle public BufferedResponse(HttpServletResponse internalResponse)
40    {
41  0 super(internalResponse);
42   
43  0 this.internalResponse = internalResponse;
44    }
45   
 
46  0 toggle @Override
47    public ServletOutputStream getOutputStream() throws IOException
48    {
49  0 if (this.outputStream == null) {
50  0 this.outputStream = new BufferOutputStream();
51    }
52   
53  0 return this.outputStream;
54    }
55   
 
56  0 toggle @Override
57    public PrintWriter getWriter() throws IOException
58    {
59  0 if (this.writer == null) {
60  0 this.writer = new PrintWriter(new OutputStreamWriter(getOutputStream(), getCharacterEncoding()));
61    }
62   
63  0 return this.writer;
64    }
65   
 
66  0 toggle public byte[] getBufferAsByteArray() throws IOException
67    {
68  0 if (this.writer != null) {
69  0 this.writer.flush();
70    }
71   
72  0 this.outputStream.flush();
73   
74  0 return this.outputStream.getContentsAsByteArray();
75    }
76   
77    }