poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cen...@apache.org
Subject svn commit: r1753123 - /poi/trunk/src/java/org/apache/poi/hssf/dev/FormulaViewer.java
Date Sun, 17 Jul 2016 21:18:12 GMT
Author: centic
Date: Sun Jul 17 21:18:12 2016
New Revision: 1753123

URL: http://svn.apache.org/viewvc?rev=1753123&view=rev
Log:
Fix one more place where stream were left open when an exception is thrown

Modified:
    poi/trunk/src/java/org/apache/poi/hssf/dev/FormulaViewer.java

Modified: poi/trunk/src/java/org/apache/poi/hssf/dev/FormulaViewer.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/dev/FormulaViewer.java?rev=1753123&r1=1753122&r2=1753123&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/dev/FormulaViewer.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/dev/FormulaViewer.java Sun Jul 17 21:18:12 2016
@@ -57,24 +57,26 @@ public class FormulaViewer
      */
     public void run() throws IOException {
         NPOIFSFileSystem fs  = new NPOIFSFileSystem(new File(file), true);
-        InputStream is = BiffViewer.getPOIFSInputStream(fs);
-        List<Record> records = RecordFactory.createRecords(is);
+        try {
+            InputStream is = BiffViewer.getPOIFSInputStream(fs);
+            try {
+                List<Record> records = RecordFactory.createRecords(is);
 
-        for (int k = 0; k < records.size(); k++)
-        {
-            Record record = records.get(k);
-
-            if (record.getSid() == FormulaRecord.sid)
-            {
-               if (list) {
-                    listFormula((FormulaRecord) record);
-               }else {
-                    parseFormulaRecord(( FormulaRecord ) record);
-               }
+                for (Record record : records) {
+                    if (record.getSid() == FormulaRecord.sid) {
+                        if (list) {
+                            listFormula((FormulaRecord) record);
+                        } else {
+                            parseFormulaRecord((FormulaRecord) record);
+                        }
+                    }
+                }
+            } finally {
+                is.close();
             }
+        } finally {
+            fs.close();
         }
-        is.close();
-        fs.close();
     }
     
     private void listFormula(FormulaRecord record) {
@@ -90,7 +92,7 @@ public class FormulaViewer
             	numArg = String.valueOf(-1);
             }
             
-            StringBuffer buf = new StringBuffer();
+            StringBuilder buf = new StringBuilder();
             
             if (token instanceof ExpPtg) return;
             buf.append(token.toFormulaString());
@@ -154,7 +156,7 @@ public class FormulaViewer
 
     private String formulaString(FormulaRecord record) {
 
-        StringBuffer buf = new StringBuffer();
+        StringBuilder buf = new StringBuilder();
 		Ptg[] tokens = record.getParsedExpression();
 		for (Ptg token : tokens) {
 			buf.append( token.toFormulaString());



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message