Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * $Id: InputStreamToByteArray.java 22370 2011-07-11 08:31:38Z dirk.olmes $
  * --------------------------------------------------------------------------------------
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
  *
  * The software in this package is published under the terms of the CPAL v1.0
  * license, a copy of which has been included with this distribution in the
  * LICENSE.txt file.
  */
package org.mule.transport.sftp.transformers;
TODO
{
    
Serial version
    private static final long serialVersionUID = -7444711427779720031L;
    public InputStreamToByteArray()
    {
    }
    @Override
    public Object doTransform(Object msgString outputEncodingthrows TransformerException
    {
        if (msg instanceof InputStream)
        {
            InputStream inputStream = null;
            try
            {
                inputStream = (InputStreammsg;
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                byte[] buffer = new byte[1024];
                int len;
                while ((len = inputStream.read(buffer)) > 0)
                {
                    baos.write(buffer, 0, len);
                }
                return baos.toByteArray();
            }
            catch (Exception e)
            {
                throw new TransformerException(thise);
            }
            finally
            {
                IOUtils.closeQuietly(inputStream);
            }
        }
        else
        {
            throw new TransformerException(
                MessageFactory.createStaticMessage("Message is not an instance of java.io.InputStream"), this);
        }
    }
New to GrepCode? Check out our FAQ X