View Javadoc

1   /*
2    *  soapUI, copyright (C) 2006 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of the GNU Lesser General Public License as published by the Free Software Foundation; 
6    *  either version 2.1 of the License, or (at your option) any later version.
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;
14  
15  import java.io.ByteArrayInputStream;
16  import java.io.ByteArrayOutputStream;
17  import java.io.IOException;
18  import java.io.InputStream;
19  import java.io.OutputStream;
20  
21  import javax.activation.DataSource;
22  import javax.mail.internet.MimeMultipart;
23  
24  class MultipartAttachmentDataSource implements DataSource
25  {
26  	private final MimeMultipart multipart;
27  
28  	public MultipartAttachmentDataSource(MimeMultipart multipart)
29  	{
30  		this.multipart = multipart;
31  	}
32  
33  	public String getContentType()
34  	{
35  		return multipart.getContentType();
36  	}
37  
38  	public InputStream getInputStream() throws IOException
39  	{
40  		try
41  		{
42  			ByteArrayOutputStream out = new ByteArrayOutputStream();
43  			multipart.writeTo(out);
44  			return new ByteArrayInputStream( out.toByteArray() );
45  		}
46  		catch (Exception e)
47  		{
48  			e.printStackTrace();
49  			return null;
50  		}		
51  	}
52  
53  	public String getName()
54  	{
55  		return multipart.toString();
56  	}
57  
58  	public OutputStream getOutputStream() throws IOException
59  	{
60  		return null;
61  	}}