View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2008 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of version 2.1 of the GNU Lesser General Public License as published by 
6    *  the Free Software Foundation.
7    *
8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
10   *  See the GNU Lesser General Public License for more details at gnu.org.
11   */
12  
13  package com.eviware.soapui.impl.wsdl.submit.transports.http.support.attachments;
14  
15  import com.eviware.soapui.SoapUI;
16  
17  import javax.activation.DataSource;
18  import javax.mail.internet.MimeMultipart;
19  import java.io.*;
20  
21  /***
22   * DataSource for multipart attachments
23   * 
24   * @author ole.matzura
25   */
26  
27  public class MultipartAttachmentDataSource implements DataSource
28  {
29  	private final MimeMultipart multipart;
30  
31  	public MultipartAttachmentDataSource(MimeMultipart multipart)
32  	{
33  		this.multipart = multipart;
34  	}
35  
36  	public String getContentType()
37  	{
38  		return multipart.getContentType();
39  	}
40  
41  	public InputStream getInputStream() throws IOException
42  	{
43  		try
44  		{
45  			ByteArrayOutputStream out = new ByteArrayOutputStream();
46  			multipart.writeTo(out);
47  			return new ByteArrayInputStream( out.toByteArray() );
48  		}
49  		catch (Exception e)
50  		{
51  			SoapUI.logError( e );
52  			return null;
53  		}		
54  	}
55  
56  	public String getName()
57  	{
58  		return multipart.toString();
59  	}
60  
61  	public OutputStream getOutputStream() throws IOException
62  	{
63  		return null;
64  	}}