objecttoinputstream.java
来自「提供ESB 应用mule源代码 提供ESB 应用mule源代码」· Java 代码 · 共 66 行
JAVA
66 行
/* * $Id: ObjectToInputStream.java 10621 2008-01-30 12:15:16Z dirk.olmes $ * -------------------------------------------------------------------------------------- * 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.transformer.simple;import org.mule.RequestContext;import org.mule.api.transformer.TransformerException;import org.mule.api.transport.OutputHandler;import java.io.ByteArrayInputStream;import java.io.ByteArrayOutputStream;import java.io.InputStream;/** * <code>ObjectToInputStream</code> converts serilaizable object to a input stream but * treats <code>java.lang.String</code> differently by converting to bytes using * the <code>String.getBytrs()</code> method. */public class ObjectToInputStream extends SerializableToByteArray{ public ObjectToInputStream() { this.registerSourceType(String.class); this.registerSourceType(OutputHandler.class); setReturnClass(InputStream.class); } // @Override public Object doTransform(Object src, String encoding) throws TransformerException { try { if (src instanceof String) { return new ByteArrayInputStream(((String) src).getBytes(encoding)); } else if (src instanceof OutputHandler) { OutputHandler oh = (OutputHandler) src; ByteArrayOutputStream out = new ByteArrayOutputStream(); oh.write(RequestContext.getEvent(), out); return new ByteArrayInputStream(out.toByteArray()); } } catch (Exception e) { throw new TransformerException(this, e); } byte[] bytes = (byte[]) super.doTransform(src, encoding); return new ByteArrayInputStream(bytes); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?