svn commit: r1797743 - in /ofbiz/ofbiz-framework/trunk/framework: common/src/main/java/org/apache/ofbiz/common/CommonServices.java entityext/src/main/java/org/apache/ofbiz/entityext/data/UpgradeServices.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1797743 - in /ofbiz/ofbiz-framework/trunk/framework: common/src/main/java/org/apache/ofbiz/common/CommonServices.java entityext/src/main/java/org/apache/ofbiz/entityext/data/UpgradeServices.java

jleroux@apache.org
Author: jleroux
Date: Tue Jun  6 07:40:51 2017
New Revision: 1797743

URL: http://svn.apache.org/viewvc?rev=1797743&view=rev
Log:
No functional changes.

Replaces Writer.close() in finally by try-with-ressource

Modified:
    ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/CommonServices.java
    ofbiz/ofbiz-framework/trunk/framework/entityext/src/main/java/org/apache/ofbiz/entityext/data/UpgradeServices.java

Modified: ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/CommonServices.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/CommonServices.java?rev=1797743&r1=1797742&r2=1797743&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/CommonServices.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/CommonServices.java Tue Jun  6 07:40:51 2017
@@ -472,10 +472,9 @@ public class CommonServices {
         OutputStream out = (OutputStream) context.get("outputStream");
 
         BufferedReader reader = new BufferedReader(new InputStreamReader(in));
-        Writer writer = new OutputStreamWriter(out);
         String line;
 
-        try {
+        try (Writer writer = new OutputStreamWriter(out)) {
             while ((line = reader.readLine()) != null) {
                 Debug.logInfo("Read line: " + line, module);
                 writer.write(line);
@@ -483,12 +482,6 @@ public class CommonServices {
         } catch (IOException e) {
             Debug.logError(e, module);
             return ServiceUtil.returnError(e.getMessage());
-        } finally {
-            try {
-                writer.close();
-            } catch (Exception e) {
-                Debug.logError(e, module);
-            }
         }
 
         Map<String, Object> result = ServiceUtil.returnSuccess();

Modified: ofbiz/ofbiz-framework/trunk/framework/entityext/src/main/java/org/apache/ofbiz/entityext/data/UpgradeServices.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/entityext/src/main/java/org/apache/ofbiz/entityext/data/UpgradeServices.java?rev=1797743&r1=1797742&r2=1797743&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/entityext/src/main/java/org/apache/ofbiz/entityext/data/UpgradeServices.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/entityext/src/main/java/org/apache/ofbiz/entityext/data/UpgradeServices.java Tue Jun  6 07:40:51 2017
@@ -65,11 +65,9 @@ public class UpgradeServices {
         String groupName = (String) context.get("groupName");
 
         Map<String, ModelEntity> modelEntities;
-        PrintWriter dataWriter = null;
-        try {
+        try (PrintWriter dataWriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
+                    new FileOutputStream(new File(System.getProperty("ofbiz.home") + "/runtime/tempfiles/" + groupName + ".sql")), "UTF-8")))) {
             modelEntities = delegator.getModelEntityMapByGroup(groupName);
-            dataWriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
-                    new FileOutputStream(new File(System.getProperty("ofbiz.home") + "/runtime/tempfiles/" + groupName + ".sql")), "UTF-8")));
 
             /* TODO:
             1) fetch the meta data of the "date-time" field using the JDBC connection and JDBC meta data;
@@ -91,16 +89,12 @@ public class UpgradeServices {
                 }
             }
             dataWriter.println("SET FOREIGN_KEY_CHECKS=1;");
-            dataWriter.close();
         } catch (GenericEntityException e) {
             Debug.logError(e, "Error getting list of entities in group: " + e.toString(), module);
             return ServiceUtil.returnError(UtilProperties.getMessage(resource, "EntityExtErrorGettingListOfEntityInGroup", UtilMisc.toMap("errorString", e.toString()), locale));
         } catch (FileNotFoundException | UnsupportedEncodingException e) {
             Debug.logError(e, e.getMessage(), module);
             return ServiceUtil.returnError(e.getMessage());
-        } finally {
-            if (dataWriter != null)
-                dataWriter.close();
         }
 
         return ServiceUtil.returnSuccess();