Coverage Report - org.mule.providers.http.ResponseWriter
 
Classes in this File Line Coverage Branch Coverage Complexity
ResponseWriter
57%
24/42
50%
3/6
1.214
 
 1  
 /*
 2  
  * $Id: ResponseWriter.java 7963 2007-08-21 08:53:15Z dirk.olmes $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 
 11  
 package org.mule.providers.http;
 12  
 
 13  
 import java.io.BufferedWriter;
 14  
 import java.io.FilterWriter;
 15  
 import java.io.IOException;
 16  
 import java.io.OutputStream;
 17  
 import java.io.OutputStreamWriter;
 18  
 import java.io.UnsupportedEncodingException;
 19  
 
 20  
 /**
 21  
  * Provides a hybrid Writer/OutputStream for sending HTTP response data
 22  
  */
 23  
 public class ResponseWriter extends FilterWriter
 24  
 {
 25  
     public static final String CRLF = "\r\n";
 26  
     public static final String ISO_8859_1 = "ISO-8859-1";
 27  144
     private OutputStream outStream = null;
 28  144
     private String encoding = null;
 29  
 
 30  
     public ResponseWriter(final OutputStream outStream) throws UnsupportedEncodingException
 31  
     {
 32  0
         this(outStream, CRLF, ISO_8859_1);
 33  0
     }
 34  
 
 35  
     public ResponseWriter(final OutputStream outStream, final String encoding)
 36  
         throws UnsupportedEncodingException
 37  
     {
 38  146
         this(outStream, CRLF, encoding);
 39  144
     }
 40  
 
 41  
     public ResponseWriter(final OutputStream outStream, final String lineSeparator, final String encoding)
 42  
         throws UnsupportedEncodingException
 43  
     {
 44  146
         super(new BufferedWriter(new OutputStreamWriter(outStream, encoding)));
 45  144
         this.outStream = outStream;
 46  144
         this.encoding = encoding;
 47  144
     }
 48  
 
 49  
     public String getEncoding()
 50  
     {
 51  0
         return encoding;
 52  
     }
 53  
 
 54  
     public void close() throws IOException
 55  
     {
 56  4
         if (outStream != null)
 57  
         {
 58  4
             super.close();
 59  4
             outStream = null;
 60  
         }
 61  4
     }
 62  
 
 63  
     /*
 64  
      * (non-Javadoc)
 65  
      * 
 66  
      * @see java.io.Writer#flush()
 67  
      */
 68  
     public void flush() throws IOException
 69  
     {
 70  144
         if (outStream != null)
 71  
         {
 72  144
             super.flush();
 73  144
             outStream.flush();
 74  
         }
 75  144
     }
 76  
 
 77  
     public void write(byte b) throws IOException
 78  
     {
 79  0
         super.flush();
 80  0
         outStream.write(b);
 81  0
     }
 82  
 
 83  
     public void write(byte[] b) throws IOException
 84  
     {
 85  0
         super.flush();
 86  0
         outStream.write(b);
 87  0
     }
 88  
 
 89  
     public void write(byte[] b, int off, int len) throws IOException
 90  
     {
 91  0
         super.flush();
 92  0
         outStream.write(b, off, len);
 93  0
     }
 94  
 
 95  
     public void print(String s) throws IOException
 96  
     {
 97  856
         if (s == null)
 98  
         {
 99  0
             s = "null";
 100  
         }
 101  856
         write(s);
 102  856
     }
 103  
 
 104  
     public void print(int i) throws IOException
 105  
     {
 106  0
         write(Integer.toString(i));
 107  0
     }
 108  
 
 109  
     public void println(int i) throws IOException
 110  
     {
 111  0
         write(Integer.toString(i));
 112  0
         write(CRLF);
 113  0
     }
 114  
 
 115  
     public void println(String s) throws IOException
 116  
     {
 117  144
         print(s);
 118  144
         write(CRLF);
 119  144
     }
 120  
 
 121  
     public void println() throws IOException
 122  
     {
 123  144
         write(CRLF);
 124  144
     }
 125  
 
 126  
 }