This is an automated email from the ASF dual-hosted git repository. rcordier pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 432a6f59ff921c9466090d590d9e4c353d9f0eb6 Author: Manish Agarwal <itsmanishagar...@gmail.com> AuthorDate: Fri Feb 15 00:16:04 2019 -0800 JAMES-2210 Evaluate the performance impact to use commons-io in FileSystemBlobStrategy As per the description chaged the code to use IOUtils::copy. Did not use IOutils::closeQuietly as it is deprecated in latest releases, and recommended way is to use the try-with-resources statement. --- .../queue/activemq/FileSystemBlobStrategy.java | 25 ++++++---------------- 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/server/queue/queue-activemq/src/main/java/org/apache/james/queue/activemq/FileSystemBlobStrategy.java b/server/queue/queue-activemq/src/main/java/org/apache/james/queue/activemq/FileSystemBlobStrategy.java index 1195a8e..3568e5c 100644 --- a/server/queue/queue-activemq/src/main/java/org/apache/james/queue/activemq/FileSystemBlobStrategy.java +++ b/server/queue/queue-activemq/src/main/java/org/apache/james/queue/activemq/FileSystemBlobStrategy.java @@ -35,6 +35,7 @@ import org.apache.activemq.blob.BlobTransferPolicy; import org.apache.activemq.blob.BlobUploadStrategy; import org.apache.activemq.command.ActiveMQBlobMessage; import org.apache.commons.io.FileUtils; +import org.apache.commons.io.IOUtils; import org.apache.james.filesystem.api.FileSystem; /** @@ -58,20 +59,16 @@ public class FileSystemBlobStrategy implements BlobUploadStrategy, BlobDownloadS @Override public URL uploadFile(ActiveMQBlobMessage message, File file) throws JMSException, IOException { - return uploadStream(message, new FileInputStream(file)); + try (FileInputStream in = new FileInputStream(file)) { + return uploadStream(message, in); + } } @Override public URL uploadStream(ActiveMQBlobMessage message, InputStream in) throws JMSException, IOException { - FileOutputStream out = null; - try { - File f = getFile(message); - out = new FileOutputStream(f); - byte[] buffer = new byte[policy.getBufferSize()]; - for (int c = in.read(buffer); c != -1; c = in.read(buffer)) { - out.write(buffer, 0, c); - out.flush(); - } + File f = getFile(message); + try (FileOutputStream out = new FileOutputStream(f)) { + IOUtils.copy(in, out, policy.getBufferSize()); out.flush(); // File.toURL() is deprecated return f.toURI().toURL(); @@ -83,15 +80,7 @@ public class FileSystemBlobStrategy implements BlobUploadStrategy, BlobDownloadS // ignore on close } } - if (out != null) { - try { - out.close(); - } catch (IOException e) { - // ignore on close - } - } } - } @Override --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org