tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From violet...@apache.org
Subject svn commit: r1720598 - in /tomcat/tc7.0.x/trunk/java/org/apache/jasper: JspC.java compiler/SmapUtil.java
Date Thu, 17 Dec 2015 15:11:43 GMT
Author: violetagg
Date: Thu Dec 17 15:11:43 2015
New Revision: 1720598

URL: http://svn.apache.org/viewvc?rev=1720598&view=rev
Log:
Close streams.
This is not needed for later versions as there these issues are fixed.

Modified:
    tomcat/tc7.0.x/trunk/java/org/apache/jasper/JspC.java
    tomcat/tc7.0.x/trunk/java/org/apache/jasper/compiler/SmapUtil.java

Modified: tomcat/tc7.0.x/trunk/java/org/apache/jasper/JspC.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/jasper/JspC.java?rev=1720598&r1=1720597&r2=1720598&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/jasper/JspC.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/jasper/JspC.java Thu Dec 17 15:11:43 2015
@@ -1060,79 +1060,110 @@ public class JspC extends Task implement
         String insertEndMarker =
             Localizer.getMessage("jspc.webinc.insertEnd");
 
-        BufferedReader reader = new BufferedReader(openWebxmlReader(webXml));
-        BufferedReader fragmentReader = new BufferedReader(
-                openWebxmlReader(new File(webxmlFile)));
-        PrintWriter writer = new PrintWriter(openWebxmlWriter(webXml2));
-
-        // Insert the <servlet> and <servlet-mapping> declarations
-        boolean inserted = false;
-        int current = reader.read();
-        while (current > -1) {
-            if (current == '<') {
-                String element = getElement(reader);
-                if (!inserted && insertBefore.contains(element)) {
-                    // Insert generated content here
-                    writer.println(insertStartMarker);
-                    while (true) {
-                        String line = fragmentReader.readLine();
-                        if (line == null) {
-                            writer.println();
-                            break;
-                        }
-                        writer.println(line);
-                    }
-                    writer.println(insertEndMarker);
-                    writer.println();
-                    writer.write(element);
-                    inserted = true;
-                } else if (element.equals(insertStartMarker)) {
-                    // Skip the previous auto-generated content
-                    while (true) {
-                        current = reader.read();
-                        if (current < 0) {
-                            throw new EOFException();
-                        }
-                        if (current == '<') {
-                            element = getElement(reader);
-                            if (element.equals(insertEndMarker)) {
+        BufferedReader reader = null;
+        BufferedReader fragmentReader = null;
+        PrintWriter writer = null;
+        try {
+            reader = new BufferedReader(openWebxmlReader(webXml));
+            fragmentReader = new BufferedReader(openWebxmlReader(new File(webxmlFile)));
+            writer = new PrintWriter(openWebxmlWriter(webXml2));
+            // Insert the <servlet> and <servlet-mapping> declarations
+            boolean inserted = false;
+            int current = reader.read();
+            while (current > -1) {
+                if (current == '<') {
+                    String element = getElement(reader);
+                    if (!inserted && insertBefore.contains(element)) {
+                        // Insert generated content here
+                        writer.println(insertStartMarker);
+                        while (true) {
+                            String line = fragmentReader.readLine();
+                            if (line == null) {
+                                writer.println();
                                 break;
                             }
+                            writer.println(line);
+                        }
+                        writer.println(insertEndMarker);
+                        writer.println();
+                        writer.write(element);
+                        inserted = true;
+                    } else if (element.equals(insertStartMarker)) {
+                        // Skip the previous auto-generated content
+                        while (true) {
+                            current = reader.read();
+                            if (current < 0) {
+                                throw new EOFException();
+                            }
+                            if (current == '<') {
+                                element = getElement(reader);
+                                if (element.equals(insertEndMarker)) {
+                                    break;
+                                }
+                            }
                         }
-                    }
-                    current = reader.read();
-                    while (current == '\n' || current == '\r') {
                         current = reader.read();
+                        while (current == '\n' || current == '\r') {
+                            current = reader.read();
+                        }
+                        continue;
+                    } else {
+                        writer.write(element);
                     }
-                    continue;
                 } else {
-                    writer.write(element);
+                    writer.write(current);
+                }
+                current = reader.read();
+            }
+        } finally {
+            if (writer != null) {
+                try {
+                    writer.close();
+                } catch (Exception e) {
+                }
+            }
+            if (reader != null) {
+                try {
+                    reader.close();
+                } catch (Exception e) {
+                }
+            }
+            if (fragmentReader != null) {
+                try {
+                    fragmentReader.close();
+                } catch (Exception e) {
                 }
-            } else {
-                writer.write(current);
             }
-            current = reader.read();
         }
-        writer.close();
-
-        reader.close();
-        fragmentReader.close();
-
-        FileInputStream fis = new FileInputStream(webXml2);
-        FileOutputStream fos = new FileOutputStream(webXml);
 
-        byte buf[] = new byte[512];
-        while (true) {
-            int n = fis.read(buf);
-            if (n < 0) {
-                break;
+        FileInputStream fis = null;
+        FileOutputStream fos = null;
+        try {
+            fis = new FileInputStream(webXml2);
+            fos = new FileOutputStream(webXml);
+            byte buf[] = new byte[512];
+            while (true) {
+                int n = fis.read(buf);
+                if (n < 0) {
+                    break;
+                }
+                fos.write(buf, 0, n);
+            }
+        } finally {
+            if (fis != null) {
+                try {
+                    fis.close();
+                } catch (Exception e) {
+                }
+            }
+            if (fos != null) {
+                try {
+                    fos.close();
+                } catch (Exception e) {
+                }
             }
-            fos.write(buf, 0, n);
         }
 
-        fis.close();
-        fos.close();
-
         if(!webXml2.delete() && log.isDebugEnabled())
             log.debug(Localizer.getMessage("jspc.delete.fail",
                     webXml2.toString()));

Modified: tomcat/tc7.0.x/trunk/java/org/apache/jasper/compiler/SmapUtil.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/jasper/compiler/SmapUtil.java?rev=1720598&r1=1720597&r2=1720598&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/jasper/compiler/SmapUtil.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/jasper/compiler/SmapUtil.java Thu Dec 17 15:11:43
2015
@@ -226,19 +226,31 @@ public class SmapUtil {
                 outStream.write(gen, 0, genPos);
             } finally {
                 if (outStream != null) {
-                    outStream.close();
+                    try {
+                        outStream.close();
+                    } catch (Exception e) {
+                    }
                 }
             }
         }
 
         static byte[] readWhole(File input) throws IOException {
-            FileInputStream inStream = new FileInputStream(input);
             int len = (int)input.length();
             byte[] bytes = new byte[len];
-            if (inStream.read(bytes, 0, len) != len) {
-                throw new IOException("expected size: " + len);
+            FileInputStream inStream = null;
+            try {
+                inStream = new FileInputStream(input);
+                if (inStream.read(bytes, 0, len) != len) {
+                    throw new IOException("expected size: " + len);
+                }
+            } finally {
+                if (inStream != null) {
+                    try {
+                        inStream.close();
+                    } catch (Exception e) {
+                    }
+                }
             }
-            inStream.close();
             return bytes;
         }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message