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.model.iface.Attachment;
16  
17  import javax.activation.DataSource;
18  import java.io.IOException;
19  import java.io.InputStream;
20  import java.io.OutputStream;
21  
22  /***
23   * Standard DataSource for existing attachments in soapUI
24   * 
25   * @author ole.matzura
26   */
27  
28  class AttachmentDataSource implements DataSource
29  {
30  	private final Attachment attachment;
31  
32  	public AttachmentDataSource(Attachment attachment)
33  	{
34  		this.attachment = attachment;
35  	}
36  
37  	public String getContentType()
38  	{
39  		return attachment.getContentType();
40  	}
41  
42  	public InputStream getInputStream() throws IOException
43  	{
44  		try
45  		{
46  			return attachment.getInputStream();
47  		}
48  		catch( Exception e )
49  		{
50  			throw new IOException( e.toString() );
51  		}
52  	}
53  
54  	public String getName()
55  	{
56  		return attachment.getName();
57  	}
58  
59  	public OutputStream getOutputStream() throws IOException
60  	{
61  		return null;
62  	}
63  }