Author: jleroux
Date: Mon Apr 8 09:17:55 2019
New Revision: 1857099
URL: http://svn.apache.org/viewvc?rev=1857099&view=rev
Log:
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/trunk/applications/content/src/main/java/org/apache/ofbiz/content/data/DataResourceWorker.java
ofbiz/ofbiz-framework/trunk/applications/party/src/main/java/org/apache/ofbiz/party/communication/CommunicationEventServices.java
ofbiz/ofbiz-framework/trunk/applications/workeffort/src/main/java/org/apache/ofbiz/workeffort/workeffort/ICalConverter.java
ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilProperties.java
ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/string/UelFunctions.java
ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/template/XslTransform.java
ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/test/UtilPropertiesTests.java
ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/FtpServices.java
ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/email/EmailServices.java
ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntitySaxReader.java
ofbiz/ofbiz-framework/trunk/framework/minilang/src/main/java/org/apache/ofbiz/minilang/MiniLangUtil.java
ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/mail/MimeMessageWrapper.java
ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/WebAppUtil.java
ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/event/SOAPEventHandler.java
ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/view/ApacheFopWorker.java
ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/webdav/ResponseHelper.java
ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/webdav/WebDavUtil.java
Modified:
ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/data/DataResourceWorker.java
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/data/DataResourceWorker.java?rev=1857099&r1=1857098&r2=1857099&view=diff
==============================================================================
---
ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/data/DataResourceWorker.java
(original)
+++
ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/data/DataResourceWorker.java
Mon Apr 8 09:17:55 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/trunk/applications/party/src/main/java/org/apache/ofbiz/party/communication/CommunicationEventServices.java
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/party/src/main/java/org/apache/ofbiz/party/communication/CommunicationEventServices.java?rev=1857099&r1=1857098&r2=1857099&view=diff
==============================================================================
---
ofbiz/ofbiz-framework/trunk/applications/party/src/main/java/org/apache/ofbiz/party/communication/CommunicationEventServices.java
(original)
+++
ofbiz/ofbiz-framework/trunk/applications/party/src/main/java/org/apache/ofbiz/party/communication/CommunicationEventServices.java
Mon Apr 8 09:17:55 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/trunk/applications/workeffort/src/main/java/org/apache/ofbiz/workeffort/workeffort/ICalConverter.java
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/workeffort/src/main/java/org/apache/ofbiz/workeffort/workeffort/ICalConverter.java?rev=1857099&r1=1857098&r2=1857099&view=diff
==============================================================================
---
ofbiz/ofbiz-framework/trunk/applications/workeffort/src/main/java/org/apache/ofbiz/workeffort/workeffort/ICalConverter.java
(original)
+++
ofbiz/ofbiz-framework/trunk/applications/workeffort/src/main/java/org/apache/ofbiz/workeffort/workeffort/ICalConverter.java
Mon Apr 8 09:17:55 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/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilProperties.java
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilProperties.java?rev=1857099&r1=1857098&r2=1857099&view=diff
==============================================================================
---
ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilProperties.java
(original)
+++
ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilProperties.java
Mon Apr 8 09:17:55 2019
@@ -1177,18 +1177,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/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/string/UelFunctions.java
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/string/UelFunctions.java?rev=1857099&r1=1857098&r2=1857099&view=diff
==============================================================================
---
ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/string/UelFunctions.java
(original)
+++
ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/string/UelFunctions.java
Mon Apr 8 09:17:55 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/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/template/XslTransform.java
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/template/XslTransform.java?rev=1857099&r1=1857098&r2=1857099&view=diff
==============================================================================
---
ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/template/XslTransform.java
(original)
+++
ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/template/XslTransform.java
Mon Apr 8 09:17:55 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/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/test/UtilPropertiesTests.java
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/test/UtilPropertiesTests.java?rev=1857099&r1=1857098&r2=1857099&view=diff
==============================================================================
---
ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/test/UtilPropertiesTests.java
(original)
+++
ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/test/UtilPropertiesTests.java
Mon Apr 8 09:17:55 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/trunk/framework/common/src/main/java/org/apache/ofbiz/common/FtpServices.java
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/FtpServices.java?rev=1857099&r1=1857098&r2=1857099&view=diff
==============================================================================
---
ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/FtpServices.java
(original)
+++
ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/FtpServices.java
Mon Apr 8 09:17:55 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/trunk/framework/common/src/main/java/org/apache/ofbiz/common/email/EmailServices.java
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/email/EmailServices.java?rev=1857099&r1=1857098&r2=1857099&view=diff
==============================================================================
---
ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/email/EmailServices.java
(original)
+++
ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/email/EmailServices.java
Mon Apr 8 09:17:55 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/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntitySaxReader.java
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntitySaxReader.java?rev=1857099&r1=1857098&r2=1857099&view=diff
==============================================================================
---
ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntitySaxReader.java
(original)
+++
ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntitySaxReader.java
Mon Apr 8 09:17:55 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/trunk/framework/minilang/src/main/java/org/apache/ofbiz/minilang/MiniLangUtil.java
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/minilang/src/main/java/org/apache/ofbiz/minilang/MiniLangUtil.java?rev=1857099&r1=1857098&r2=1857099&view=diff
==============================================================================
---
ofbiz/ofbiz-framework/trunk/framework/minilang/src/main/java/org/apache/ofbiz/minilang/MiniLangUtil.java
(original)
+++
ofbiz/ofbiz-framework/trunk/framework/minilang/src/main/java/org/apache/ofbiz/minilang/MiniLangUtil.java
Mon Apr 8 09:17:55 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/trunk/framework/service/src/main/java/org/apache/ofbiz/service/mail/MimeMessageWrapper.java
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/mail/MimeMessageWrapper.java?rev=1857099&r1=1857098&r2=1857099&view=diff
==============================================================================
---
ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/mail/MimeMessageWrapper.java
(original)
+++
ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/mail/MimeMessageWrapper.java
Mon Apr 8 09:17:55 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/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/WebAppUtil.java
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/WebAppUtil.java?rev=1857099&r1=1857098&r2=1857099&view=diff
==============================================================================
---
ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/WebAppUtil.java
(original)
+++
ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/WebAppUtil.java
Mon Apr 8 09:17:55 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/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/event/SOAPEventHandler.java
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/event/SOAPEventHandler.java?rev=1857099&r1=1857098&r2=1857099&view=diff
==============================================================================
---
ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/event/SOAPEventHandler.java
(original)
+++
ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/event/SOAPEventHandler.java
Mon Apr 8 09:17:55 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/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/view/ApacheFopWorker.java
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/view/ApacheFopWorker.java?rev=1857099&r1=1857098&r2=1857099&view=diff
==============================================================================
---
ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/view/ApacheFopWorker.java
(original)
+++
ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/view/ApacheFopWorker.java
Mon Apr 8 09:17:55 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/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/webdav/ResponseHelper.java
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/webdav/ResponseHelper.java?rev=1857099&r1=1857098&r2=1857099&view=diff
==============================================================================
---
ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/webdav/ResponseHelper.java
(original)
+++
ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/webdav/ResponseHelper.java
Mon Apr 8 09:17:55 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/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/webdav/WebDavUtil.java
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/webdav/WebDavUtil.java?rev=1857099&r1=1857098&r2=1857099&view=diff
==============================================================================
---
ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/webdav/WebDavUtil.java
(original)
+++
ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/webdav/WebDavUtil.java
Mon Apr 8 09:17:55 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;
}