cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anto...@apache.org
Subject svn commit: r366703 - in /cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/bean: CocoonBean.java helpers/BeanConfigurator.java
Date Sat, 07 Jan 2006 11:12:32 GMT
Author: antonio
Date: Sat Jan  7 03:12:29 2006
New Revision: 366703

URL: http://svn.apache.org/viewcvs?rev=366703&view=rev
Log:
Close streams.

Modified:
    cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/bean/CocoonBean.java
    cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/bean/helpers/BeanConfigurator.java

Modified: cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/bean/CocoonBean.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/bean/CocoonBean.java?rev=366703&r1=366702&r2=366703&view=diff
==============================================================================
--- cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/bean/CocoonBean.java (original)
+++ cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/bean/CocoonBean.java Sat Jan
 7 03:12:29 2006
@@ -33,6 +33,7 @@
 import org.apache.excalibur.source.SourceUtil;
 
 import java.io.BufferedReader;
+import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.IOException;
 import java.io.OutputStream;
@@ -593,14 +594,15 @@
             n.addExtraDescription("missing-file", target.getSourceURI());
 
             ModifiableSource source = getSource(target);
+            OutputStream stream = null;
+            PrintStream out = null;
             try {
-                OutputStream stream = source.getOutputStream();
-
-                PrintStream out = new PrintStream(stream);
+                stream = source.getOutputStream();
+                out = new PrintStream(stream);
                 Notifier.notify(n, out, "text/html");
-                out.flush();
-                out.close();
             } finally {
+                if (out != null) out.close();
+                if (stream != null) stream.close();
                 releaseSource(source);
             }
         }
@@ -670,30 +672,38 @@
      */ 
     private void readChecksumFile() throws Exception {
         checksums = new HashMap();
-        
+        InputStream is = null;
+        InputStreamReader isr = null;
+        BufferedReader reader = null;
         try {
             Source checksumSource = sourceResolver.resolveURI(checksumsURI);
-            BufferedReader reader = new BufferedReader(new InputStreamReader(checksumSource.getInputStream()));
+            is = checksumSource.getInputStream();
+            isr = new InputStreamReader(is);
+            reader = new BufferedReader(isr);
             String line;
-            int lineNo=0;
-            while ((line = reader.readLine())!=null) {
+            int lineNo = 0;
+            while ((line = reader.readLine()) != null) {
                 lineNo++;
-                if (line.trim().startsWith("#") || line.trim().length()==0 ) {
+                if (line.trim().startsWith("#") || line.trim().length() == 0) {
                     continue;
                 }
-                if (line.indexOf("\t")==-1) { 
-                    throw new ProcessingException("Missing tab at line "+lineNo+" of " +
checksumsURI);
+                if (line.indexOf("\t") == -1) { 
+                    throw new ProcessingException("Missing tab at line " + lineNo + " of
" + checksumsURI);
                 }
-                String filename = line.substring(0,line.indexOf("\t"));
-                String checksum = line.substring(line.indexOf("\t")+1);
+                String filename = line.substring(0, line.indexOf("\t"));
+                String checksum = line.substring(line.indexOf("\t") + 1);
                 checksums.put(filename, checksum);
             }
             reader.close();
         } catch (SourceNotFoundException e) {
             // return leaving checksums map empty
+        } finally {
+            if (reader != null) reader.close();
+            if (isr != null) isr.close();
+            if (is != null) is.close();
         }
     }
-    
+
     private void writeChecksumFile() throws Exception {
         Source checksumSource = sourceResolver.resolveURI(checksumsURI);
         if (!(checksumSource instanceof ModifiableSource)) {

Modified: cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/bean/helpers/BeanConfigurator.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/bean/helpers/BeanConfigurator.java?rev=366703&r1=366702&r2=366703&view=diff
==============================================================================
--- cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/bean/helpers/BeanConfigurator.java
(original)
+++ cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/bean/helpers/BeanConfigurator.java
Sat Jan  7 03:12:29 2006
@@ -16,12 +16,15 @@
 package org.apache.cocoon.bean.helpers;
 
 import java.io.BufferedReader;
+import java.io.FileNotFoundException;
 import java.io.FileReader;
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.cocoon.bean.CocoonBean;
 import org.apache.cocoon.bean.helpers.OutputStreamListener;
+import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang.BooleanUtils;
 
 import org.w3c.dom.Document;
@@ -366,9 +369,9 @@
                 dest = getAttributeValue(node, ATTR_URI_DESTURI);
             }
 
-            if (root != null && type != null & dest != null) {
+            if (root != null && type != null && dest != null) {
                 cocoon.addTarget(type, root, src, dest);
-            } else if (root != null & dest != null) {
+            } else if (root != null && dest != null) {
                 cocoon.addTarget(root, src, dest);
             } else if (dest != null) {
                 cocoon.addTarget(src, dest);
@@ -457,27 +460,26 @@
      */
     public static List processURIFile(String filename) {
         List uris = new ArrayList();
+        FileReader fr = null;
+        BufferedReader uriFile = null;
         try {
-            BufferedReader uriFile = new BufferedReader(new FileReader(filename));
-
-            while (true) {
-                String uri = uriFile.readLine();
-
-                if (null == uri) {
-                    break;
-                }
-                
+            fr = new FileReader(filename);
+            uriFile = new BufferedReader(fr);
+            String uri;
+            while ((uri = uriFile.readLine()) != null) {
                 uri = uri.trim();
-                if (!uri.equals("") && !uri.startsWith("#")){
+                if (!uri.equals("") && !uri.startsWith("#")) {
                     uris.add(uri.trim());
                 }
             }
-
-            uriFile.close();
-        } catch (Exception e) {
-            // ignore errors.
+        } catch (FileNotFoundException e) {
+            // nothing to do
+        } catch (IOException e) {
+            // nothing to do
+        } finally {
+            IOUtils.closeQuietly(uriFile);
+            IOUtils.closeQuietly(fr);
         }
         return uris;
     }
-
 }



Mime
View raw message