jstrachan    2002/11/25 06:29:07

  Modified:    jelly/src/java/org/apache/commons/jelly/tags/util
                        LoadTextTag.java
  Log:
  patched bug which incorrectly kept open the Reader that is used to load text from a 
file
  
  Revision  Changes    Path
  1.4       +28 -12    
jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/util/LoadTextTag.java
  
  Index: LoadTextTag.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/util/LoadTextTag.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- LoadTextTag.java  30 Oct 2002 19:16:20 -0000      1.3
  +++ LoadTextTag.java  25 Nov 2002 14:29:07 -0000      1.4
  @@ -73,6 +73,9 @@
   import org.apache.commons.jelly.TagSupport;
   import org.apache.commons.jelly.XMLOutput;
   
  +import org.apache.commons.logging.Log;
  +import org.apache.commons.logging.LogFactory;
  +
   /** 
    * A tag which loads text from a file or URI into a Jelly variable. 
    *
  @@ -81,6 +84,9 @@
    */
   public class LoadTextTag extends TagSupport {
   
  +    /** The Log to which logging calls will be made. */
  +    private static final Log log = LogFactory.getLog(LoadTextTag.class);
  +
       private String var;
       private File file;
       private String uri;
  @@ -177,17 +183,27 @@
           StringBuffer buffer = new StringBuffer();
           
           // @todo its probably more efficient to use a fixed char[] buffer instead
  -        BufferedReader bufferedReader = new BufferedReader(reader);
  -        while (true) {
  -            String line = bufferedReader.readLine();
  -            if (line == null) {
  -                break;
  -            }
  -            else {
  -                buffer.append(line);
  -                buffer.append('\n');
  -            }
  -        }
  -        return buffer.toString();
  +             try {        
  +             BufferedReader bufferedReader = new BufferedReader(reader);
  +             while (true) {
  +                 String line = bufferedReader.readLine();
  +                 if (line == null) {
  +                     break;
  +                 }
  +                 else {
  +                     buffer.append(line);
  +                     buffer.append('\n');
  +                 }
  +             }
  +             return buffer.toString();
  +             }
  +             finally {
  +                     try {
  +                             reader.close();
  +                     }
  +                     catch (Exception e) {
  +                             log.error( "Caught exception closing Reader: " + e, e);
  +                     }
  +             }
       }
   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to