jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fschumac...@apache.org
Subject svn commit: r1783521 - /jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/mail/sampler/MailFileFolder.java
Date Sat, 18 Feb 2017 11:36:53 GMT
Author: fschumacher
Date: Sat Feb 18 11:36:53 2017
New Revision: 1783521

URL: http://svn.apache.org/viewvc?rev=1783521&view=rev
Log:
Use try-with statement to close all streams.

Modified:
    jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/mail/sampler/MailFileFolder.java

Modified: jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/mail/sampler/MailFileFolder.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/mail/sampler/MailFileFolder.java?rev=1783521&r1=1783520&r2=1783521&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/mail/sampler/MailFileFolder.java
(original)
+++ jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/mail/sampler/MailFileFolder.java
Sat Feb 18 11:36:53 2017
@@ -23,6 +23,7 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.FilenameFilter;
+import java.io.IOException;
 import java.io.InputStream;
 
 import javax.mail.Flags;
@@ -108,16 +109,12 @@ public class MailFileFolder extends Fold
         } else {
             f = new File(folderPath,String.format(FILENAME_FORMAT, Integer.valueOf(index)));
         }
-        try {
-            InputStream fis = new BufferedInputStream(new FileInputStream(f));
-            try {
-                Message m = new MailFileMessage(this, fis, index);
-                return m;
-            } finally {
-                IOUtils.closeQuietly(fis);
-            }
-        } catch (FileNotFoundException e) {
-            throw new MessagingException("Cannot open folder: "+e.getMessage(), e);
+        try (InputStream fis = new FileInputStream(f);
+                InputStream bis = new BufferedInputStream(fis)) {
+            return new MailFileMessage(this, bis, index);
+        } catch (IOException e) {
+            throw new MessagingException(
+                    "Cannot open folder: " + e.getMessage(), e);
         }
     }
 



Mime
View raw message