1 /* 2 * $Id: StreamingBridgeComponent.java 7963 2007-08-21 08:53:15Z dirk.olmes $ 3 * -------------------------------------------------------------------------------------- 4 * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.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 package org.mule.components.simple; 11 12 import org.mule.impl.model.streaming.StreamingService; 13 import org.mule.umo.UMOEventContext; 14 import org.mule.util.IOUtils; 15 16 import java.io.InputStream; 17 import java.io.OutputStream; 18 19 /** 20 * A simple Bridging component that can be used with the Streaming Model to bridge from one 21 * transport stream to another. 22 */ 23 public class StreamingBridgeComponent implements StreamingService 24 { 25 26 public void call(InputStream in, OutputStream out, UMOEventContext context) throws Exception 27 { 28 if (out == null) 29 { 30 throw new IllegalStateException("There is no outputstream for this request on: " + context.getEndpointURI() + 31 ". This might be because this is a one way request, but the StreamingBridge component should not be used in this scenario"); 32 } 33 34 // TODO if we can find a way (e.g. for FTP) to pass in (remote) file's size, it would 35 // allow to detect stream corruption and broken connections by comparing the actually read 36 // and size values 37 IOUtils.copyLarge(in, out); 38 39 // once all data are copied we may as well close - it loses nothing and helps avoid 40 // timing errors in tests. 41 out.close(); 42 } 43 44 }