Index: src/java/org/apache/commons/httpclient/methods/multipart/FilePart.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/multipart/FilePart.java,v retrieving revision 1.3 diff -u -r1.3 FilePart.java --- src/java/org/apache/commons/httpclient/methods/multipart/FilePart.java 29 Oct 2002 06:40:15 -0000 1.3 +++ src/java/org/apache/commons/httpclient/methods/multipart/FilePart.java 30 Oct 2002 23:13:11 -0000 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/multipart/FilePart.java,v 1.3 2002/10/29 06:40:15 jsdever Exp $ - * $Revision: 1.3 $ - * $Date: 2002/10/29 06:40:15 $ + * $Header: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/multipart/FilePart.java,v 1.2 2002/10/11 05:16:32 sullis Exp $ + * $Revision: 1.2 $ + * $Date: 2002/10/11 05:16:32 $ * ==================================================================== * * The Apache Software License, Version 1.1 @@ -70,6 +70,8 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.security.InvalidParameterException; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; /** @@ -90,6 +92,9 @@ */ public class FilePart extends Part { + /** Log object for this class. */ + private static final Log log = LogFactory.getLog(FilePart.class); + //TODO: make this configurable static int MAX_BUFF_SIZE = 1 * 1024 * 1024; // 1 MiBs @@ -164,13 +169,16 @@ // We need to cast fileLength to an int to call mark(int) on the // input stream, so we must ensure that the file length will fit // into an int before trying to use mark and reset. - this.markSupported = fileInputStream.markSupported() && - fileLength <= Integer.MAX_VALUE; - this.bufferData = !markSupported; + if (fileInputStream != null) { + this.markSupported = fileInputStream.markSupported() && + fileLength <= Integer.MAX_VALUE; + this.bufferData = !markSupported; + } } protected void sendHeader(OutputStream out) throws IOException { + log.trace("enter sendHeader(OutputStream out)"); super.sendHeader(out); sendFilename(out); sendContentType(out); @@ -178,6 +186,7 @@ protected void sendFilename(OutputStream out) throws IOException { + log.trace("enter sendFilename(OutputStream out)"); String filename = "; filename=\"" + fileName + "\""; out.write(filename.getBytes()); } @@ -185,6 +194,7 @@ protected void sendContentType(OutputStream out) throws IOException { + log.trace("enter sendContentType(OutputStream out)"); out.write(CRLF_bytes); out.write("Content-Type: application/octet-stream".getBytes()); } @@ -195,6 +205,7 @@ protected void sendData(OutputStream out) throws IOException { + log.trace("enter sendData(OutputStream out)"); byte[] buff; @@ -203,6 +214,7 @@ // this file contains no data, so there is nothing to send. // we don't want to create a zero length buffer as this will // cause an infinite loop when reading. + log.debug("No data to send."); return; } else if (lengthOfData() > MAX_BUFF_SIZE) { @@ -217,6 +229,7 @@ } if (file != null) { is = new FileInputStream(file); + dataBuf = null; } if (dataBuf != null) { // Send the buffered data from a previous send. @@ -240,6 +253,9 @@ fileStream.reset(); } } + if (file != null) { + is.close(); + } } protected long lengthOfData() @@ -258,6 +274,7 @@ * @see #getBufferData() */ public void setBufferData(boolean bufferData) { + log.trace("enter setBufferData(boolean bufferData)"); this.bufferData = bufferData; } Index: src/java/org/apache/commons/httpclient/methods/multipart/Part.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/multipart/Part.java,v retrieving revision 1.2 diff -u -r1.2 Part.java --- src/java/org/apache/commons/httpclient/methods/multipart/Part.java 13 Oct 2002 18:57:10 -0000 1.2 +++ src/java/org/apache/commons/httpclient/methods/multipart/Part.java 30 Oct 2002 23:13:12 -0000 @@ -65,17 +65,23 @@ import java.io.OutputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; /** * Abstract class for one Part of a multipart post object. * * @author Matthew Albright * @author Jeff Dever + * @author Adrian Sutton * * @since 2.0 */ public abstract class Part { + /** Log object for this class. */ + private static final Log log = LogFactory.getLog(Part.class); + static String boundary = "----------------314159265358979323846"; static byte[] boundary_bytes = boundary.getBytes(); static String CRLF = "\r\n"; @@ -89,6 +95,7 @@ public static void sendLastBoundary(OutputStream out) throws IOException { + log.trace("enter sendLastBoundary(OutputStream out)"); out.write(extra_bytes); out.write(boundary_bytes); out.write(extra_bytes); @@ -97,6 +104,7 @@ public static int lengthOfLastBoundary() throws IOException { + log.trace("enter lengthOfLastBoundary()"); ByteArrayOutputStream out = new ByteArrayOutputStream(); sendLastBoundary(out); @@ -108,6 +116,7 @@ protected void sendStart(OutputStream out) throws IOException { + log.trace("enter sendStart(OutputStream out)"); out.write(extra_bytes); out.write(boundary_bytes); out.write(CRLF_bytes); @@ -115,6 +124,7 @@ protected int lengthOfStart() throws IOException { + log.trace("enter lengthOfStart()"); ByteArrayOutputStream out = new ByteArrayOutputStream(); sendStart(out); return(out.size()); @@ -122,6 +132,7 @@ protected void sendHeader(OutputStream out) throws IOException { + log.trace("enter sendHeader(OutputStream out)"); String content_dispos = "Content-Disposition: form-data; name=\"" + getName() + "\""; @@ -130,6 +141,7 @@ protected int lengthOfHeader() throws IOException { + log.trace("enter lengthOfHeader()"); ByteArrayOutputStream out = new ByteArrayOutputStream(); sendHeader(out); return(out.size()); @@ -138,12 +150,14 @@ protected void sendEndOfHeader(OutputStream out) throws IOException { + log.trace("enter sendEndOfHeader(OutputStream out)"); out.write(CRLF_bytes); out.write(CRLF_bytes); } protected int lengthOfEndOfHeader() throws IOException { + log.trace("enter lengthOfEndOfHeader()"); ByteArrayOutputStream out = new ByteArrayOutputStream(); sendEndOfHeader(out); return out.size(); @@ -156,11 +170,13 @@ protected void sendEnd(OutputStream out) throws IOException { + log.trace("enter sendEnd(OutputStream out)"); out.write(CRLF_bytes); } protected int lengthOfEnd() throws IOException { + log.trace("enter lengthOfEnd()"); ByteArrayOutputStream out = new ByteArrayOutputStream(); sendEnd(out); return out.size(); @@ -172,6 +188,7 @@ */ final public void send(OutputStream out) throws IOException { + log.trace("enter send(OutputStream out)"); sendStart(out); sendHeader(out); sendEndOfHeader(out); @@ -180,6 +197,7 @@ } final public long length() throws IOException { + log.trace("enter length()"); return lengthOfStart() + lengthOfHeader() + lengthOfEndOfHeader() +