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 98034ed4ea6fc3224f84bdac856adab708f4aa3d Author: Benoit Tellier <btell...@linagora.com> AuthorDate: Fri Nov 22 09:02:48 2019 +0700 JAMES-2110 Use IOUtils::copy in more places --- .../james/mailbox/maildir/mail/MaildirMessageMapper.java | 6 ++---- .../apache/james/imap/decode/ImapRequestLineReader.java | 13 ++++--------- .../imap/decode/main/OutputStreamImapResponseWriter.java | 15 +++------------ 3 files changed, 9 insertions(+), 25 deletions(-) diff --git a/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMessageMapper.java b/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMessageMapper.java index 6bbddaa..b9d29fb 100644 --- a/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMessageMapper.java +++ b/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMessageMapper.java @@ -36,6 +36,7 @@ import javax.mail.Flags; import javax.mail.Flags.Flag; import org.apache.commons.io.FileUtils; +import org.apache.commons.io.IOUtils; import org.apache.james.mailbox.MailboxSession; import org.apache.james.mailbox.MessageUid; import org.apache.james.mailbox.ModSeq; @@ -310,10 +311,7 @@ public class MaildirMessageMapper extends AbstractMessageMapper { try (FileOutputStream fos = new FileOutputStream(messageFile); InputStream input = message.getFullContent()) { byte[] b = new byte[BUF_SIZE]; - int len = 0; - while ((len = input.read(b)) != -1) { - fos.write(b, 0, len); - } + IOUtils.copy(input, fos, BUF_SIZE); } } catch (IOException ioe) { throw new MailboxException("Failure while save MailboxMessage " + message + " in Mailbox " + mailbox, ioe); diff --git a/protocols/imap/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java b/protocols/imap/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java index 9c86626..ab65ce3 100644 --- a/protocols/imap/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java +++ b/protocols/imap/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java @@ -34,6 +34,7 @@ import java.util.List; import javax.mail.Flags; +import org.apache.commons.io.IOUtils; import org.apache.james.imap.api.ImapConstants; import org.apache.james.imap.api.Tag; import org.apache.james.imap.api.display.HumanReadableText; @@ -370,16 +371,10 @@ public abstract class ImapRequestLineReader { } else { try (FastByteArrayOutputStream out = new FastByteArrayOutputStream(); InputStream in = consumeLiteral(false)) { - byte[] buf = new byte[0xFFFF]; - - for (int len; (len = in.read(buf)) != -1; ) { - out.write(buf, 0, len); - } - - final byte[] bytes = out.toByteArray(); - final ByteBuffer buffer = ByteBuffer.wrap(bytes); + IOUtils.copy(in, out, 0xFFFF); + byte[] bytes = out.toByteArray(); + ByteBuffer buffer = ByteBuffer.wrap(bytes); return decode(charset, buffer); - } catch (IOException e) { throw new DecodingException(HumanReadableText.BAD_IO_ENCODING, "Bad character encoding", e); } diff --git a/protocols/imap/src/main/java/org/apache/james/imap/decode/main/OutputStreamImapResponseWriter.java b/protocols/imap/src/main/java/org/apache/james/imap/decode/main/OutputStreamImapResponseWriter.java index 27539bd..271698f 100644 --- a/protocols/imap/src/main/java/org/apache/james/imap/decode/main/OutputStreamImapResponseWriter.java +++ b/protocols/imap/src/main/java/org/apache/james/imap/decode/main/OutputStreamImapResponseWriter.java @@ -23,6 +23,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import org.apache.commons.io.IOUtils; import org.apache.james.imap.encode.ImapResponseWriter; import org.apache.james.imap.message.response.Literal; @@ -32,28 +33,18 @@ import org.apache.james.imap.message.response.Literal; */ public class OutputStreamImapResponseWriter implements ImapResponseWriter { + public static final int BUFFER_SIZE = 1024; private final OutputStream output; public OutputStreamImapResponseWriter(OutputStream output) { this.output = output; } - public void flush() throws IOException { - output.flush(); - } - - - @Override public void write(Literal literal) throws IOException { try (InputStream in = literal.getInputStream()) { - - byte[] buffer = new byte[1024]; - for (int len; (len = in.read(buffer)) != -1; ) { - output.write(buffer, 0, len); - } + IOUtils.copy(in, output, BUFFER_SIZE); } - } @Override --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org