Coverage report

  %line %branch
org.apache.jetspeed.aggregator.impl.HttpBufferedResponse
0% 
0% 

 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  * 
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  * 
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.jetspeed.aggregator.impl;
 18  
 
 19  
 import java.io.IOException;
 20  
 import java.io.PrintWriter;
 21  
 import java.io.UnsupportedEncodingException;
 22  
 
 23  
 import org.apache.commons.logging.Log;
 24  
 import org.apache.commons.logging.LogFactory;
 25  
 import javax.servlet.ServletOutputStream;
 26  
 import javax.servlet.http.HttpServletResponse;
 27  
 import org.apache.pluto.util.PrintWriterServletOutputStream;
 28  
 
 29  
 public class HttpBufferedResponse extends javax.servlet.http.HttpServletResponseWrapper
 30  
 {
 31  
     private boolean usingWriter;
 32  
     private boolean usingStream;
 33  
 
 34  
     /** Commons logging */
 35  0
     protected final static Log log = LogFactory.getLog(HttpBufferedResponse.class);
 36  
 
 37  
     private ServletOutputStream wrappedStream;
 38  
     private PrintWriter writer;
 39  
 
 40  
     public HttpBufferedResponse(HttpServletResponse servletResponse,
 41  
                                 PrintWriter writer)
 42  
     {
 43  0
         super(servletResponse);
 44  0
         this.writer = writer;
 45  0
     }
 46  
 
 47  
     public ServletOutputStream getOutputStream() throws IllegalStateException, IOException
 48  
     {
 49  0
         if (usingWriter)
 50  
         {
 51  0
             throw new IllegalStateException("getOutputStream can't be used after getWriter was invoked");
 52  
         }
 53  
 
 54  0
         if (wrappedStream == null)
 55  
         {            
 56  0
             wrappedStream = new PrintWriterServletOutputStream(writer, getResponse().getCharacterEncoding());                                                               
 57  
         }
 58  
 
 59  0
         usingStream = true;
 60  
 
 61  0
         return wrappedStream;
 62  
     }
 63  
 
 64  
     public PrintWriter getWriter() throws UnsupportedEncodingException, IllegalStateException, IOException {
 65  
 
 66  0
         if (usingStream)
 67  
         {
 68  0
             throw new IllegalStateException("getWriter can't be used after getOutputStream was invoked");
 69  
         }
 70  
 
 71  0
         usingWriter = true;
 72  
 
 73  0
         return writer;
 74  
     }
 75  
 
 76  
 
 77  
     public void setBufferSize(int size)
 78  
     {
 79  
         // ignore
 80  0
     }
 81  
 
 82  
     public int getBufferSize()
 83  
     {
 84  0
         return 0;
 85  
     }
 86  
 
 87  
     public void flushBuffer() throws IOException
 88  
     {
 89  0
         writer.flush();
 90  0
     }
 91  
 
 92  
     public boolean isCommitted()
 93  
     {
 94  0
         return false;
 95  
     }
 96  
 
 97  
     public void reset()
 98  
     {
 99  
         // ignore right now
 100  0
     }
 101  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.