You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jmeter-dev@jakarta.apache.org by se...@apache.org on 2006/12/06 01:51:15 UTC

svn commit: r482854 - /jakarta/jmeter/branches/rel-2-2/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java

Author: sebb
Date: Tue Dec  5 16:51:14 2006
New Revision: 482854

URL: http://svn.apache.org/viewvc?view=rev&rev=482854
Log:
Bug 41100 - PUT files not being closed

Modified:
    jakarta/jmeter/branches/rel-2-2/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java

Modified: jakarta/jmeter/branches/rel-2-2/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/branches/rel-2-2/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java?view=diff&rev=482854&r1=482853&r2=482854
==============================================================================
--- jakarta/jmeter/branches/rel-2-2/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java (original)
+++ jakarta/jmeter/branches/rel-2-2/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java Tue Dec  5 16:51:14 2006
@@ -20,6 +20,7 @@
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
 import java.net.InetAddress;
 import java.net.URL;
 import java.net.UnknownHostException;
@@ -664,11 +665,51 @@
          String filename = getFilename();
          if ((filename != null) && (filename.trim().length() > 0))
          {
-             RequestEntity requestEntity = new InputStreamRequestEntity(
-                     new FileInputStream(filename),getMimetype());
+             RequestEntity requestEntity = 
+            	 new FileRequestEntity(new File(filename),getMimetype());
              put.setRequestEntity(requestEntity);
          }
      }
+
+	// Implement locally, as current implementation (3.1Beta) does not close file...
+	private class FileRequestEntity implements RequestEntity {
+
+	    final File file;
+	    final String contentType;
+	    
+	    public FileRequestEntity(final File file, final String contentType) {
+	        super();
+	        if (file == null) {
+	            throw new IllegalArgumentException("File may not be null");
+	        }
+	        this.file = file;
+	        this.contentType = contentType;
+	    }
+	    public long getContentLength() {
+	        return this.file.length();
+	    }
+
+	    public String getContentType() {
+	        return this.contentType;
+	    }
+
+	    public boolean isRepeatable() {
+	        return true;
+	    }
+
+	    public void writeRequest(OutputStream out) throws IOException {
+	        InputStream in = new FileInputStream(this.file);
+	        try {
+	            int l;
+	            byte[] buffer = new byte[1024];
+	            while ((l = in.read(buffer)) != -1) {
+	                out.write(buffer, 0, l);
+	            }
+	        } finally {
+	            in.close();
+	        }
+	    }
+	}
 
     /**
 	 * From the <code>HttpMethod</code>, store all the "set-cookie" key-pair



---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org