1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.submit.transports.http.support.attachments;
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 import com.eviware.soapui.SoapUI;
25
26 /***
27 * DataSource for multipart attachments
28 *
29 * @author ole.matzura
30 */
31
32 public class MultipartAttachmentDataSource implements DataSource
33 {
34 private final MimeMultipart multipart;
35
36 public MultipartAttachmentDataSource( MimeMultipart multipart )
37 {
38 this.multipart = multipart;
39 }
40
41 public String getContentType()
42 {
43 return multipart.getContentType();
44 }
45
46 public InputStream getInputStream() throws IOException
47 {
48 try
49 {
50 ByteArrayOutputStream out = new ByteArrayOutputStream();
51 multipart.writeTo( out );
52 return new ByteArrayInputStream( out.toByteArray() );
53 }
54 catch( Exception e )
55 {
56 SoapUI.logError( e );
57 return null;
58 }
59 }
60
61 public String getName()
62 {
63 return multipart.toString();
64 }
65
66 public OutputStream getOutputStream() throws IOException
67 {
68 return null;
69 }
70 }