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:10 UTC
svn commit: r1857486 - in /ofbiz/ofbiz-framework/branches/release18.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:10 2019
New Revision: 1857486
URL: http://svn.apache.org/viewvc?rev=1857486&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/release18.12/ (props changed)
ofbiz/ofbiz-framework/branches/release18.12/applications/content/src/main/java/org/apache/ofbiz/content/data/DataResourceWorker.java
ofbiz/ofbiz-framework/branches/release18.12/applications/party/src/main/java/org/apache/ofbiz/party/communication/CommunicationEventServices.java
ofbiz/ofbiz-framework/branches/release18.12/applications/workeffort/src/main/java/org/apache/ofbiz/workeffort/workeffort/ICalConverter.java
ofbiz/ofbiz-framework/branches/release18.12/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilProperties.java
ofbiz/ofbiz-framework/branches/release18.12/framework/base/src/main/java/org/apache/ofbiz/base/util/string/UelFunctions.java
ofbiz/ofbiz-framework/branches/release18.12/framework/base/src/main/java/org/apache/ofbiz/base/util/template/XslTransform.java
ofbiz/ofbiz-framework/branches/release18.12/framework/base/src/main/java/org/apache/ofbiz/base/util/test/UtilPropertiesTests.java
ofbiz/ofbiz-framework/branches/release18.12/framework/common/src/main/java/org/apache/ofbiz/common/FtpServices.java
ofbiz/ofbiz-framework/branches/release18.12/framework/common/src/main/java/org/apache/ofbiz/common/email/EmailServices.java
ofbiz/ofbiz-framework/branches/release18.12/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntitySaxReader.java
ofbiz/ofbiz-framework/branches/release18.12/framework/minilang/src/main/java/org/apache/ofbiz/minilang/MiniLangUtil.java
ofbiz/ofbiz-framework/branches/release18.12/framework/service/src/main/java/org/apache/ofbiz/service/mail/MimeMessageWrapper.java
ofbiz/ofbiz-framework/branches/release18.12/framework/webapp/src/main/java/org/apache/ofbiz/webapp/WebAppUtil.java
ofbiz/ofbiz-framework/branches/release18.12/framework/webapp/src/main/java/org/apache/ofbiz/webapp/event/SOAPEventHandler.java
ofbiz/ofbiz-framework/branches/release18.12/framework/webapp/src/main/java/org/apache/ofbiz/webapp/view/ApacheFopWorker.java
ofbiz/ofbiz-framework/branches/release18.12/framework/webapp/src/main/java/org/apache/ofbiz/webapp/webdav/ResponseHelper.java
ofbiz/ofbiz-framework/branches/release18.12/framework/webapp/src/main/java/org/apache/ofbiz/webapp/webdav/WebDavUtil.java
Propchange: ofbiz/ofbiz-framework/branches/release18.12/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sat Apr 13 17:50:10 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:1849931,1850015,1850023,1850530,1850647,1850685,1850694,1850711,1850914,1850918,1850921,1850948,1850953,1851006,1851013,1851068,1851074,1851130,1851158,1851200,1851224,1851247,1851254,1851315,1851319,1851350,1851353,1851433,1851500,1851805,1851885,1851998,1852503,1852587,1852818,1852882,1853070,1853109,1853691,1853745,1853750,1854306,1854457,1854683,1855078,1855083,1855287,1855371,1855403,1855488,1855492,1855497,1855501,1855898,1856212,1856405,1856455,1856459-1856460,1856484,1856598,1856610,1856613,1856617,1856667,1857152,1857154,1857173,1857180,1857213,1857392
+/ofbiz/ofbiz-framework/trunk:1849931,1850015,1850023,1850530,1850647,1850685,1850694,1850711,1850914,1850918,1850921,1850948,1850953,1851006,1851013,1851068,1851074,1851130,1851158,1851200,1851224,1851247,1851254,1851315,1851319,1851350,1851353,1851433,1851500,1851805,1851885,1851998,1852503,1852587,1852818,1852882,1853070,1853109,1853691,1853745,1853750,1854306,1854457,1854683,1855078,1855083,1855287,1855371,1855403,1855488,1855492,1855497,1855501,1855898,1856212,1856405,1856455,1856459-1856460,1856484,1856598,1856610,1856613,1856617,1856667,1857099,1857152,1857154,1857173,1857180,1857213,1857392
Modified: ofbiz/ofbiz-framework/branches/release18.12/applications/content/src/main/java/org/apache/ofbiz/content/data/DataResourceWorker.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release18.12/applications/content/src/main/java/org/apache/ofbiz/content/data/DataResourceWorker.java?rev=1857486&r1=1857485&r2=1857486&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/branches/release18.12/applications/content/src/main/java/org/apache/ofbiz/content/data/DataResourceWorker.java (original)
+++ ofbiz/ofbiz-framework/branches/release18.12/applications/content/src/main/java/org/apache/ofbiz/content/data/DataResourceWorker.java Sat Apr 13 17:50:10 2019
@@ -628,9 +628,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,
@@ -888,14 +889,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/release18.12/applications/party/src/main/java/org/apache/ofbiz/party/communication/CommunicationEventServices.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release18.12/applications/party/src/main/java/org/apache/ofbiz/party/communication/CommunicationEventServices.java?rev=1857486&r1=1857485&r2=1857486&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/branches/release18.12/applications/party/src/main/java/org/apache/ofbiz/party/communication/CommunicationEventServices.java (original)
+++ ofbiz/ofbiz-framework/branches/release18.12/applications/party/src/main/java/org/apache/ofbiz/party/communication/CommunicationEventServices.java Sat Apr 13 17:50:10 2019
@@ -1611,8 +1611,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/release18.12/applications/workeffort/src/main/java/org/apache/ofbiz/workeffort/workeffort/ICalConverter.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release18.12/applications/workeffort/src/main/java/org/apache/ofbiz/workeffort/workeffort/ICalConverter.java?rev=1857486&r1=1857485&r2=1857486&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/branches/release18.12/applications/workeffort/src/main/java/org/apache/ofbiz/workeffort/workeffort/ICalConverter.java (original)
+++ ofbiz/ofbiz-framework/branches/release18.12/applications/workeffort/src/main/java/org/apache/ofbiz/workeffort/workeffort/ICalConverter.java Sat Apr 13 17:50:10 2019
@@ -582,9 +582,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/release18.12/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilProperties.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release18.12/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilProperties.java?rev=1857486&r1=1857485&r2=1857486&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/branches/release18.12/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilProperties.java (original)
+++ ofbiz/ofbiz-framework/branches/release18.12/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilProperties.java Sat Apr 13 17:50:10 2019
@@ -1185,18 +1185,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/release18.12/framework/base/src/main/java/org/apache/ofbiz/base/util/string/UelFunctions.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release18.12/framework/base/src/main/java/org/apache/ofbiz/base/util/string/UelFunctions.java?rev=1857486&r1=1857485&r2=1857486&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/branches/release18.12/framework/base/src/main/java/org/apache/ofbiz/base/util/string/UelFunctions.java (original)
+++ ofbiz/ofbiz-framework/branches/release18.12/framework/base/src/main/java/org/apache/ofbiz/base/util/string/UelFunctions.java Sat Apr 13 17:50:10 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/release18.12/framework/base/src/main/java/org/apache/ofbiz/base/util/template/XslTransform.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release18.12/framework/base/src/main/java/org/apache/ofbiz/base/util/template/XslTransform.java?rev=1857486&r1=1857485&r2=1857486&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/branches/release18.12/framework/base/src/main/java/org/apache/ofbiz/base/util/template/XslTransform.java (original)
+++ ofbiz/ofbiz-framework/branches/release18.12/framework/base/src/main/java/org/apache/ofbiz/base/util/template/XslTransform.java Sat Apr 13 17:50:10 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/release18.12/framework/base/src/main/java/org/apache/ofbiz/base/util/test/UtilPropertiesTests.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release18.12/framework/base/src/main/java/org/apache/ofbiz/base/util/test/UtilPropertiesTests.java?rev=1857486&r1=1857485&r2=1857486&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/branches/release18.12/framework/base/src/main/java/org/apache/ofbiz/base/util/test/UtilPropertiesTests.java (original)
+++ ofbiz/ofbiz-framework/branches/release18.12/framework/base/src/main/java/org/apache/ofbiz/base/util/test/UtilPropertiesTests.java Sat Apr 13 17:50:10 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/release18.12/framework/common/src/main/java/org/apache/ofbiz/common/FtpServices.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release18.12/framework/common/src/main/java/org/apache/ofbiz/common/FtpServices.java?rev=1857486&r1=1857485&r2=1857486&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/branches/release18.12/framework/common/src/main/java/org/apache/ofbiz/common/FtpServices.java (original)
+++ ofbiz/ofbiz-framework/branches/release18.12/framework/common/src/main/java/org/apache/ofbiz/common/FtpServices.java Sat Apr 13 17:50:10 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/release18.12/framework/common/src/main/java/org/apache/ofbiz/common/email/EmailServices.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release18.12/framework/common/src/main/java/org/apache/ofbiz/common/email/EmailServices.java?rev=1857486&r1=1857485&r2=1857486&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/branches/release18.12/framework/common/src/main/java/org/apache/ofbiz/common/email/EmailServices.java (original)
+++ ofbiz/ofbiz-framework/branches/release18.12/framework/common/src/main/java/org/apache/ofbiz/common/email/EmailServices.java Sat Apr 13 17:50:10 2019
@@ -541,8 +541,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)){
@@ -555,7 +554,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"));
@@ -566,10 +564,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/release18.12/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntitySaxReader.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release18.12/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntitySaxReader.java?rev=1857486&r1=1857485&r2=1857486&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/branches/release18.12/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntitySaxReader.java (original)
+++ ofbiz/ofbiz-framework/branches/release18.12/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntitySaxReader.java Sat Apr 13 17:50:10 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/release18.12/framework/minilang/src/main/java/org/apache/ofbiz/minilang/MiniLangUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release18.12/framework/minilang/src/main/java/org/apache/ofbiz/minilang/MiniLangUtil.java?rev=1857486&r1=1857485&r2=1857486&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/branches/release18.12/framework/minilang/src/main/java/org/apache/ofbiz/minilang/MiniLangUtil.java (original)
+++ ofbiz/ofbiz-framework/branches/release18.12/framework/minilang/src/main/java/org/apache/ofbiz/minilang/MiniLangUtil.java Sat Apr 13 17:50:10 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/release18.12/framework/service/src/main/java/org/apache/ofbiz/service/mail/MimeMessageWrapper.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release18.12/framework/service/src/main/java/org/apache/ofbiz/service/mail/MimeMessageWrapper.java?rev=1857486&r1=1857485&r2=1857486&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/branches/release18.12/framework/service/src/main/java/org/apache/ofbiz/service/mail/MimeMessageWrapper.java (original)
+++ ofbiz/ofbiz-framework/branches/release18.12/framework/service/src/main/java/org/apache/ofbiz/service/mail/MimeMessageWrapper.java Sat Apr 13 17:50:10 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/release18.12/framework/webapp/src/main/java/org/apache/ofbiz/webapp/WebAppUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release18.12/framework/webapp/src/main/java/org/apache/ofbiz/webapp/WebAppUtil.java?rev=1857486&r1=1857485&r2=1857486&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/branches/release18.12/framework/webapp/src/main/java/org/apache/ofbiz/webapp/WebAppUtil.java (original)
+++ ofbiz/ofbiz-framework/branches/release18.12/framework/webapp/src/main/java/org/apache/ofbiz/webapp/WebAppUtil.java Sat Apr 13 17:50:10 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/release18.12/framework/webapp/src/main/java/org/apache/ofbiz/webapp/event/SOAPEventHandler.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release18.12/framework/webapp/src/main/java/org/apache/ofbiz/webapp/event/SOAPEventHandler.java?rev=1857486&r1=1857485&r2=1857486&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/branches/release18.12/framework/webapp/src/main/java/org/apache/ofbiz/webapp/event/SOAPEventHandler.java (original)
+++ ofbiz/ofbiz-framework/branches/release18.12/framework/webapp/src/main/java/org/apache/ofbiz/webapp/event/SOAPEventHandler.java Sat Apr 13 17:50:10 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/release18.12/framework/webapp/src/main/java/org/apache/ofbiz/webapp/view/ApacheFopWorker.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release18.12/framework/webapp/src/main/java/org/apache/ofbiz/webapp/view/ApacheFopWorker.java?rev=1857486&r1=1857485&r2=1857486&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/branches/release18.12/framework/webapp/src/main/java/org/apache/ofbiz/webapp/view/ApacheFopWorker.java (original)
+++ ofbiz/ofbiz-framework/branches/release18.12/framework/webapp/src/main/java/org/apache/ofbiz/webapp/view/ApacheFopWorker.java Sat Apr 13 17:50:10 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/release18.12/framework/webapp/src/main/java/org/apache/ofbiz/webapp/webdav/ResponseHelper.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release18.12/framework/webapp/src/main/java/org/apache/ofbiz/webapp/webdav/ResponseHelper.java?rev=1857486&r1=1857485&r2=1857486&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/branches/release18.12/framework/webapp/src/main/java/org/apache/ofbiz/webapp/webdav/ResponseHelper.java (original)
+++ ofbiz/ofbiz-framework/branches/release18.12/framework/webapp/src/main/java/org/apache/ofbiz/webapp/webdav/ResponseHelper.java Sat Apr 13 17:50:10 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/release18.12/framework/webapp/src/main/java/org/apache/ofbiz/webapp/webdav/WebDavUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release18.12/framework/webapp/src/main/java/org/apache/ofbiz/webapp/webdav/WebDavUtil.java?rev=1857486&r1=1857485&r2=1857486&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/branches/release18.12/framework/webapp/src/main/java/org/apache/ofbiz/webapp/webdav/WebDavUtil.java (original)
+++ ofbiz/ofbiz-framework/branches/release18.12/framework/webapp/src/main/java/org/apache/ofbiz/webapp/webdav/WebDavUtil.java Sat Apr 13 17:50:10 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;
}