hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Sean Taylor <da...@bluesunrise.com>
Subject InputStream part source
Date Thu, 17 Jul 2003 20:22:54 GMT
I created a little class called InputStreamPartSource to wrapper an  
input stream as a part source.

MultipartPostMethod post  = new  
MultipartPostMethod("http://192.168.1.4:8080/someServlet");
InputStreamPartSource source = new InputStreamPartSource(stream,  
"business.xml");
FilePart part = new FilePart("business.xml", source);
post.addPart(part);
int status = client.executeMethod(post);

It seems that the abstract class Part is calling createInputStream  
twice on my source.
Why does it need to create the stream twice?
This causes a bad file descriptor since the stream was already closed  
after the first call.
The stream is an expensive resource which comes from a CMS system and I  
prefer not to create it twice.
Is this a bug are normal/required behavior?

InputStreamPartSource Class included below

public class InputStreamPartSource implements PartSource
{
	InputStream stream = null;
	String filename = null;
	int length = 0;
	
	public InputStreamPartSource(InputStream stream, String filename, int  
length)
	{
		this.stream = stream;
		this.filename = filename;
		this.length = length;
	}
     /* (non-Javadoc)
      * @see  
org.apache.commons.httpclient.methods.multipart.PartSource#createInputSt 
ream()
      */
     public InputStream createInputStream()
     throws IOException
     {
     	return this.stream;
     }

     /* (non-Javadoc)
      * @see  
org.apache.commons.httpclient.methods.multipart.PartSource#getFileName()
      */
     public String getFileName()
     {
         return this.filename;
     }

     /* (non-Javadoc)
      * @see  
org.apache.commons.httpclient.methods.multipart.PartSource#getLength()
      */
     public long getLength()
     {
         return this.length;
     }


--
David Sean Taylor
Bluesunrise Software
david@bluesunrise.com
+01 707 773-4646




Mime
View raw message