[ https://issues.apache.org/jira/browse/JAMES-2343?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16461853#comment-16461853 ]
ASF GitHub Bot commented on JAMES-2343: --------------------------------------- Github user chibenwa commented on a diff in the pull request: https://github.com/apache/james-project/pull/105#discussion_r185686252 --- Diff: server/container/core/src/main/java/org/apache/james/server/core/BufferedDeferredFileOutputStream.java --- @@ -0,0 +1,251 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.james.server.core; + +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; + +import org.apache.commons.io.IOUtils; +import org.apache.commons.io.output.ByteArrayOutputStream; +import org.apache.commons.io.output.DeferredFileOutputStream; +import org.apache.commons.io.output.ThresholdingOutputStream; + +/** + * An almost copy of {@link DeferredFileOutputStream} with buffered file stream. + */ +public class BufferedDeferredFileOutputStream extends ThresholdingOutputStream { + + /** + * The output stream to which data will be written prior to the theshold + * being reached. + */ + private ByteArrayOutputStream memoryOutputStream; + + + /** + * The output stream to which data will be written at any given time. This + * will always be one of <code>memoryOutputStream</code> or + * <code>diskOutputStream</code>. + */ + private OutputStream currentOutputStream; + + + /** + * The file to which output will be directed if the threshold is exceeded. + */ + private File outputFile; + + /** + * The temporary file prefix. + */ + private final String prefix; + + /** + * The temporary file suffix. + */ + private final String suffix; + + /** + * The directory to use for temporary files. + */ + private final File directory; + + + /** + * True when close() has been called successfully. + */ + private boolean closed = false; + + /** + * Constructs an instance of this class which will trigger an event at the + * specified threshold, and save data to a file beyond that point. + * + * @param threshold The number of bytes at which to trigger an event. + * @param outputFile The file to which data is saved beyond the threshold. + */ + public BufferedDeferredFileOutputStream(final int threshold, final File outputFile) { + this(threshold, outputFile, null, null, null); + } + + + /** + * Constructs an instance of this class which will trigger an event at the + * specified threshold, and save data to a temporary file beyond that point. + * + * @param threshold The number of bytes at which to trigger an event. + * @param prefix Prefix to use for the temporary file. + * @param suffix Suffix to use for the temporary file. + * @param directory Temporary file directory. + * + * @since 1.4 --- End diff -- This `@since` and all followings makes no sens in a James context. They should be removed. > Use buffered file output stream for MimeMessageInputStreamSource > ---------------------------------------------------------------- > > Key: JAMES-2343 > URL: https://issues.apache.org/jira/browse/JAMES-2343 > Project: James Server > Issue Type: Improvement > Components: James Core > Reporter: TzeKai Lee > Priority: Major > > Currently MimeMessageInputStreamSource use DeferredFileOutputStream from > commons-io which does _not_ buffer output stream when switched to > FileOutputStream. In my preliminary test, simply wrap FileOutputStream with > BufferedOutputStream could make a 50% performance improvement for mail larger > than deferring threshold (currently 100kb). -- This message was sent by Atlassian JIRA (v7.6.3#76005) --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org