jmeter-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sebb <seb...@gmail.com>
Subject Re: svn commit: r1205606 - /jmeter/trunk/src/core/org/apache/jmeter/services/FileServer.java
Date Wed, 23 Nov 2011 22:43:08 GMT
On 23 November 2011 21:24,  <pmouawad@apache.org> wrote:
> Author: pmouawad
> Date: Wed Nov 23 21:24:09 2011
> New Revision: 1205606
>
> URL: http://svn.apache.org/viewvc?rev=1205606&view=rev
> Log:
> Simplify / Clarify code by using Closeable interface
>
> Modified:
>    jmeter/trunk/src/core/org/apache/jmeter/services/FileServer.java
>
> Modified: jmeter/trunk/src/core/org/apache/jmeter/services/FileServer.java
> URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/services/FileServer.java?rev=1205606&r1=1205605&r2=1205606&view=diff
> ==============================================================================
> --- jmeter/trunk/src/core/org/apache/jmeter/services/FileServer.java (original)
> +++ jmeter/trunk/src/core/org/apache/jmeter/services/FileServer.java Wed Nov 23 21:24:09
2011
> @@ -23,6 +23,7 @@ package org.apache.jmeter.services;
>
>  import java.io.BufferedReader;
>  import java.io.BufferedWriter;
> +import java.io.Closeable;
>  import java.io.File;
>  import java.io.FileInputStream;
>  import java.io.FileOutputStream;
> @@ -39,6 +40,7 @@ import org.apache.commons.collections.Ar
>  import org.apache.jmeter.gui.JMeterFileFilter;
>  import org.apache.jmeter.util.JMeterUtils;
>  import org.apache.jorphan.logging.LoggingManager;
> +import org.apache.jorphan.util.JOrphanUtils;
>  import org.apache.log.Logger;
>
>  /**
> @@ -393,13 +395,7 @@ public class FileServer {
>     private void closeFile(String name, FileEntry fileEntry) throws IOException {
>         if (fileEntry != null && fileEntry.inputOutputObject != null) {
>             log.info("Close: "+name);
> -            if (fileEntry.inputOutputObject instanceof Reader) {
> -                ((Reader) fileEntry.inputOutputObject).close();
> -            } else if (fileEntry.inputOutputObject instanceof Writer) {
> -                ((Writer) fileEntry.inputOutputObject).close();
> -            } else {
> -                log.error("Unknown inputOutputObject type : " + fileEntry.inputOutputObject.getClass());
> -            }
> +            JOrphanUtils.closeQuietly(fileEntry.inputOutputObject);

This changes the behaviour, in that the code no longer throws IOException.

I'm not convinced that is the correct thing to do, especially for a Writer.

Could still simplify the code by using

      fileEntry.inputOutputObject.close()

instead of closeQuietly.

We can then catch the IOE later if necessary and take appropriate
action, e.g. log it.

>             fileEntry.inputOutputObject = null;
>         }
>     }
> @@ -437,9 +433,9 @@ public class FileServer {
>     private static class FileEntry{
>         private String headerLine;
>         private final File file;
> -        private Object inputOutputObject; // Reader/Writer
> +        private Closeable inputOutputObject;
>         private final String charSetEncoding;
> -        FileEntry(File f, Object o, String e){
> +        FileEntry(File f, Closeable o, String e){
>             file=f;
>             inputOutputObject=o;
>             charSetEncoding=e;
>
>
>

Mime
View raw message