Coverage Report - org.mule.impl.ResponseOutputStream
 
Classes in this File Line Coverage Branch Coverage Complexity
ResponseOutputStream
0%
0/21
0%
0/1
1.286
 
 1  
 /*
 2  
  * $Id: ResponseOutputStream.java 7976 2007-08-21 14:26:13Z 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.impl;
 12  
 
 13  
 import java.io.BufferedOutputStream;
 14  
 import java.io.IOException;
 15  
 import java.io.OutputStream;
 16  
 import java.net.Socket;
 17  
 
 18  
 import org.apache.commons.io.output.ByteArrayOutputStream;
 19  
 
 20  
 /**
 21  
  * <code>ResponseOutputStream</code> is an output stream associated with the
 22  
  * currently received event. Note that if the stream is from a socket the socket is
 23  
  * also available on this stream so that the socket state can be validated before
 24  
  * writing.
 25  
  */
 26  
 
 27  
 public class ResponseOutputStream extends BufferedOutputStream
 28  
 {
 29  0
     private static ByteArrayOutputStream defaultStream = new ByteArrayOutputStream();
 30  
 
 31  0
     private boolean used = false;
 32  0
     private boolean isDefault = false;
 33  0
     private Socket socket = null;
 34  
 
 35  
     public ResponseOutputStream()
 36  
     {
 37  0
         super(defaultStream);
 38  0
         isDefault = true;
 39  0
     }
 40  
 
 41  
     public ResponseOutputStream(OutputStream stream)
 42  
     {
 43  0
         super(stream);
 44  0
     }
 45  
 
 46  
     public ResponseOutputStream(Socket socket) throws IOException
 47  
     {
 48  0
         super(socket.getOutputStream());
 49  0
         this.socket = socket;
 50  0
     }
 51  
 
 52  
     public void write(int b) throws IOException
 53  
     {
 54  0
         super.write(b);
 55  0
         used = true;
 56  0
     }
 57  
 
 58  
     public byte[] getBytes() throws IOException
 59  
     {
 60  0
         if (isDefault)
 61  
         {
 62  0
             flush();
 63  0
             return defaultStream.toByteArray();
 64  
         }
 65  0
         return null;
 66  
     }
 67  
 
 68  
     public boolean isUsed()
 69  
     {
 70  0
         return used;
 71  
     }
 72  
 
 73  
     public Socket getSocket()
 74  
     {
 75  0
         return socket;
 76  
     }
 77  
 }