Coverage Report - org.apache.commons.messagelet.impl.BufferedServletOutputStream
 
Classes in this File Line Coverage Branch Coverage Complexity
BufferedServletOutputStream
0%
0/24
N/A
1
 
 1  
 /*
 2  
  * Copyright (C) The Apache Software Foundation. All rights reserved.
 3  
  *
 4  
  * This software is published under the terms of the Apache Software License
 5  
  * version 1.1, a copy of which has been included with this distribution in
 6  
  * the LICENSE file.
 7  
  * 
 8  
  * $Id: BufferedServletOutputStream.java 155459 2005-02-26 13:24:44Z dirkv $
 9  
  */
 10  
 package org.apache.commons.messagelet.impl;
 11  
 
 12  
 import java.io.ByteArrayOutputStream;
 13  
 import java.io.IOException;
 14  
 import java.io.OutputStream;
 15  
 import java.io.UnsupportedEncodingException;
 16  
 
 17  
 import javax.servlet.ServletOutputStream;
 18  
 
 19  
 /** 
 20  
  * <p><code>BufferedServletOutputStream</code> implements
 21  
  * a buffered ServletOutputStream in a similar way to
 22  
  * ByteArrayOutputStream represents a buffered OutputStream.</p>
 23  
  *
 24  
   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
 25  
   * @version $Revision: 155459 $
 26  
  */
 27  
 public class BufferedServletOutputStream extends ServletOutputStream {
 28  
     
 29  
     /** The underlying <code>ByteArrayOutputStream</code> that the output
 30  
      * is written to */
 31  
     protected ByteArrayOutputStream buffer;
 32  
     
 33  
     
 34  0
     public BufferedServletOutputStream() {
 35  0
         buffer = new ByteArrayOutputStream();
 36  0
     }
 37  
     
 38  0
     public BufferedServletOutputStream(int size) {
 39  0
         buffer = new ByteArrayOutputStream(size);
 40  0
     }
 41  
     
 42  
     // Delegating methods from OutputStream
 43  
     //-------------------------------------------------------------------------    
 44  
     
 45  
     public void write(byte[] b) throws  IOException {
 46  0
         buffer.write(b);
 47  0
     }
 48  
     
 49  
     public void write(byte[] b, int off, int len) throws  IOException {
 50  0
         buffer.write(b, off, len);
 51  0
     }
 52  
     
 53  
     public void write(int b) throws  IOException {
 54  0
         buffer.write(b);
 55  0
     }
 56  
         
 57  
     public void close() throws  IOException {
 58  0
         buffer.close();
 59  0
     }
 60  
     
 61  
     public void flush() throws  IOException {
 62  0
         buffer.flush();
 63  0
     }    
 64  
     
 65  
     
 66  
     // Methods promoted from ByteArrayOutputStream
 67  
     //-------------------------------------------------------------------------    
 68  
     
 69  
     /** Resets the count field of this buffer to zero, 
 70  
      * so that all currently accumulated output in the 
 71  
      * ouput stream is discarded. 
 72  
      */
 73  
     public void reset() {
 74  0
         buffer.reset();
 75  0
     }
 76  
  
 77  
     /** Returns the current size of the buffer. 
 78  
      */ 
 79  
     public int size() {
 80  0
         return buffer.size();
 81  
     }
 82  
     
 83  
 
 84  
     
 85  
     /** Creates a newly allocated byte array. 
 86  
      */
 87  
     public byte[] toByteArray() {
 88  0
         return buffer.toByteArray();
 89  
     }
 90  
     
 91  
     /** Converts the buffer's contents into a string, 
 92  
      * translating bytes into characters according 
 93  
      * to the platform's default character encoding. 
 94  
      */          
 95  
     public String toString() {
 96  0
         return buffer.toString();
 97  
     }
 98  
        
 99  
     /** Converts the buffer's contents into a string, 
 100  
      * translating bytes into characters according 
 101  
      * to the specified character encoding. 
 102  
      */
 103  
     public String toString(String enc) throws UnsupportedEncodingException {
 104  0
         return buffer.toString(enc);
 105  
     }
 106  
           
 107  
     /** Writes the complete contents of this buffer
 108  
      * to the specified output stream argument, 
 109  
      * as if by calling the output stream's write 
 110  
      * method using out.write(buf, 0, count). 
 111  
      */
 112  
     public void writeTo(OutputStream out) throws  IOException {
 113  0
         buffer.writeTo(out);
 114  0
     }
 115  
     
 116  
 }