You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2020/11/21 15:37:08 UTC
[commons-email] branch master updated: Use try-with-resource.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-email.git
The following commit(s) were added to refs/heads/master by this push:
new fa7b811 Use try-with-resource.
fa7b811 is described below
commit fa7b8118d9d910dceb8a070a39bd7fc2e5de861a
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Nov 21 10:37:04 2020 -0500
Use try-with-resource.
---
.../apache/commons/mail/ByteArrayDataSource.java | 12 +----------
.../apache/commons/mail/util/MimeMessageUtils.java | 24 ++--------------------
.../resolver/AbstractDataSourceResolverTest.java | 5 +----
3 files changed, 4 insertions(+), 37 deletions(-)
diff --git a/src/main/java/org/apache/commons/mail/ByteArrayDataSource.java b/src/main/java/org/apache/commons/mail/ByteArrayDataSource.java
index 322d874..e489abb 100644
--- a/src/main/java/org/apache/commons/mail/ByteArrayDataSource.java
+++ b/src/main/java/org/apache/commons/mail/ByteArrayDataSource.java
@@ -71,20 +71,10 @@ public class ByteArrayDataSource implements DataSource
public ByteArrayDataSource(final byte[] data, final String aType) throws IOException
{
this.type = aType;
- ByteArrayInputStream bis = null;
-
- try
+ try (ByteArrayInputStream bis = new ByteArrayInputStream(data))
{
- bis = new ByteArrayInputStream(data);
this.byteArrayDataSource(bis);
}
- finally
- {
- if (bis != null)
- {
- bis.close();
- }
- }
}
/**
diff --git a/src/main/java/org/apache/commons/mail/util/MimeMessageUtils.java b/src/main/java/org/apache/commons/mail/util/MimeMessageUtils.java
index 5e3d7d3..503480c 100644
--- a/src/main/java/org/apache/commons/mail/util/MimeMessageUtils.java
+++ b/src/main/java/org/apache/commons/mail/util/MimeMessageUtils.java
@@ -53,20 +53,10 @@ public final class MimeMessageUtils
public static MimeMessage createMimeMessage(final Session session, final byte[] source)
throws MessagingException, IOException
{
- ByteArrayInputStream is = null;
-
- try
+ try (ByteArrayInputStream is = new ByteArrayInputStream(source))
{
- is = new ByteArrayInputStream(source);
return new MimeMessage(session, is);
}
- finally
- {
- if (is != null)
- {
- is.close();
- }
- }
}
/**
@@ -81,20 +71,10 @@ public final class MimeMessageUtils
public static MimeMessage createMimeMessage(final Session session, final File source)
throws MessagingException, IOException
{
- FileInputStream is = null;
-
- try
+ try (FileInputStream is = new FileInputStream(source))
{
- is = new FileInputStream(source);
return createMimeMessage(session, is);
}
- finally
- {
- if (is != null)
- {
- is.close();
- }
- }
}
/**
diff --git a/src/test/java/org/apache/commons/mail/resolver/AbstractDataSourceResolverTest.java b/src/test/java/org/apache/commons/mail/resolver/AbstractDataSourceResolverTest.java
index 7466b0b..fc4caf9 100644
--- a/src/test/java/org/apache/commons/mail/resolver/AbstractDataSourceResolverTest.java
+++ b/src/test/java/org/apache/commons/mail/resolver/AbstractDataSourceResolverTest.java
@@ -31,11 +31,8 @@ public abstract class AbstractDataSourceResolverTest {
{
if(dataSource != null)
{
- final InputStream is = dataSource.getInputStream();
- try {
+ try (InputStream is = dataSource.getInputStream()) {
return IOUtils.toByteArray(is);
- } finally {
- is.close();
}
}
return null;