inputsteamex.java

来自「fiupload文件上传」· Java 代码 · 共 54 行

JAVA
54
字号
package com.cnblogs.zxub.upload;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author zxub 2006-7-14 下午05:28:36
 */
public class InputSteamEx extends InputStream
{

    private InputStream input = null;
    private StreamReportImpl streamReport = null;

    public InputSteamEx(InputStream input, StreamReportImpl report)
    {
        this.input = input;
        this.streamReport = report;
    }

    public int read() throws IOException
    {
        byte b[] = new byte[1];
        int readNext = -1;
        int readByte = -1;
        if (input != null) readNext = input.read(b);
        if (readNext != -1)
        {
            readByte = b[0];
            streamReport.report(1L);
        }
        else
        {
            streamReport.report(-1L);
        }
        return readByte;
    }

    public int read(byte b[], int off, int len) throws IOException
    {
        int readSize = -1;
        if (input != null) readSize = input.read(b, off, len);
        streamReport.report(readSize);
        return readSize;
    }

    public void close() throws IOException
    {
        super.close();
        if (input != null) input.close();
    }

}

⌨️ 快捷键说明

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