1
2
3
4
5
6
7
8
9
10
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 }}