⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 byteswrittenresetoutputstream.java

📁 java 开发的邮件服务器平台。支持以下协议。 协议可以修改为自己的专门标识
💻 JAVA
字号:
/*********************************************************************** * Copyright (c) 2000-2004 The Apache Software Foundation.             * * All rights reserved.                                                * * ------------------------------------------------------------------- * * Licensed 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.util.watchdog;import java.io.IOException;import java.io.OutputStream;/** * This will reset the Watchdog each time a certain amount of data has * been transferred.  This allows us to keep the timeout settings low, while * not timing out during large data transfers. */public class BytesWrittenResetOutputStream extends OutputStream {    /**     * The output stream wrapped by this method     */    OutputStream out = null;    /**     * The Watchdog to be reset every lengthReset bytes     */    private Watchdog watchdog;    /**     * The number of bytes that need to be written before the counter is reset.     */    int lengthReset = 0;    /**     * The number of bytes written since the counter was last reset     */    int writtenCounter = 0;    public BytesWrittenResetOutputStream(OutputStream out,                                         Watchdog watchdog,                                         int lengthReset) {        this.out = out;        this.watchdog = watchdog;        this.lengthReset = lengthReset;        writtenCounter = 0;    }    /**     * Write an array of bytes to the stream     *     * @param b the array of bytes to write to the stream     * @param off the index in the array where we start writing     * @param len the number of bytes of the array to write     *     * @throws IOException if an exception is encountered when writing     */    public void write(byte[] b, int off, int len) throws IOException {        out.write(b, off, len);        writtenCounter += len;        if (writtenCounter > lengthReset) {            writtenCounter = 0;            watchdog.reset();        }    }    /**     * Write a byte to the stream     *     * @param b the byte to write to the stream     *     * @throws IOException if an exception is encountered when writing     */    public void write(int b) throws IOException {        out.write(b);        writtenCounter++;        if (writtenCounter > lengthReset) {            writtenCounter = 0;            watchdog.reset();        }    }    /**     * Flush the stream     *     * @throws IOException if an exception is encountered when flushing     */    public void flush() throws IOException {        out.flush();    }    /**     * Close the stream     *     * @throws IOException if an exception is encountered when closing     */    public void close() throws IOException {        out.close();    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -