Skip to content
Permalink
Browse files
Use try-with-resources
  • Loading branch information
garydgregory committed Jun 9, 2022
1 parent 29cce9a commit e93e4e81652b8d30854815023ad9cf91e28ce230
Showing 4 changed files with 12 additions and 15 deletions.
@@ -1432,6 +1432,7 @@ else if (this.emailBody != null)

if (this.popBeforeSmtp)
{
// TODO Why is this not a Store leak? When to close?
final Store store = session.getStore("pop3");
store.connect(this.popHost, this.popUsername, this.popPassword);
}
@@ -386,8 +386,7 @@ public MultiPartEmail attach(
// verify that the URL is valid
try
{
final InputStream is = url.openStream();
is.close();
url.openStream().close();
}
catch (final IOException e)
{
@@ -414,16 +413,13 @@ public MultiPartEmail attach(
final String description)
throws EmailException
{
if (ds == null)
{
throw new EmailException("Invalid Datasource");
}
// verify that the DataSource is valid
try
try (InputStream is = ds.getInputStream())
{
final InputStream is = ds != null ? ds.getInputStream() : null;
if (is != null)
{
// close the input stream to prevent file locking on windows
is.close();
}

if (is == null)
{
throw new EmailException("Invalid Datasource");
@@ -433,7 +429,6 @@ public MultiPartEmail attach(
{
throw new EmailException("Invalid Datasource", e);
}

return attach(ds, name, description, EmailAttachment.ATTACHMENT);
}

@@ -105,8 +105,6 @@ public DataSource resolve(final String resourceLocation, final boolean isLenient
result = ds;
}
}


return result;
}
catch (final IOException e)
@@ -270,10 +270,13 @@ protected DataSource createDataSource(final Multipart parent, final MimePart par
final DataHandler dataHandler = part.getDataHandler();
final DataSource dataSource = dataHandler.getDataSource();
final String contentType = getBaseMimeType(dataSource.getContentType());
final byte[] content = this.getContent(dataSource.getInputStream());
byte[] content;
try (InputStream inputStream = dataSource.getInputStream())
{
content = this.getContent(inputStream);
}
final ByteArrayDataSource result = new ByteArrayDataSource(content, contentType);
final String dataSourceName = getDataSourceName(part, dataSource);

result.setName(dataSourceName);
return result;
}

0 comments on commit e93e4e8

Please sign in to comment.