⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filetostring.java

📁 提供ESB 应用mule源代码 提供ESB 应用mule源代码
💻 JAVA
字号:
/* * $Id: FileToString.java 11967 2008-06-05 20:32:19Z dfeist $ * -------------------------------------------------------------------------------------- * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.file.transformers;import org.mule.api.transformer.TransformerException;import org.mule.util.IOUtils;import java.io.File;import java.io.InputStream;import java.io.UnsupportedEncodingException;/** * <code>FileToString</code> reads file contents into a string. */public class FileToString extends FileToByteArray{    public FileToString()    {        registerSourceType(File.class);        registerSourceType(InputStream.class);        registerSourceType(byte[].class);        setReturnClass(String.class);    }    /**     * Simple implementation which relies on {@link FileToByteArray} to get a     * <code>byte[]</code> from the file beeing parsed and then transform it to a     * String with the correct encoding. If the encoding isn't supported simply throw     * an exception, good tranformation or no transformation at all. NOTE: if a     * <code>byte[]</code> is passed in as a source object this transformer accepts     * it and tries the usual transformation.     */    // @Override    public Object doTransform(Object src, String encoding) throws TransformerException    {        byte[] bytes;        if (src instanceof InputStream)        {            bytes = IOUtils.toByteArray((InputStream) src);        }        else if (src instanceof byte[])        {            bytes = (byte[])src;        }        else        {            bytes = (byte[])super.doTransform(src, encoding);        }        try        {            return new String(bytes, encoding);        }        catch (UnsupportedEncodingException uee)        {            throw new TransformerException(this, uee);        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -