Hi David,
This sounds like normal behaviour though it seems wierd at first.

The reason you need to be able to recreate the input stream is because HttpClient sometimes needs to recreate and resend the entire request. The most common cause for this is when the server requires authentication, but there are a number of reasons.

If you want to avoid creating the input stream twice your only option is to buffer the content somewhere (memory or disk) and that may or may not prove to be just as slow.

Regards,

Adrian Sutton.

On Friday, July 18, 2003, at 06:22 AM, David Sean Taylor wrote:

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#createInputS tream()
*/
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 [EMAIL PROTECTED] +01 707 773-4646

----------------------------------------------
Intencha "tomorrow's technology today"
Ph: 38478913 0422236329
Suite 8/29 Oatland Crescent
Holland Park West 4121
Australia QLD
www.intencha.com


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to