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

📄 httpinputstream.java

📁 一个简单的visio程序。
💻 JAVA
字号:

package servlet.http;

import java.io.IOException;
import java.io.InputStream;
import javax.servlet.ServletInputStream;

public class HttpInputStream extends ServletInputStream
{

    public HttpInputStream(int i)
    {
        buf = new byte[i];
    }

    public HttpInputStream()
    {
        this(512);
    }

    public void init(InputStream inputstream)
        throws IOException
    {
        in = inputstream;
    }

    public void next()
    {
        length = -1;
        limit = 0x7fffffff;
        total = 0;
        count = 0;
        pos = 0;
    }

    public void finish()
        throws IOException
    {
        if(length != -1)
        {
            int j;
            for(int i = limit - total; i > 0; i -= j)
            {
                j = (int)skip(i);
                if(j == 0)
                    throw new IOException("invalid content length");
            }

        }
    }

    public void resets()
    {
        in = null;
    }

    public int getTotal()
    {
        return total;
    }

    public void setContentLength(int i)
    {
        if(i < 0)
            throw new IllegalArgumentException("invalid content length");
        length = i;
        if(0x7fffffff - total > i)
            limit = total + i;
    }

    public int getContentLength()
    {
        return length;
    }

    public int read()
        throws IOException
    {
        if(total >= limit)
            return -1;
        if(pos >= count)
        {
            fill();
            if(pos >= count)
                return -1;
        }
        total++;
        return buf[pos++] & 0xff;
    }

    public int read(byte abyte0[], int i, int j)
        throws IOException
    {
        if(total >= limit)
            return -1;
        int k = count - pos;
        if(k <= 0)
        {
            fill();
            k = count - pos;
            if(k <= 0)
                return -1;
        }
        if(k < j)
            j = k;
        System.arraycopy(buf, pos, abyte0, i, j);
        pos += j;
        total += j;
        return j;
    }

    public int readLine(byte abyte0[], int i, int j)
        throws IOException
    {
        if(total >= limit)
            return -1;
        int k1 = 0;
        k1 = j;
        int k = count - pos;
        if(k <= 0)
        {
            fill();
            k = count - pos;
            if(k <= 0)
                return -1;
        }
        int i1;
        if(k < j)
            i1 = k;
        else
            i1 = j;
        int l1 = copyLine(buf, pos, abyte0, i, i1);
        pos += l1;
        total += l1;
        k1 -= l1;
        int j2 = l1;
        if(j2 == 0)
            return -1;
        int i2;
        for(; k1 > 0 && abyte0[(i + j2) - 1] != 10; j2 += i2)
        {
            fill();
            int l = count - pos;
            if(l <= 0)
                return j2;
            int j1;
            if(l < k1)
                j1 = l;
            else
                j1 = k1;
            i2 = copyLine(buf, pos, abyte0, i + j2, j1);
            pos += i2;
            total += i2;
            k1 -= i2;
        }

        return j2;
    }

    private static int copyLine(byte abyte0[], int i, byte abyte1[], int j, int k)
    {
        int l;
        for(l = i; k-- > 0 && abyte0[l++] != 10;);
        System.arraycopy(abyte0, i, abyte1, j, l - i);
        return l - i;
    }

    public long skip(long l)
        throws IOException
    {
        if(total >= limit)
            return 0L;
        for(long l1 = l; l1 > 0L;)
        {
            int i = count - pos;
            if(i <= 0)
            {
                fill();
                i = count - pos;
                if(i <= 0)
                    return l - l1;
            }
            if(l1 < i)
                i = (int)l1;
            l1 -= i;
            pos += i;
            total += i;
        }

        return l;
    }

    public int available()
        throws IOException
    {
        return Math.min((count - pos) + in.available(), limit - total);
    }

    public void close()
        throws IOException
    {
        finish();
    }

    protected void fill()
        throws IOException
    {
        int i = Math.min(buf.length, limit - total);
        if(i > 0)
        {
            i = in.read(buf, 0, i);
            if(i > 0)
            {
                pos = 0;
                count = i;
            }
        }
    }

    protected InputStream in;
    protected byte buf[];
    protected int count;
    protected int pos;
    protected int total;
    protected int limit;
    protected int length;
}

⌨️ 快捷键说明

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