View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.transformer.simple;
8   
9   import org.mule.api.transformer.TransformerException;
10  import org.mule.transformer.AbstractDiscoverableTransformer;
11  import org.mule.transformer.types.DataTypeFactory;
12  
13  import java.io.IOException;
14  
15  import javax.activation.DataHandler;
16  
17  public class DataHandlerToInputStreamTransformer extends AbstractDiscoverableTransformer
18  {
19  
20      public DataHandlerToInputStreamTransformer()
21      {
22          registerSourceType(DataTypeFactory.create(DataHandler.class));
23          setReturnDataType(DataTypeFactory.INPUT_STREAM);
24      }
25  
26      @Override
27      public Object doTransform(Object src, String enc) throws TransformerException
28      {
29          try
30          {
31              return ((DataHandler) src).getInputStream();
32          }
33          catch (IOException e)
34          {
35              throw new TransformerException(this, e);
36          }
37      }
38  }