"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
------------------------------------------------------------------------


git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/branches/release17.12@1857487 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jacques Le Roux
2019-04-13 17:50:42 +00:00
parent bf73437f27
commit 69a46f08f4
17 changed files with 36 additions and 100 deletions
@@ -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);
@@ -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));