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

📄 httprequestline.java

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

package servlet.http;

import java.io.*;
import java.util.Hashtable;
import javax.servlet.ServletInputStream;
import servlet.util.Ascii;

// Referenced classes of package servlet.http:
//            MessageBytes

class HttpRequestLine extends Ascii
{

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

    public HttpRequestLine()
    {
        this(128);
    }

    public void reset()
    {
        line.reset();
        method.reset();
        uri.reset();
        path.reset();
        query.reset();
        protocol.reset();
        params = null;
        proxy = false;
    }

    public boolean parse(ServletInputStream servletinputstream)
        throws IOException, IllegalArgumentException
    {
        int i = readLine(servletinputstream);
        if(i == -1)
            return false;
        if(buf == null)
            buf = new byte[size];
        parse(buf, 0, i - 1);
        params = null;
        return true;
    }

    private int readLine(ServletInputStream servletinputstream)
        throws IOException, IllegalArgumentException
    {
        int i = 0;
        byte abyte0[] = buf;
        do
        {
            do
            {
                int j = servletinputstream.readLine(abyte0, i, abyte0.length - i);
                if(j == -1)
                    return -1;
                i += j;
                if(abyte0[i - 1] == 10)
                {
                    if(i > 1 && abyte0[i - 2] == 13)
                        abyte0[--i - 1] = 10;
                    return i;
                }
            }
            while(i != abyte0.length);
            if(i == 32768)
                throw new IllegalArgumentException("request line too long");
            int k = Math.min(abyte0.length * 2, 32768);
            buf = new byte[k];
            System.arraycopy(abyte0, 0, buf, 0, abyte0.length);
            abyte0 = buf;
        }
        while(true);
    }

    protected void parse(byte abyte0[], int i, int j)
        throws IllegalArgumentException
    {
        line.setBytes(abyte0, i, j);
        byte byte0 = abyte0[i++];
        if(!Ascii.isAlpha(byte0))
            throw new IllegalArgumentException("invalid request line");
        while(Ascii.isAlpha(byte0 = abyte0[i++])) ;
        method.setBytes(abyte0, 0, i - 1);
        if(byte0 != 32)
            throw new IllegalArgumentException("invalid request line");
        while((byte0 = abyte0[i++]) == 32) ;
        int k = i - 1;
        for(; byte0 != 63 && !Ascii.isWhite(byte0); byte0 = abyte0[i++])
            if(byte0 == 58)
                proxy = true;

        path.setBytes(abyte0, k, i - k - 1);
        if(byte0 == 63)
        {
            int i1 = i;
            while(!Ascii.isWhite(byte0 = abyte0[i++])) ;
            query.setBytes(abyte0, i1, i - i1 - 1);
        }
        else
        {
            query.reset();
        }
        uri.setBytes(abyte0, k, i - k - 1);
        for(; byte0 == 32; byte0 = abyte0[i++]);
        if(byte0 != 10)
        {
            int l = i - 1;
            byte byte1;
            while(!Ascii.isWhite(byte1 = abyte0[i++])) ;
            protocol.setBytes(abyte0, l, i - l - 1);
            return;
        }
        else
        {
            protocol.setBytes(HTTP_09_BYTES, 0, HTTP_09_BYTES.length);
            return;
        }
    }

    public MessageBytes getMethod()
    {
        return method;
    }

    public MessageBytes getProtocol()
    {
        return protocol;
    }

    public MessageBytes getQueryString()
    {
        return query;
    }

    public MessageBytes getURI()
    {
        return uri;
    }

    public MessageBytes getRequestPath()
    {
        return path;
    }

    public MessageBytes getRequestLine()
    {
        return line;
    }

    public boolean isFullRequest()
    {
        return protocol.isSet() && protocol.getBytes() != HTTP_09_BYTES;
    }

    public boolean isProxyRequest()
    {
        return proxy;
    }

    public String toString()
    {
        return line.toString();
    }

    public void write(OutputStream outputstream)
        throws IOException
    {
        line.write(outputstream);
    }

    public void dump(PrintStream printstream)
    {
        printstream.println("line   = \"" + line + '"');
        printstream.println("method = \"" + method + '"');
        printstream.println("path   = \"" + path + '"');
        printstream.println("uri    = \"" + uri + '"');
        printstream.println("query  = \"" + query + '"');
        printstream.println("protocol = \"" + protocol + '"');
    }

    private static final byte HTTP_09_BYTES[] = {
        72, 84, 84, 80, 47, 48, 46, 57
    };
    protected static final int MAXLINE = 32768;
    protected byte buf[];
    protected int size;
    protected final MessageBytes line = new MessageBytes();
    protected final MessageBytes method = new MessageBytes();
    protected final MessageBytes uri = new MessageBytes();
    protected final MessageBytes path = new MessageBytes();
    protected final MessageBytes query = new MessageBytes();
    protected final MessageBytes protocol = new MessageBytes();
    protected Hashtable params;
    protected boolean proxy;

}

⌨️ 快捷键说明

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