httpresponse.java

来自「一个简单的visio程序。」· Java 代码 · 共 809 行 · 第 1/2 页

JAVA
809
字号

    public void setDateHeader(String s, long l)
    {
        headers.putDateHeader(s, l);
    }

    public void setDateHeader(String s)
    {
        headers.putDateHeader(s);
    }

    public boolean containsHeader(String s)
    {
        return headers.containsHeader(s);
    }

    public MimeHeaders getHeaders()
    {
        return headers;
    }

    protected String reason(int i)
    {
        switch(i)
        {
        case 101: /* 'e' */
            return "Switching Protocols";

        case 100: /* 'd' */
            return "Continue";

        case 200:
            return "OK";

        case 201:
            return "Created";

        case 202:
            return "Accepted";

        case 203:
            return "Non Authoritative Information";

        case 204:
            return "No Content";

        case 205:
            return "Reset Content";

        case 206:
            return "Partial Content";

        case 300:
            return "Multiple Choices";

        case 301:
            return "Moved Permanently";

        case 302:
            return "Moved Temporarily";

        case 303:
            return "See Other";

        case 304:
            return "Not Modified";

        case 305:
            return "Use Proxy";

        case 400:
            return "Bad Request";

        case 401:
            return "Unauthorized";

        case 402:
            return "Payment Required";

        case 403:
            return "Forbidden";

        case 404:
            return "Not Found";

        case 405:
            return "Method Not Allowed";

        case 406:
            return "Not Acceptable";

        case 407:
            return "Proxy Authentication Required";

        case 408:
            return "Request Timeout";

        case 409:
            return "Conflict";

        case 410:
            return "Gone";

        case 411:
            return "Length Required";

        case 412:
            return "Precondition Failed";

        case 413:
            return "Request Entity Too Large";

        case 414:
            return "Request URI Too Long";

        case 415:
            return "Unsuppored Media Type";

        case 500:
            return "Internal Server Error";

        case 501:
            return "Not Implemented";

        case 502:
            return "Bad Gateway";

        case 503:
            return "Service Unavailable";

        case 504:
            return "Gateway Timeout";

        case 505:
            return "HTTP Version Not Supported";

        }
        return "Unknown";
    }

    public void sendError(int i, String s)
        throws IOException
    {
        keepAlive = false;
        HttpOutputStream httpoutputstream = out;
        if(!httpoutputstream.isCommitted())
        {
            String s1 = headers.getHeader("Server");
            String s2 = headers.getHeader("WWW-Authenticate");
            headers.clear();
            httpoutputstream.next();
            httpoutputstream.setObserver(this);
            httpoutputstream.setIOException(null);
            setStatus(i);
            if(s1 != null)
                setHeader("Server", s1);
            if(s2 != null)
                setHeader("WWW-Authenticate", s2);
            mimeType = null;
            setContentType("text/html");
            String s3 = i + " " + reason;
            int j = s3.length() * 2 + 19 + 15 + 2 + 4 + 11 + 2 + 14 + 2;
            j += s != null ? s.length() + 3 + 2 : 0;
            setContentLength(j);
            httpoutputstream.print("<html><head><title>");
            httpoutputstream.print(s3);
            httpoutputstream.println("</title></head>");
            httpoutputstream.print("<h1>");
            httpoutputstream.print(s3);
            httpoutputstream.println("</h1><body>");
            if(s != null)
            {
                httpoutputstream.print(s);
                httpoutputstream.println("<p>");
            }
            httpoutputstream.println("</body></html>");
            httpoutputstream.flush();
            httpoutputstream.finish();
        }
    }

    public void sendError(int i)
        throws IOException
    {
        sendError(i, null);
    }

    public void sendRedirect(String s)
        throws IOException
    {
        HttpOutputStream httpoutputstream = out;
        if(httpoutputstream.getTotal() == 0)
        {
            setStatus(302);
            mimeType = null;
            setContentType("text/html");
            setHeader("Location", s);
            setContentLength(110 + s.length() + 16 + 7);
            httpoutputstream.println("<head><title>Document moved</title></head>");
            httpoutputstream.println("<body><h1>Document moved</h1>");
            httpoutputstream.print("This document has moved <a href=\"");
            httpoutputstream.print(s);
            httpoutputstream.println("\">here</a>.<p>");
            httpoutputstream.println("</body>");
            httpoutputstream.finish();
        }
    }

    public void update(Observable observable, Object obj)
    {
        HttpOutputStream httpoutputstream;
        try
        {
            httpoutputstream = (HttpOutputStream)obj;
        }
        catch(ClassCastException ex)
        {
            throw new InternalError("update called with invalid argument type");
        }
        try
        {
            if(!headersWritten)
            {
                writeHeaders();
                return;
            }
        }
        catch(IOException ioexception)
        {
            httpoutputstream.setIOException(ioexception);
        }
    }

    public void setHttpSession(HttpSession httpsession)
    {
        session = (HttpSessionImpl)httpsession;
        if(session != null && session.isNew() && session.isUsingCookies())
            addCookie(session.getCookie());
    }

    public String encodeUrl(String s)
    {
        return s;
    }

    public String encodeRedirectUrl(String s)
    {
        return s;
    }

    public Object clone()
    {
        try
        {
            return super.clone();
        }
        catch(CloneNotSupportedException ex)
        {
            throw new RuntimeException("Clone not supported on Cloneable");
        }
    }

    public void setRawOutputStream(OutputStream outputstream, boolean flag)
        throws IOException
    {
        if(flag)
        {
            out = new HttpOutputStream();
            out.setObserver(this);
        }
        out.init(outputstream, true);
    }

    public OutputStream getRawOutputStream()
    {
        return out.getRawOutputStream();
    }

    public void unsetContentLength()
    {
        contentLenSet = false;
        setKeepAlive(false);
        headers.removeHeader("Content-Length");
        out.unsetContentLength();
    }

    public void setHeadersWritten()
    {
        headersWritten = true;
    }

    protected void writeHeaders()
        throws IOException
    {
        headersWritten = true;
        bufHeader.reset();
        outHeader.next();
        outHeader.init(bufHeader);
        outHeader.print(protocol);
        outHeader.write(32);
        outHeader.print(status);
        outHeader.write(32);
        int i;
        if(keepAlive)
            if((i = out.getContentLength()) != -1)
            {
                if(!contentLenSet)
                    headers.putIntHeader("Content-Length", i);
                if(printKeepAlive)
                    headers.putHeader("Connection", "Keep-Alive");
            }
            else
            {
                keepAlive = false;
            }
        headers.putDateHeader("Date");
        outHeader.println(reason);
        headers.write(outHeader);
        outHeader.flush();
        byte abyte0[] = bufHeader.toByteArray();
        headerBytes = abyte0.length;
        out.setHeader(abyte0);
    }
    public java.lang.String encodeURL(java.lang.String url) {
      return null;
    }
    protected int status;
    protected String reason;
    protected String protocol;
    protected final MimeHeaders headers = new MimeHeaders();
    protected HttpOutputStream out;
    protected HttpOutputStream outHeader;
    protected ByteArrayOutputStream bufHeader;
    protected ServletConnection con;
    protected int headerBytes;
    protected boolean keepAlive;
    protected boolean printKeepAlive;
    protected boolean contentLenSet;
    protected HttpSessionImpl session;
    private boolean headersWritten;
    private String mimeType;
    private PrintWriter writer;
    private String charEncoding;
    private boolean gotWriter;
    private boolean gotOutputStream;
    private static final String tspecials = "()<>@,;:\\\"/[]?={} \t";
	

	public void addDateHeader(java.lang.String name,long date)
	{
		;
	}

	public void addHeader(java.lang.String name,java.lang.String value)
	{
		;
	}

	public void addIntHeader(java.lang.String name,int value)
	{
		;
	}

	public void flushBuffer() throws java.io.IOException
	{
		;
	}

	public int getBufferSize()
	{
		return 1024000;
	}

	public void setLocale(java.util.Locale loc)
	{
		;
	}

	public java.util.Locale getLocale()
	{
		return null;
	}

	public void resetBuffer()
	{
		;
	}

	public void setBufferSize(int size)
	{
		;
	}

	public boolean isCommitted()
	{
		return true;
	}

	public java.lang.String encodeRedirectURL(java.lang.String url)
	{
		return null;
	}
}

⌨️ 快捷键说明

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