Skip to content
Permalink
Browse files
Use try-with-resource.
  • Loading branch information
garydgregory committed Nov 21, 2020
1 parent 045bcb5 commit fa7b8118d9d910dceb8a070a39bd7fc2e5de861a
Showing 3 changed files with 4 additions and 37 deletions.
@@ -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();
}
}
}

/**
@@ -53,20 +53,10 @@ private 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 static MimeMessage createMimeMessage(final Session session, final byte[]
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();
}
}
}

/**
@@ -31,11 +31,8 @@ protected byte[] toByteArray(final DataSource dataSource) throws IOException
{
if(dataSource != null)
{
final InputStream is = dataSource.getInputStream();
try {
try (InputStream is = dataSource.getInputStream()) {
return IOUtils.toByteArray(is);
} finally {
is.close();
}
}
return null;

0 comments on commit fa7b811

Please sign in to comment.