This is an automated email from the ASF dual-hosted git repository.
pawan pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git The following commit(s) were added to refs/heads/trunk by this push: new 2a4a617 Improved: Replace try-finally with try with resources(OFBIZ-11826) 2a4a617 is described below commit 2a4a617d0d63dd288cca5dd1f657c16d83d36240 Author: Pawan Verma <[hidden email]> AuthorDate: Mon Jun 22 21:32:42 2020 +0530 Improved: Replace try-finally with try with resources(OFBIZ-11826) Set checkstyleMain.maxErrors to 26678 (-4) Thanks: Jacques for the review. --- .../ofbiz/accounting/thirdparty/sagepay/SagePayUtil.java | 6 +----- .../java/org/apache/ofbiz/base/util/KeyStoreUtil.java | 15 +++------------ .../src/main/java/org/apache/ofbiz/base/util/UtilXml.java | 8 +------- .../ofbiz/webtools/labelmanager/SaveLabelsToXmlFile.java | 4 +--- 4 files changed, 6 insertions(+), 27 deletions(-) diff --git a/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/sagepay/SagePayUtil.java b/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/sagepay/SagePayUtil.java index bf2ea19..65dc2f7 100644 --- a/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/sagepay/SagePayUtil.java +++ b/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/sagepay/SagePayUtil.java @@ -147,8 +147,7 @@ public final class SagePayUtil { HttpEntity httpEntity = response.getEntity(); if (httpEntity != null) { InputStream inputStream = httpEntity.getContent(); - BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8)); - try{ + try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))) { String data = null; while ((data = reader.readLine()) != null) { if (data.indexOf("=") != -1) { @@ -158,9 +157,6 @@ public final class SagePayUtil { } } } - finally { - reader.close(); - } } Debug.logInfo("SagePay Response Data : " + responseData, MODULE); return responseData; diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/util/KeyStoreUtil.java b/framework/base/src/main/java/org/apache/ofbiz/base/util/KeyStoreUtil.java index de92631..aafa1c8 100755 --- a/framework/base/src/main/java/org/apache/ofbiz/base/util/KeyStoreUtil.java +++ b/framework/base/src/main/java/org/apache/ofbiz/base/util/KeyStoreUtil.java @@ -67,11 +67,8 @@ public final class KeyStoreUtil { public static void storeComponentKeyStore(String componentName, String keyStoreName, KeyStore store) throws IOException, GenericConfigException, NoSuchAlgorithmException, CertificateException, KeyStoreException { ComponentConfig.KeystoreInfo ks = ComponentConfig.getKeystoreInfo(componentName, keyStoreName); File file = FileUtil.getFile(ks.createResourceHandler().getFullLocation()); - FileOutputStream out = new FileOutputStream(file); - try { + try (FileOutputStream out = new FileOutputStream(file)) { store.store(out, ks.getPassword().toCharArray()); - } finally { - out.close(); } } @@ -89,11 +86,8 @@ public final class KeyStoreUtil { throw new IOException("Invalid keystore type; null"); } KeyStore ks = KeyStore.getInstance(type); - InputStream in = url.openStream(); - try { + try (InputStream in = url.openStream()) { ks.load(in, password.toCharArray()); - } finally { - in.close(); } return ks; } @@ -118,11 +112,8 @@ public final class KeyStoreUtil { } if (keyFile.exists() && keyFile.canRead()) { - InputStream in = new FileInputStream(keyFile); - try { + try (InputStream in = new FileInputStream(keyFile)) { ks.load(in, password.toCharArray()); - } finally { - in.close(); } } else { ks.load(null, "changeit".toCharArray()); diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilXml.java b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilXml.java index f25cd1c..90249b3 100644 --- a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilXml.java +++ b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilXml.java @@ -325,14 +325,8 @@ public final class UtilXml { return; } File outFile = new File(filename); - FileOutputStream fos = null; - try { - fos = new FileOutputStream(outFile); + try (FileOutputStream fos = new FileOutputStream(outFile)) { writeXmlDocument(fos, node); - } finally { - if (fos != null) { - fos.close(); - } } } diff --git a/framework/webtools/src/main/java/org/apache/ofbiz/webtools/labelmanager/SaveLabelsToXmlFile.java b/framework/webtools/src/main/java/org/apache/ofbiz/webtools/labelmanager/SaveLabelsToXmlFile.java index e10de22..c3b560f 100644 --- a/framework/webtools/src/main/java/org/apache/ofbiz/webtools/labelmanager/SaveLabelsToXmlFile.java +++ b/framework/webtools/src/main/java/org/apache/ofbiz/webtools/labelmanager/SaveLabelsToXmlFile.java @@ -143,14 +143,12 @@ public class SaveLabelsToXmlFile { } } } - FileOutputStream fos = new FileOutputStream(labelFile.file); - try { + try (FileOutputStream fos = new FileOutputStream(labelFile.file)) { if (apacheLicenseText != null) { fos.write(apacheLicenseText.getBytes()); } UtilXml.writeXmlDocument(resourceElem, fos, "UTF-8", !(apacheLicenseText == null), true, 4); } finally { - fos.close(); // clear cache to see immediately the new labels and // translations in OFBiz UtilCache.clearCache("properties.UtilPropertiesBundleCache"); |
Free forum by Nabble | Edit this page |