You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jl...@apache.org on 2019/04/13 17:50:43 UTC
svn commit: r1857487 - in /ofbiz/ofbiz-framework/branches/release17.12: ./
applications/content/src/main/java/org/apache/ofbiz/content/data/
applications/party/src/main/java/org/apache/ofbiz/party/communication/
applications/workeffort/src/main/java/or...
Author: jleroux
Date: Sat Apr 13 17:50:42 2019
New Revision: 1857487
URL: http://svn.apache.org/viewvc?rev=1857487&view=rev
Log:
"Applied fix from trunk for revision: 1857099"
------------------------------------------------------------------------
r1857099 | jleroux | 2019-04-08 11:17:55 +0200 (lun. 08 avr. 2019) | 12 lignes
Improved: Using try-with-resources with File IO Objects.
(OFBIZ-9855)
Uses try with resources for File IO objects like ObjectInputStream and other
objects. File classes have the AutoCloseable interface.
jleroux: this is only a part of the 2nd patch. The 1st patch will be committed
soon too...
All tests pass
Thanks: Pradhan Yash Sharma
------------------------------------------------------------------------
Modified:
ofbiz/ofbiz-framework/branches/release17.12/ (props changed)
ofbiz/ofbiz-framework/branches/release17.12/applications/content/src/main/java/org/apache/ofbiz/content/data/DataResourceWorker.java
ofbiz/ofbiz-framework/branches/release17.12/applications/party/src/main/java/org/apache/ofbiz/party/communication/CommunicationEventServices.java
ofbiz/ofbiz-framework/branches/release17.12/applications/workeffort/src/main/java/org/apache/ofbiz/workeffort/workeffort/ICalConverter.java
ofbiz/ofbiz-framework/branches/release17.12/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilProperties.java
ofbiz/ofbiz-framework/branches/release17.12/framework/base/src/main/java/org/apache/ofbiz/base/util/string/UelFunctions.java
ofbiz/ofbiz-framework/branches/release17.12/framework/base/src/main/java/org/apache/ofbiz/base/util/template/XslTransform.java
ofbiz/ofbiz-framework/branches/release17.12/framework/base/src/main/java/org/apache/ofbiz/base/util/test/UtilPropertiesTests.java
ofbiz/ofbiz-framework/branches/release17.12/framework/common/src/main/java/org/apache/ofbiz/common/FtpServices.java
ofbiz/ofbiz-framework/branches/release17.12/framework/common/src/main/java/org/apache/ofbiz/common/email/EmailServices.java
ofbiz/ofbiz-framework/branches/release17.12/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntitySaxReader.java
ofbiz/ofbiz-framework/branches/release17.12/framework/minilang/src/main/java/org/apache/ofbiz/minilang/MiniLangUtil.java
ofbiz/ofbiz-framework/branches/release17.12/framework/service/src/main/java/org/apache/ofbiz/service/mail/MimeMessageWrapper.java
ofbiz/ofbiz-framework/branches/release17.12/framework/webapp/src/main/java/org/apache/ofbiz/webapp/WebAppUtil.java
ofbiz/ofbiz-framework/branches/release17.12/framework/webapp/src/main/java/org/apache/ofbiz/webapp/event/SOAPEventHandler.java
ofbiz/ofbiz-framework/branches/release17.12/framework/webapp/src/main/java/org/apache/ofbiz/webapp/view/ApacheFopWorker.java
ofbiz/ofbiz-framework/branches/release17.12/framework/webapp/src/main/java/org/apache/ofbiz/webapp/webdav/ResponseHelper.java
ofbiz/ofbiz-framework/branches/release17.12/framework/webapp/src/main/java/org/apache/ofbiz/webapp/webdav/WebDavUtil.java
Propchange: ofbiz/ofbiz-framework/branches/release17.12/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sat Apr 13 17:50:42 2019
@@ -10,4 +10,4 @@
/ofbiz/branches/json-integration-refactoring:1634077-1635900
/ofbiz/branches/multitenant20100310:921280-927264
/ofbiz/branches/release13.07:1547657
-/ofbiz/ofbiz-framework/trunk:1819499,1819598,1819800,1819805,1819811,1819947,1820038,1820262,1820374-1820375,1820441,1820457,1820644,1820658,1820790,1820823,1820949,1820966,1821012,1821036,1821112,1821115,1821144,1821186,1821219,1821226,1821230,1821386,1821613,1821628,1821965,1822125,1822310,1822377,1822383,1822393,1823467,1823562,1823876,1824314,1824316,1824732,1824803,1824847,1824855,1825192,1825211,1825216,1825233,1825450,1826374,1826502,1826592,1826671,1826674,1826780,1826805,1826938,1826997,1827439,1828255,1828316,1828346,1828424,1828512,1828514,1829690,1830936,1831074,1831078,1831234,1831608,1831831,1832577,1832662,1832756,1832800,1832944,1833173,1833211,1834181,1834191,1834736,1835235,1835887,1835891,1835953,1835964,1836144,1836871,1837857,1838032,1838256,1838381,1840189,1840199,1840828,1841657,1841662,1842372,1842921,1843225,1843893,1844943,1845418,1845420,1845466,1845544,1845552,1845558,1845933,1845995,1846097,1846107,1846214,1846594,1846632,1847398,1847478,1847670,1847715,
1847890,1848263,1848336,1848386,1848398,1848441,1848444,1848447,1848449,1848467,1848469,1848745,1848849-1848850,1849021,1849165,1849191,1849193,1849275,1849467,1849528,1849540,1849567,1849693,1850015,1850023,1850530,1850647,1850685,1850694,1850914,1850918,1850948,1850953,1851006,1851068,1851074,1851130,1851158,1851163,1851200,1851247,1851319,1851350,1851805,1851998,1852587,1852818,1853070,1853109,1853691,1853745,1853750,1854306,1854457,1855078,1855287,1855371,1855403,1855488,1855492,1855497,1855501,1855898,1856405,1856455,1856459-1856460,1856484,1856598,1856617,1856667,1857173,1857180,1857213,1857392
+/ofbiz/ofbiz-framework/trunk:1819499,1819598,1819800,1819805,1819811,1819947,1820038,1820262,1820374-1820375,1820441,1820457,1820644,1820658,1820790,1820823,1820949,1820966,1821012,1821036,1821112,1821115,1821144,1821186,1821219,1821226,1821230,1821386,1821613,1821628,1821965,1822125,1822310,1822377,1822383,1822393,1823467,1823562,1823876,1824314,1824316,1824732,1824803,1824847,1824855,1825192,1825211,1825216,1825233,1825450,1826374,1826502,1826592,1826671,1826674,1826780,1826805,1826938,1826997,1827439,1828255,1828316,1828346,1828424,1828512,1828514,1829690,1830936,1831074,1831078,1831234,1831608,1831831,1832577,1832662,1832756,1832800,1832944,1833173,1833211,1834181,1834191,1834736,1835235,1835887,1835891,1835953,1835964,1836144,1836871,1837857,1838032,1838256,1838381,1840189,1840199,1840828,1841657,1841662,1842372,1842921,1843225,1843893,1844943,1845418,1845420,1845466,1845544,1845552,1845558,1845933,1845995,1846097,1846107,1846214,1846594,1846632,1847398,1847478,1847670,1847715,
1847890,1848263,1848336,1848386,1848398,1848441,1848444,1848447,1848449,1848467,1848469,1848745,1848849-1848850,1849021,1849165,1849191,1849193,1849275,1849467,1849528,1849540,1849567,1849693,1850015,1850023,1850530,1850647,1850685,1850694,1850914,1850918,1850948,1850953,1851006,1851068,1851074,1851130,1851158,1851163,1851200,1851247,1851319,1851350,1851805,1851998,1852587,1852818,1853070,1853109,1853691,1853745,1853750,1854306,1854457,1855078,1855287,1855371,1855403,1855488,1855492,1855497,1855501,1855898,1856405,1856455,1856459-1856460,1856484,1856598,1856617,1856667,1857099,1857173,1857180,1857213,1857392
Modified: ofbiz/ofbiz-framework/branches/release17.12/applications/content/src/main/java/org/apache/ofbiz/content/data/DataResourceWorker.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release17.12/applications/content/src/main/java/org/apache/ofbiz/content/data/DataResourceWorker.java?rev=1857487&r1=1857486&r2=1857487&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/branches/release17.12/applications/content/src/main/java/org/apache/ofbiz/content/data/DataResourceWorker.java (original)
+++ ofbiz/ofbiz-framework/branches/release17.12/applications/content/src/main/java/org/apache/ofbiz/content/data/DataResourceWorker.java Sat Apr 13 17:50:42 2019
@@ -624,9 +624,10 @@ public class DataResourceWorker impleme
public static String renderDataResourceAsText(LocalDispatcher dispatcher, Delegator delegator, String dataResourceId, Map<String, Object> templateContext,
Locale locale, String targetMimeTypeId, boolean cache) throws GeneralException, IOException {
- Writer writer = new StringWriter();
+ try (Writer writer = new StringWriter()) {
renderDataResourceAsText(dispatcher, delegator, dataResourceId, writer, templateContext, locale, targetMimeTypeId, cache, null);
return writer.toString();
+ }
}
public static String renderDataResourceAsText(LocalDispatcher dispatcher, String dataResourceId, Appendable out,
@@ -884,14 +885,13 @@ public class DataResourceWorker impleme
URL url = FlexibleLocation.resolveLocation(dataResource.getString("objectInfo"));
if (url.getHost() != null) { // is absolute
- InputStream in = url.openStream();
int c;
- StringWriter sw = new StringWriter();
+ try (InputStream in = url.openStream(); StringWriter sw = new StringWriter()) {
while ((c = in.read()) != -1) {
sw.write(c);
}
- sw.close();
text = sw.toString();
+ }
} else {
String prefix = DataResourceWorker.buildRequestPrefix(delegator, locale, webSiteId, https);
String sep = "";
Modified: ofbiz/ofbiz-framework/branches/release17.12/applications/party/src/main/java/org/apache/ofbiz/party/communication/CommunicationEventServices.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release17.12/applications/party/src/main/java/org/apache/ofbiz/party/communication/CommunicationEventServices.java?rev=1857487&r1=1857486&r2=1857487&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/branches/release17.12/applications/party/src/main/java/org/apache/ofbiz/party/communication/CommunicationEventServices.java (original)
+++ ofbiz/ofbiz-framework/branches/release17.12/applications/party/src/main/java/org/apache/ofbiz/party/communication/CommunicationEventServices.java Sat Apr 13 17:50:42 2019
@@ -1354,8 +1354,9 @@ public class CommunicationEventServices
URL imageUrl;
try {
imageUrl = FlexibleLocation.resolveLocation("component://common-theme/webapp/images/spacer.gif");
- InputStream imageStream = imageUrl.openStream();
+ try (InputStream imageStream = imageUrl.openStream()) {
UtilHttp.streamContentToBrowser(response, imageStream, 43, "image/gif", null);
+ }
} catch (MalformedURLException e) {
Debug.logError(e, module);
} catch (IOException e) {
Modified: ofbiz/ofbiz-framework/branches/release17.12/applications/workeffort/src/main/java/org/apache/ofbiz/workeffort/workeffort/ICalConverter.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release17.12/applications/workeffort/src/main/java/org/apache/ofbiz/workeffort/workeffort/ICalConverter.java?rev=1857487&r1=1857486&r2=1857487&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/branches/release17.12/applications/workeffort/src/main/java/org/apache/ofbiz/workeffort/workeffort/ICalConverter.java (original)
+++ ofbiz/ofbiz-framework/branches/release17.12/applications/workeffort/src/main/java/org/apache/ofbiz/workeffort/workeffort/ICalConverter.java Sat Apr 13 17:50:42 2019
@@ -578,9 +578,8 @@ public class ICalConverter {
calendar = new Calendar();
} else {
if (Debug.verboseOn()) Debug.logVerbose("iCalendar Data found, using saved Calendar", module);
- StringReader reader = new StringReader(iCalData);
+ try (StringReader reader = new StringReader(iCalData)) {
CalendarBuilder builder = new CalendarBuilder();
- try {
calendar = builder.build(reader);
newCalendar = false;
} catch (Exception e) {
Modified: ofbiz/ofbiz-framework/branches/release17.12/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilProperties.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release17.12/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilProperties.java?rev=1857487&r1=1857486&r2=1857487&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/branches/release17.12/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilProperties.java (original)
+++ ofbiz/ofbiz-framework/branches/release17.12/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilProperties.java Sat Apr 13 17:50:42 2019
@@ -1187,18 +1187,12 @@ public final class UtilProperties implem
super(defaults);
}
public ExtendedProperties(URL url, Locale locale) throws IOException, InvalidPropertiesFormatException {
- InputStream in = null;
- try {
- in = new BufferedInputStream(url.openStream());
+ try (InputStream in = new BufferedInputStream(url.openStream())) {
if (url.getFile().endsWith(".xml")) {
xmlToProperties(in, locale, this);
} else {
load(in);
}
- } finally {
- if (in != null) {
- in.close();
- }
}
}
@Override
Modified: ofbiz/ofbiz-framework/branches/release17.12/framework/base/src/main/java/org/apache/ofbiz/base/util/string/UelFunctions.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release17.12/framework/base/src/main/java/org/apache/ofbiz/base/util/string/UelFunctions.java?rev=1857487&r1=1857486&r2=1857487&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/branches/release17.12/framework/base/src/main/java/org/apache/ofbiz/base/util/string/UelFunctions.java (original)
+++ ofbiz/ofbiz-framework/branches/release17.12/framework/base/src/main/java/org/apache/ofbiz/base/util/string/UelFunctions.java Sat Apr 13 17:50:42 2019
@@ -25,6 +25,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Method;
+import java.net.MalformedURLException;
import java.net.URL;
import java.sql.Timestamp;
import java.text.DateFormat;
Modified: ofbiz/ofbiz-framework/branches/release17.12/framework/base/src/main/java/org/apache/ofbiz/base/util/template/XslTransform.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release17.12/framework/base/src/main/java/org/apache/ofbiz/base/util/template/XslTransform.java?rev=1857487&r1=1857486&r2=1857487&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/branches/release17.12/framework/base/src/main/java/org/apache/ofbiz/base/util/template/XslTransform.java (original)
+++ ofbiz/ofbiz-framework/branches/release17.12/framework/base/src/main/java/org/apache/ofbiz/base/util/template/XslTransform.java Sat Apr 13 17:50:42 2019
@@ -82,10 +82,11 @@ public final class XslTransform {
// compile the xsl template
Transformer transformer = tfactory.newTransformer(new StreamSource(template));
// and apply the xsl template to the source document and save in a result string
- StringWriter sw = new StringWriter();
+ try (StringWriter sw = new StringWriter()) {
StreamResult sr = new StreamResult(sw);
transformer.transform(source, sr);
result = sw.toString();
+ } catch (IOException e) {}
} else {
Debug.logError("tfactory does not support SAX features!", module);
}
@@ -156,8 +157,9 @@ public final class XslTransform {
} else if (UtilValidate.isNotEmpty(inputUrl)) {
URL url = FlexibleLocation.resolveLocation(inputUrl);
URLConnection conn = URLConnector.openConnection(url);
- InputStream in = conn.getInputStream();
+ try (InputStream in = conn.getInputStream()) {
source = new StreamSource(in);
+ }
}
return source;
}
Modified: ofbiz/ofbiz-framework/branches/release17.12/framework/base/src/main/java/org/apache/ofbiz/base/util/test/UtilPropertiesTests.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release17.12/framework/base/src/main/java/org/apache/ofbiz/base/util/test/UtilPropertiesTests.java?rev=1857487&r1=1857486&r2=1857487&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/branches/release17.12/framework/base/src/main/java/org/apache/ofbiz/base/util/test/UtilPropertiesTests.java (original)
+++ ofbiz/ofbiz-framework/branches/release17.12/framework/base/src/main/java/org/apache/ofbiz/base/util/test/UtilPropertiesTests.java Sat Apr 13 17:50:42 2019
@@ -75,7 +75,8 @@ public class UtilPropertiesTests extends
"\">Key Value</value>\n" +
" </property>\n" +
"</resource>";
- InputStream in = new ByteArrayInputStream(new String(xmlData.getBytes(), Charset.forName("UTF-8")).getBytes());
+ try (InputStream in = new ByteArrayInputStream(new String(xmlData.getBytes(), Charset.forName("UTF-8")).getBytes())) {
return UtilProperties.xmlToProperties(in, locale, null);
+ }
}
}
Modified: ofbiz/ofbiz-framework/branches/release17.12/framework/common/src/main/java/org/apache/ofbiz/common/FtpServices.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release17.12/framework/common/src/main/java/org/apache/ofbiz/common/FtpServices.java?rev=1857487&r1=1857486&r2=1857487&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/branches/release17.12/framework/common/src/main/java/org/apache/ofbiz/common/FtpServices.java (original)
+++ ofbiz/ofbiz-framework/branches/release17.12/framework/common/src/main/java/org/apache/ofbiz/common/FtpServices.java Sat Apr 13 17:50:42 2019
@@ -120,11 +120,6 @@ public class FtpServices {
} catch (Exception e) {
Debug.logWarning(e, "[putFile] Problem with FTP disconnect: ", module);
}
- try {
- localFile.close();
- } catch (Exception e) {
- Debug.logWarning(e, "[putFile] Problem closing local file: ", module);
- }
}
if (errorList.size() > 0) {
Debug.logError("[putFile] The following error(s) (" + errorList.size() + ") occurred: " + errorList, module);
@@ -188,11 +183,6 @@ public class FtpServices {
} catch (Exception e) {
Debug.logWarning(e, "[getFile] Problem with FTP disconnect: ", module);
}
- try {
- localFile.close();
- } catch (Exception e) {
- Debug.logWarning(e, "[getFile] Problem closing local file: ", module);
- }
}
if (errorList.size() > 0) {
Debug.logError("[getFile] The following error(s) (" + errorList.size() + ") occurred: " + errorList, module);
Modified: ofbiz/ofbiz-framework/branches/release17.12/framework/common/src/main/java/org/apache/ofbiz/common/email/EmailServices.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release17.12/framework/common/src/main/java/org/apache/ofbiz/common/email/EmailServices.java?rev=1857487&r1=1857486&r2=1857487&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/branches/release17.12/framework/common/src/main/java/org/apache/ofbiz/common/email/EmailServices.java (original)
+++ ofbiz/ofbiz-framework/branches/release17.12/framework/common/src/main/java/org/apache/ofbiz/common/email/EmailServices.java Sat Apr 13 17:50:42 2019
@@ -536,8 +536,7 @@ public class EmailServices {
isMultiPart = true;
// start processing fo pdf attachment
- try {
- Writer writer = new StringWriter();
+ try (Writer writer = new StringWriter(); ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
// substitute the freemarker variables...
ScreenStringRenderer foScreenStringRenderer = null;
if(MimeConstants.MIME_PLAIN_TEXT.equals(attachmentType)){
@@ -550,7 +549,6 @@ public class EmailServices {
screensAtt.render(xslfoAttachScreenLocation);
// create the output stream for the generation
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
if (MimeConstants.MIME_PLAIN_TEXT.equals(attachmentType)) {
baos.write(writer.toString().getBytes("UTF-8"));
@@ -561,10 +559,6 @@ public class EmailServices {
ApacheFopWorker.transform(src, null, fop);
}
- // and generate the attachment
- baos.flush();
- baos.close();
-
// store in the list of maps for sendmail....
bodyParts.add(UtilMisc.<String, Object>toMap("content", baos.toByteArray(), "type", attachmentType, "filename", attachmentName));
Modified: ofbiz/ofbiz-framework/branches/release17.12/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntitySaxReader.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release17.12/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntitySaxReader.java?rev=1857487&r1=1857486&r2=1857487&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/branches/release17.12/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntitySaxReader.java (original)
+++ ofbiz/ofbiz-framework/branches/release17.12/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntitySaxReader.java Sat Apr 13 17:50:42 2019
@@ -188,9 +188,10 @@ public class EntitySaxReader extends Def
Debug.logWarning("content was null, doing nothing", module);
return 0;
}
- ByteArrayInputStream bis = new ByteArrayInputStream(content.getBytes("UTF-8"));
+ try (ByteArrayInputStream bis = new ByteArrayInputStream(content.getBytes("UTF-8"))) {
return this.parse(bis, "Internal Content");
+ }
}
public long parse(URL location) throws SAXException, java.io.IOException {
@@ -199,17 +200,9 @@ public class EntitySaxReader extends Def
return 0;
}
Debug.logImportant("Beginning import from URL: " + location.toExternalForm(), module);
- InputStream is = null;
long numberRead = 0;
- try {
- is = location.openStream();
+ try (InputStream is = location.openStream()) {
numberRead = this.parse(is, location.toString());
- } finally {
- if (is != null) {
- try {
- is.close();
- } catch(Exception e) {}
- }
}
return numberRead;
}
Modified: ofbiz/ofbiz-framework/branches/release17.12/framework/minilang/src/main/java/org/apache/ofbiz/minilang/MiniLangUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release17.12/framework/minilang/src/main/java/org/apache/ofbiz/minilang/MiniLangUtil.java?rev=1857487&r1=1857486&r2=1857487&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/branches/release17.12/framework/minilang/src/main/java/org/apache/ofbiz/minilang/MiniLangUtil.java (original)
+++ ofbiz/ofbiz-framework/branches/release17.12/framework/minilang/src/main/java/org/apache/ofbiz/minilang/MiniLangUtil.java Sat Apr 13 17:50:42 2019
@@ -283,40 +283,22 @@ public final class MiniLangUtil {
*/
public static void writeMiniLangDocument(URL xmlURL, Document document) {
URL styleSheetURL = null;
- InputStream styleSheetInStream = null;
Transformer transformer = null;
try {
styleSheetURL = FlexibleLocation.resolveLocation("component://minilang/config/MiniLang.xslt");
- styleSheetInStream = styleSheetURL.openStream();
TransformerFactory transformerFactory = TransformerFactory.newInstance();
+ try (InputStream styleSheetInStream = styleSheetURL.openStream()) {
transformer = transformerFactory.newTransformer(new StreamSource(styleSheetInStream));
+ }
} catch (Exception e) {
Debug.logWarning(e, "Error reading minilang/config/MiniLang.xslt: ", module);
return;
- } finally {
- if (styleSheetInStream != null) {
- try {
- styleSheetInStream.close();
- } catch (IOException e) {
- Debug.logWarning(e, "Error closing minilang/config/MiniLang.xslt: ", module);
- }
- }
}
- FileOutputStream fos = null;
- try {
- fos = new FileOutputStream(xmlURL.getFile());
+ try (FileOutputStream fos = new FileOutputStream(xmlURL.getFile())) {
UtilXml.transformDomDocument(transformer, document, fos);
Debug.logInfo("Saved Mini-language file " + xmlURL, module);
} catch (Exception e) {
Debug.logWarning(e, "Error writing mini-language file " + xmlURL + ": ", module);
- } finally {
- if (fos != null) {
- try {
- fos.close();
- } catch (IOException e) {
- Debug.logWarning(e, "Error closing " + xmlURL + ": ", module);
- }
- }
}
}
Modified: ofbiz/ofbiz-framework/branches/release17.12/framework/service/src/main/java/org/apache/ofbiz/service/mail/MimeMessageWrapper.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release17.12/framework/service/src/main/java/org/apache/ofbiz/service/mail/MimeMessageWrapper.java?rev=1857487&r1=1857486&r2=1857487&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/branches/release17.12/framework/service/src/main/java/org/apache/ofbiz/service/mail/MimeMessageWrapper.java (original)
+++ ofbiz/ofbiz-framework/branches/release17.12/framework/service/src/main/java/org/apache/ofbiz/service/mail/MimeMessageWrapper.java Sat Apr 13 17:50:42 2019
@@ -105,10 +105,9 @@ public class MimeMessageWrapper implemen
if (message == null) {
// deserialize the message
if (serializedBytes != null) {
- ByteArrayInputStream bais = new ByteArrayInputStream(serializedBytes);
- try {
+ try (ByteArrayInputStream bais = new ByteArrayInputStream(serializedBytes)){
message = new MimeMessage(this.getSession(), bais);
- } catch (MessagingException e) {
+ } catch (MessagingException | IOException e) {
Debug.logError(e, module);
throw new GeneralRuntimeException(e.getMessage(), e);
}
@@ -393,8 +392,7 @@ public class MimeMessageWrapper implemen
public ByteBuffer getPartByteBuffer(String index) {
BodyPart part = getPart(index);
if (part != null) {
- try {
- InputStream stream = part.getInputStream();
+ try (InputStream stream = part.getInputStream()) {
return getByteBufferFromStream(stream);
} catch (Exception e) {
Debug.logError(e, module);
@@ -510,18 +508,16 @@ public class MimeMessageWrapper implemen
}
protected ByteBuffer getByteBufferFromStream(InputStream stream) {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[4096];
- try {
+ try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
for (int n; (n = stream.read(buffer)) != -1;) {
baos.write(buffer, 0, n);
}
+ return ByteBuffer.wrap(baos.toByteArray());
} catch (IOException e) {
Debug.logError(e, module);
return null;
}
-
- return ByteBuffer.wrap(baos.toByteArray());
}
static {
Modified: ofbiz/ofbiz-framework/branches/release17.12/framework/webapp/src/main/java/org/apache/ofbiz/webapp/WebAppUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release17.12/framework/webapp/src/main/java/org/apache/ofbiz/webapp/WebAppUtil.java?rev=1857487&r1=1857486&r2=1857487&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/branches/release17.12/framework/webapp/src/main/java/org/apache/ofbiz/webapp/WebAppUtil.java (original)
+++ ofbiz/ofbiz-framework/branches/release17.12/framework/webapp/src/main/java/org/apache/ofbiz/webapp/WebAppUtil.java Sat Apr 13 17:50:42 2019
@@ -249,7 +249,6 @@ public final class WebAppUtil {
throw new IllegalArgumentException(webXmlFileLocation + " does not exist.");
}
boolean namespaceAware = true;
- InputStream is = new FileInputStream(file);
result = new WebXml();
LocalResolver lr = new LocalResolver(new DefaultHandler());
ErrorHandler handler = new LocalErrorHandler(webXmlFileLocation, lr);
@@ -257,17 +256,10 @@ public final class WebAppUtil {
digester.getParser();
digester.push(result);
digester.setErrorHandler(handler);
- try {
+ try (InputStream is = new FileInputStream(file)) {
digester.parse(new InputSource(is));
} finally {
digester.reset();
- if (is != null) {
- try {
- is.close();
- } catch (Throwable t) {
- Debug.logError(t, "Exception thrown while parsing " + webXmlFileLocation + ": ", module);
- }
- }
}
result = webXmlCache.putIfAbsentAndGet(webXmlFileLocation, result);
}
Modified: ofbiz/ofbiz-framework/branches/release17.12/framework/webapp/src/main/java/org/apache/ofbiz/webapp/event/SOAPEventHandler.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release17.12/framework/webapp/src/main/java/org/apache/ofbiz/webapp/event/SOAPEventHandler.java?rev=1857487&r1=1857486&r2=1857487&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/branches/release17.12/framework/webapp/src/main/java/org/apache/ofbiz/webapp/event/SOAPEventHandler.java (original)
+++ ofbiz/ofbiz-framework/branches/release17.12/framework/webapp/src/main/java/org/apache/ofbiz/webapp/event/SOAPEventHandler.java Sat Apr 13 17:50:42 2019
@@ -103,8 +103,7 @@ public class SOAPEventHandler implements
}
if (wsdl != null) {
- try {
- OutputStream os = response.getOutputStream();
+ try (OutputStream os = response.getOutputStream()) {
response.setContentType("text/xml");
UtilXml.writeXmlDocument(os, wsdl);
response.flushBuffer();
@@ -119,8 +118,7 @@ public class SOAPEventHandler implements
}
if (serviceName == null) {
- try {
- Writer writer = response.getWriter();
+ try (Writer writer = response.getWriter()) {
StringBuilder sb = new StringBuilder();
sb.append("<html><head><title>OFBiz SOAP/1.1 Services</title></head>");
sb.append("<body>No such service.").append("<p>Services:<ul>");
Modified: ofbiz/ofbiz-framework/branches/release17.12/framework/webapp/src/main/java/org/apache/ofbiz/webapp/view/ApacheFopWorker.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release17.12/framework/webapp/src/main/java/org/apache/ofbiz/webapp/view/ApacheFopWorker.java?rev=1857487&r1=1857486&r2=1857487&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/branches/release17.12/framework/webapp/src/main/java/org/apache/ofbiz/webapp/view/ApacheFopWorker.java (original)
+++ ofbiz/ofbiz-framework/branches/release17.12/framework/webapp/src/main/java/org/apache/ofbiz/webapp/view/ApacheFopWorker.java Sat Apr 13 17:50:42 2019
@@ -138,10 +138,10 @@ public final class ApacheFopWorker {
public static void transform(File srcFile, File destFile, File stylesheetFile, String outputFormat) throws IOException, FOPException {
StreamSource src = new StreamSource(srcFile);
StreamSource stylesheet = stylesheetFile == null ? null : new StreamSource(stylesheetFile);
- BufferedOutputStream dest = new BufferedOutputStream(new FileOutputStream(destFile));
+ try (BufferedOutputStream dest = new BufferedOutputStream(new FileOutputStream(destFile))) {
Fop fop = createFopInstance(dest, outputFormat);
transform(src, stylesheet, fop);
- dest.close();
+ }
}
/** Transform an xsl-fo InputStream to the specified OutputStream format.
Modified: ofbiz/ofbiz-framework/branches/release17.12/framework/webapp/src/main/java/org/apache/ofbiz/webapp/webdav/ResponseHelper.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release17.12/framework/webapp/src/main/java/org/apache/ofbiz/webapp/webdav/ResponseHelper.java?rev=1857487&r1=1857486&r2=1857487&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/branches/release17.12/framework/webapp/src/main/java/org/apache/ofbiz/webapp/webdav/ResponseHelper.java (original)
+++ ofbiz/ofbiz-framework/branches/release17.12/framework/webapp/src/main/java/org/apache/ofbiz/webapp/webdav/ResponseHelper.java Sat Apr 13 17:50:42 2019
@@ -98,13 +98,12 @@ public class ResponseHelper {
}
public void writeResponse(HttpServletResponse response, Writer writer) throws IOException {
- ByteArrayOutputStream os = new ByteArrayOutputStream();
- try {
+ try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
UtilXml.writeXmlDocument(os, this.responseDocument, "UTF-8", true, true);
+ response.setContentLength(os.size());
+ writer.write(os.toString("UTF-8"));
} catch (Exception e) {
throw new IOException(e.getMessage());
}
- response.setContentLength(os.size());
- writer.write(os.toString("UTF-8"));
}
}
Modified: ofbiz/ofbiz-framework/branches/release17.12/framework/webapp/src/main/java/org/apache/ofbiz/webapp/webdav/WebDavUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release17.12/framework/webapp/src/main/java/org/apache/ofbiz/webapp/webdav/WebDavUtil.java?rev=1857487&r1=1857486&r2=1857487&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/branches/release17.12/framework/webapp/src/main/java/org/apache/ofbiz/webapp/webdav/WebDavUtil.java (original)
+++ ofbiz/ofbiz-framework/branches/release17.12/framework/webapp/src/main/java/org/apache/ofbiz/webapp/webdav/WebDavUtil.java Sat Apr 13 17:50:42 2019
@@ -55,14 +55,8 @@ public final class WebDavUtil {
public static Document getDocumentFromRequest(HttpServletRequest request) throws IOException, SAXException, ParserConfigurationException {
Document document = null;
- InputStream is = null;
- try {
- is = request.getInputStream();
+ try (InputStream is = request.getInputStream()) {
document = UtilXml.readXmlDocument(is, false, "WebDAV request");
- } finally {
- if (is != null) {
- is.close();
- }
}
return document;
}