You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by pm...@apache.org on 2016/12/21 19:16:23 UTC
svn commit: r1775544 -
/jmeter/trunk/src/protocol/ftp/org/apache/jmeter/protocol/ftp/sampler/FTPSampler.java
Author: pmouawad
Date: Wed Dec 21 19:16:23 2016
New Revision: 1775544
URL: http://svn.apache.org/viewvc?rev=1775544&view=rev
Log:
sonar : close target which can be a FileOutputStream
Modified:
jmeter/trunk/src/protocol/ftp/org/apache/jmeter/protocol/ftp/sampler/FTPSampler.java
Modified: jmeter/trunk/src/protocol/ftp/org/apache/jmeter/protocol/ftp/sampler/FTPSampler.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/ftp/org/apache/jmeter/protocol/ftp/sampler/FTPSampler.java?rev=1775544&r1=1775543&r2=1775544&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/ftp/org/apache/jmeter/protocol/ftp/sampler/FTPSampler.java (original)
+++ jmeter/trunk/src/protocol/ftp/org/apache/jmeter/protocol/ftp/sampler/FTPSampler.java Wed Dec 21 19:16:23 2016
@@ -220,37 +220,41 @@ public class FTPSampler extends Abstract
} else {
final boolean saveResponse = isSaveResponse();
ByteArrayOutputStream baos=null; // No need to close this
- OutputStream target=null; // No need to close this
- if (saveResponse){
- baos = new ByteArrayOutputStream();
- target=baos;
- }
- if (local.length()>0){
- output=new FileOutputStream(local);
- if (target==null) {
- target=output;
- } else {
- target = new TeeOutputStream(output,baos);
+ OutputStream target=null;
+ try {
+ if (saveResponse){
+ baos = new ByteArrayOutputStream();
+ target=baos;
}
- }
- if (target == null){
- target=new NullOutputStream();
- }
- input = ftp.retrieveFileStream(remote);
- if (input == null){// Could not access file or other error
- res.setResponseCode(Integer.toString(ftp.getReplyCode()));
- res.setResponseMessage(ftp.getReplyString());
- } else {
- long bytes = IOUtils.copy(input,target);
- ftpOK = bytes > 0;
- if (saveResponse && baos != null){
- res.setResponseData(baos.toByteArray());
- if (!binaryTransfer) {
- res.setDataType(SampleResult.TEXT);
+ if (local.length()>0){
+ output=new FileOutputStream(local);
+ if (target==null) {
+ target=output;
+ } else {
+ target = new TeeOutputStream(output,baos);
}
+ }
+ if (target == null){
+ target=new NullOutputStream();
+ }
+ input = ftp.retrieveFileStream(remote);
+ if (input == null){// Could not access file or other error
+ res.setResponseCode(Integer.toString(ftp.getReplyCode()));
+ res.setResponseMessage(ftp.getReplyString());
} else {
- res.setBytes(bytes);
+ long bytes = IOUtils.copy(input,target);
+ ftpOK = bytes > 0;
+ if (saveResponse && baos != null){
+ res.setResponseData(baos.toByteArray());
+ if (!binaryTransfer) {
+ res.setDataType(SampleResult.TEXT);
+ }
+ } else {
+ res.setBytes(bytes);
+ }
}
+ } finally {
+ IOUtils.closeQuietly(target);
}
}