View Javadoc

1   /*
2    * $Id: DataHandlerToInputStreamTransformer.java 21114 2011-01-26 15:29:13Z aperepel $
3    * -------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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.AbstractDiscoverableTransformer;
15  import org.mule.transformer.types.DataTypeFactory;
16  
17  import java.io.IOException;
18  
19  import javax.activation.DataHandler;
20  
21  public class DataHandlerToInputStreamTransformer extends AbstractDiscoverableTransformer
22  {
23  
24      public DataHandlerToInputStreamTransformer()
25      {
26          registerSourceType(DataTypeFactory.create(DataHandler.class));
27          setReturnDataType(DataTypeFactory.INPUT_STREAM);
28      }
29  
30      @Override
31      public Object doTransform(Object src, String enc) throws TransformerException
32      {
33          try
34          {
35              return ((DataHandler) src).getInputStream();
36          }
37          catch (IOException e)
38          {
39              throw new TransformerException(this, e);
40          }
41      }
42  }