Return-Path: Mailing-List: contact commons-httpclient-dev-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list commons-httpclient-dev@jakarta.apache.org Received: (qmail 40923 invoked from network); 17 Jul 2003 20:23:25 -0000 Received: from h-64-105-95-98.snvacaid.covad.net (HELO bluesunrise.com) (64.105.95.98) by daedalus.apache.org with SMTP; 17 Jul 2003 20:23:25 -0000 Received: from bluesunrise.com [192.168.1.3] by bluesunrise.com [127.0.0.1] with SMTP (MDaemon.PRO.v5.0.1.R) for ; Thu, 17 Jul 2003 13:17:59 -0700 Date: Thu, 17 Jul 2003 13:22:54 -0700 Mime-Version: 1.0 (Apple Message framework v552) Content-Type: text/plain; delsp=yes; charset=US-ASCII; format=flowed Subject: InputStream part source From: David Sean Taylor To: commons-httpclient-dev@jakarta.apache.org Content-Transfer-Encoding: 7bit Message-Id: <723E8170-B894-11D7-8C98-000393C78E78@bluesunrise.com> X-Mailer: Apple Mail (2.552) X-MDRemoteIP: 192.168.1.3 X-Return-Path: david@bluesunrise.com X-MDaemon-Deliver-To: commons-httpclient-dev@jakarta.apache.org X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N 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