Coverage Report - org.mule.impl.model.streaming.CallbackOutputStream
 
Classes in this File Line Coverage Branch Coverage Complexity
CallbackOutputStream
0%
0/21
0%
0/2
1.286
CallbackOutputStream$Callback
N/A
N/A
1.286
 
 1  
 /*
 2  
  * $Id: CallbackOutputStream.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.model.streaming;
 12  
 
 13  
 import java.io.IOException;
 14  
 import java.io.OutputStream;
 15  
 
 16  
 import org.apache.commons.logging.Log;
 17  
 import org.apache.commons.logging.LogFactory;
 18  
 
 19  
 public class CallbackOutputStream extends OutputStream
 20  
 {
 21  
 
 22  0
     protected final Log logger = LogFactory.getLog(CallbackOutputStream.class);
 23  
 
 24  
     public static interface Callback
 25  
     {
 26  
 
 27  
         public void onClose() throws Exception;
 28  
 
 29  
     }
 30  
 
 31  
     private OutputStream delegate;
 32  
     private Callback callback;
 33  
 
 34  
     public CallbackOutputStream(OutputStream delegate, Callback callback)
 35  0
     {
 36  0
         this.delegate = delegate;
 37  0
         this.callback = callback;
 38  0
     }
 39  
 
 40  
     public void write(int b) throws IOException
 41  
     {
 42  0
         delegate.write(b);
 43  0
     }
 44  
 
 45  
     public void write(byte b[]) throws IOException
 46  
     {
 47  0
         delegate.write(b);
 48  0
     }
 49  
 
 50  
     public void write(byte b[], int off, int len) throws IOException
 51  
     {
 52  0
         delegate.write(b, off, len);
 53  0
     }
 54  
 
 55  
     public void close() throws IOException
 56  
     {
 57  
         try
 58  
         {
 59  0
             delegate.close();
 60  
         }
 61  
         finally
 62  
         {
 63  0
             closeCallback();
 64  0
         }
 65  0
     }
 66  
 
 67  
     private void closeCallback()
 68  
     {
 69  0
         if (null != callback)
 70  
         {
 71  
             try
 72  
             {
 73  0
                 callback.onClose();
 74  
             }
 75  0
             catch(Exception e)
 76  
             {
 77  0
                 logger.debug("Suppressing exception while releasing resources: " + e.getMessage());
 78  0
             }
 79  
         }
 80  
 
 81  0
     }
 82  
 
 83  
 }