Coverage Report - org.mule.transformer.simple.StringAppendTransformer
 
Classes in this File Line Coverage Branch Coverage Complexity
StringAppendTransformer
0%
0/24
0%
0/4
1.333
 
 1  
 /*
 2  
  * $Id: StringAppendTransformer.java 11316 2008-03-11 15:50:38Z 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.transformer.simple;
 12  
 
 13  
 import org.mule.api.transformer.TransformerException;
 14  
 import org.mule.transformer.AbstractTransformer;
 15  
 import org.mule.util.IOUtils;
 16  
 import org.mule.util.StringUtils;
 17  
 
 18  
 import java.io.InputStream;
 19  
 
 20  
 public class StringAppendTransformer extends AbstractTransformer
 21  
 {
 22  
 
 23  0
     private String message = StringUtils.EMPTY;
 24  
 
 25  
     public StringAppendTransformer()
 26  
     {
 27  0
         this(StringUtils.EMPTY);
 28  0
     }
 29  
 
 30  
     public StringAppendTransformer(String message)
 31  0
     {
 32  0
         this.message = message;
 33  0
         setReturnClass(String.class);
 34  0
         registerSourceType(String.class);
 35  0
         registerSourceType(byte[].class);
 36  0
         registerSourceType(InputStream.class);
 37  0
     }
 38  
 
 39  
     protected Object doTransform(Object src, String encoding) throws TransformerException
 40  
     {
 41  
         String string;
 42  0
         if (src instanceof byte[])
 43  
         {
 44  0
             string = new String((byte[]) src);
 45  
         }
 46  0
         else if (src instanceof InputStream)
 47  
         {
 48  0
             InputStream input = (InputStream) src;
 49  
             try
 50  
             {
 51  0
                 string = IOUtils.toString(input);
 52  
             }
 53  
             finally
 54  
             {
 55  0
                 IOUtils.closeQuietly(input);
 56  0
             }
 57  0
         }
 58  
         else
 59  
         {
 60  0
             string = (String) src;
 61  
         }
 62  
 
 63  0
         return append(message, string);
 64  
     }
 65  
 
 66  
     public static String append(String append, String msg)
 67  
     {
 68  0
         return msg + append;
 69  
     }
 70  
 
 71  
     public String getMessage()
 72  
     {
 73  0
         return message;
 74  
     }
 75  
 
 76  
     public void setMessage(String message)
 77  
     {
 78  0
         this.message = message;
 79  0
     }
 80  
 
 81  
 }