Author: norman Date: Thu Nov 18 18:35:45 2010 New Revision: 1036569 URL: http://svn.apache.org/viewvc?rev=1036569&view=rev Log: Use Channels to transfer data if possible. See IMAP-231
Removed: james/imap/trunk/store/src/main/java/org/apache/james/mailbox/store/streaming/InputStreamFullContent.java Modified: james/imap/trunk/store/src/main/java/org/apache/james/mailbox/store/streaming/InputStreamContent.java Modified: james/imap/trunk/store/src/main/java/org/apache/james/mailbox/store/streaming/InputStreamContent.java URL: http://svn.apache.org/viewvc/james/imap/trunk/store/src/main/java/org/apache/james/mailbox/store/streaming/InputStreamContent.java?rev=1036569&r1=1036568&r2=1036569&view=diff ============================================================================== --- james/imap/trunk/store/src/main/java/org/apache/james/mailbox/store/streaming/InputStreamContent.java (original) +++ james/imap/trunk/store/src/main/java/org/apache/james/mailbox/store/streaming/InputStreamContent.java Thu Nov 18 18:35:45 2010 @@ -18,9 +18,11 @@ ****************************************************************/ package org.apache.james.mailbox.store.streaming; +import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; +import java.nio.channels.FileChannel; import java.nio.channels.WritableByteChannel; import org.apache.james.mailbox.Content; @@ -72,15 +74,24 @@ public final class InputStreamContent im in = m.getBodyContent(); break; } - // read all the content of the underlying InputStream in 16384 byte chunks, wrap them - // in a ByteBuffer and finally write the Buffer to the channel - byte[] buf = new byte[16384]; - int i = 0; - while ((i = in.read(buf)) != -1) { - ByteBuffer buffer = ByteBuffer.wrap(buf); - // set the limit of the buffer to the returned bytes + + if (in instanceof FileInputStream) { + FileChannel fileChannel = ((FileInputStream)in).getChannel(); + fileChannel.transferTo(0, fileChannel.size(), channel); + fileChannel.close(); + } else { + int i = 0; + + // read all the content of the underlying InputStream in 16384 byte chunks, wrap them + // in a ByteBuffer and finally write the Buffer to the channel + byte[] buf = new byte[16384]; + while ((i = in.read(buf)) != -1) { + + ByteBuffer buffer = ByteBuffer.wrap(buf); + // set the limit of the buffer to the returned bytes buffer.limit(i); channel.write(buffer); + } } } finally { if(in != null) { --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org