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

📄 httpfields.java

📁 jetty SERVER連接資料庫用的軟體
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        return -1L;    }    /* -------------------------------------------------------------- */    /**     * Get a header as a date value. Returns the value of a date field, or -1 if not found. The case     * of the field name is ignored.     *      * @param name the case-insensitive field name     */    public long getDateField(String name)    {        Field field = getField(name);        if (field == null || field._revision != _revision) return -1;        if (field._numValue != -1) return field._numValue;        String val = valueParameters(BufferUtil.to8859_1_String(field._value), null);        if (val == null) return -1;                        for (int i = 0; i < __dateReceiveInit; i++)        {            if (_dateReceive[i] == null) _dateReceive[i] = (SimpleDateFormat) __dateReceive[i].clone();            try            {                Date date = (Date) _dateReceive[i].parseObject(val);                return field._numValue = date.getTime();            }            catch (java.lang.Exception e)            {            }        }        if (val.endsWith(" GMT"))        {            val = val.substring(0, val.length() - 4);            for (int i = 0; i < __dateReceiveInit; i++)            {                try                {                    Date date = (Date) _dateReceive[i].parseObject(val);                    return field._numValue = date.getTime();                }                catch (java.lang.Exception e)                {                }            }        }                // The standard formats did not work.  So we will lock the common format array        // and look at lazily creating the non-standard formats        synchronized (__dateReceive)        {            for (int i = __dateReceiveInit; i < _dateReceive.length; i++)            {                if (_dateReceive[i] == null)                 {                    if (__dateReceive[i]==null)                    {                        __dateReceive[i] = new SimpleDateFormat(__dateReceiveFmt[i], Locale.US);                        __dateReceive[i].setTimeZone(__GMT);                    }                    _dateReceive[i] = (SimpleDateFormat) __dateReceive[i].clone();                }                                try                {                    Date date = (Date) _dateReceive[i].parseObject(val);                    return field._numValue = date.getTime();                }                catch (java.lang.Exception e)                {                }            }            if (val.endsWith(" GMT"))            {                val = val.substring(0, val.length() - 4);                for (int i = 0; i < _dateReceive.length; i++)                {                    try                    {                        Date date = (Date) _dateReceive[i].parseObject(val);                        return field._numValue = date.getTime();                    }                    catch (java.lang.Exception e)                    {                    }                }            }        }                throw new IllegalArgumentException("Cannot convert date: " + val);    }    /* -------------------------------------------------------------- */    /**     * Sets the value of an long field.     *      * @param name the field name     * @param value the field long value     */    public void putLongField(Buffer name, long value)    {        Buffer v = BufferUtil.toBuffer(value);        put(name, v, value);    }    /* -------------------------------------------------------------- */    /**     * Sets the value of an long field.     *      * @param name the field name     * @param value the field long value     */    public void putLongField(String name, long value)    {        Buffer n = HttpHeaders.CACHE.lookup(name);        Buffer v = BufferUtil.toBuffer(value);        put(n, v, value);    }    /* -------------------------------------------------------------- */    /**     * Sets the value of an long field.     *      * @param name the field name     * @param value the field long value     */    public void addLongField(String name, long value)    {        Buffer n = HttpHeaders.CACHE.lookup(name);        Buffer v = BufferUtil.toBuffer(value);        add(n, v, value);    }    /* -------------------------------------------------------------- */    /**     * Sets the value of an long field.     *      * @param name the field name     * @param value the field long value     */    public void addLongField(Buffer name, long value)    {        Buffer v = BufferUtil.toBuffer(value);        add(name, v, value);    }    /* -------------------------------------------------------------- */    /**     * Sets the value of a date field.     *      * @param name the field name     * @param date the field date value     */    public void putDateField(Buffer name, long date)    {        if (_dateBuffer == null)        {            _dateBuffer = new StringBuffer(32);            _calendar = new GregorianCalendar(__GMT);        }        _dateBuffer.setLength(0);        _calendar.setTimeInMillis(date);        formatDate(_dateBuffer, _calendar, false);        Buffer v = new ByteArrayBuffer(_dateBuffer.toString());        put(name, v, date);    }    /* -------------------------------------------------------------- */    /**     * Sets the value of a date field.     *      * @param name the field name     * @param date the field date value     */    public void putDateField(String name, long date)    {        Buffer n = HttpHeaders.CACHE.lookup(name);        putDateField(n,date);    }    /* -------------------------------------------------------------- */    /**     * Sets the value of a date field.     *      * @param name the field name     * @param date the field date value     */    public void addDateField(String name, long date)    {        if (_dateBuffer == null)        {            _dateBuffer = new StringBuffer(32);            _calendar = new GregorianCalendar(__GMT);        }        _dateBuffer.setLength(0);        _calendar.setTimeInMillis(date);        formatDate(_dateBuffer, _calendar, false);        Buffer n = HttpHeaders.CACHE.lookup(name);        Buffer v = new ByteArrayBuffer(_dateBuffer.toString());        add(n, v, date);    }    /* ------------------------------------------------------------ */    /**     * Format a set cookie value     *      * @param cookie The cookie.     * @param cookie2 If true, use the alternate cookie 2 header     */    public void addSetCookie(Cookie cookie)    {        String name = cookie.getName();        String value = cookie.getValue();        int version = cookie.getVersion();        // Check arguments        if (name == null || name.length() == 0) throw new IllegalArgumentException("Bad cookie name");        // Format value and params        StringBuffer buf = new StringBuffer(128);        String name_value_params = null;        synchronized (buf)        {            QuotedStringTokenizer.quoteIfNeeded(buf, name);            buf.append('=');            if (value != null && value.length() > 0)                QuotedStringTokenizer.quoteIfNeeded(buf, value);            if (version > 0)            {                buf.append(";Version=");                buf.append(version);                String comment = cookie.getComment();                if (comment != null && comment.length() > 0)                {                    buf.append(";Comment=");                    QuotedStringTokenizer.quoteIfNeeded(buf, comment);                }            }            String path = cookie.getPath();            if (path != null && path.length() > 0)            {                buf.append(";Path=");                buf.append(URIUtil.encodePath(path));            }            String domain = cookie.getDomain();            if (domain != null && domain.length() > 0)            {                buf.append(";Domain=");                buf.append(domain.toLowerCase());// lowercase for IE            }            long maxAge = cookie.getMaxAge();            if (maxAge >= 0)            {                if (version == 0)                {                    buf.append(";Expires=");                    if (maxAge == 0)                        buf.append(__01Jan1970);                    else                        formatDate(buf, System.currentTimeMillis() + 1000L * maxAge, true);                }                else                {                    buf.append(";Max-Age=");                    buf.append(maxAge);                }            }            else if (version > 0)            {                buf.append(";Discard");            }            if (cookie.getSecure())            {                buf.append(";Secure");            }            if (cookie instanceof HttpOnlyCookie)                buf.append(";HttpOnly");            // TODO - straight to Buffer?            name_value_params = buf.toString();        }        put(HttpHeaders.EXPIRES_BUFFER, __01Jan1970_BUFFER);        add(HttpHeaders.SET_COOKIE_BUFFER, new ByteArrayBuffer(name_value_params));    }    /* -------------------------------------------------------------- */    public void put(Buffer buffer) throws IOException    {        for (int i = 0; i < _fields.size(); i++)        {            Field field = (Field) _fields.get(i);            if (field != null && field._revision == _revision) field.put(buffer);        }        BufferUtil.putCRLF(buffer);    }    /* -------------------------------------------------------------- */    public String toString()    {        try        {            ByteArrayBuffer buffer = new ByteArrayBuffer(4096);            put(buffer);            return BufferUtil.to8859_1_String(buffer);        }        catch (Exception e)        {            e.printStackTrace();        }        return null;    }    /* ------------------------------------------------------------ */    /**     * Clear the header.     */    public void clear()    {        _revision++;        if (_revision > 1000000)        {            _revision = 0;            for (int i = _fields.size(); i-- > 0;)            {                Field field = (Field) _fields.get(i);                if (field != null) field.clear();            }        }    }    /* ------------------------------------------------------------ */    /**     * Destroy the header. Help the garbage collector by null everything that we can.     */    public void destroy()    {        if (_fields != null)        {            for (int i = _fields.size(); i-- > 0;)            {                Field field = (Field) _fields.get(i);                if (field != null) field.destroy();            }        }        _fields = null;        _dateBuffer = null;        _calendar = null;        _dateReceive = null;    }    /* ------------------------------------------------------------ */    /**     * Add fields from another HttpFields instance. Single valued fields are replaced, while all     * others are added.     *      * @param fields     */    public void add(HttpFields fields)    {

⌨️ 快捷键说明

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