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

📄 httpfields.java

📁 jetty SERVER連接資料庫用的軟體
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
     * Get multi headers     *      * @return Enumeration of the values, or null if no such header.     * @param name the case-insensitive field name     */    public Enumeration getValues(String name)    {        final Field field = getField(name);        if (field == null)             return null;        final int revision=_revision;        return new Enumeration()        {            Field f = field;            public boolean hasMoreElements()            {                while (f != null && f._revision != revision)                    f = f._next;                return f != null;            }            public Object nextElement() throws NoSuchElementException            {                if (f == null) throw new NoSuchElementException();                Field n = f;                do                    f = f._next;                while (f != null && f._revision != revision);                return n.getValue();            }        };    }    /* -------------------------------------------------------------- */    /**     * Get multi headers     *      * @return Enumeration of the value Strings, or null if no such header.     * @param name the case-insensitive field name     */    public Enumeration getValues(Buffer name)    {        final Field field = getField(name);        if (field == null)             return null;        final int revision=_revision;        return new Enumeration()        {            Field f = field;            public boolean hasMoreElements()            {                while (f != null && f._revision != revision)                    f = f._next;                return f != null;            }            public Object nextElement() throws NoSuchElementException            {                if (f == null) throw new NoSuchElementException();                Field n = f;                f = f._next;                while (f != null && f._revision != revision)                    f = f._next;                return n.getValue();            }        };    }    /* -------------------------------------------------------------- */    /**     * Get multi field values with separator. The multiple values can be represented as separate     * headers of the same name, or by a single header using the separator(s), or a combination of     * both. Separators may be quoted.     *      * @param name the case-insensitive field name     * @param separators String of separators.     * @return Enumeration of the values, or null if no such header.     */    public Enumeration getValues(String name, final String separators)    {        final Enumeration e = getValues(name);        if (e == null)             return null;        return new Enumeration()        {            QuotedStringTokenizer tok = null;            public boolean hasMoreElements()            {                if (tok != null && tok.hasMoreElements()) return true;                while (e.hasMoreElements())                {                    String value = (String) e.nextElement();                    tok = new QuotedStringTokenizer(value, separators, false, false);                    if (tok.hasMoreElements()) return true;                }                tok = null;                return false;            }            public Object nextElement() throws NoSuchElementException            {                if (!hasMoreElements()) throw new NoSuchElementException();                String next = (String) tok.nextElement();                if (next != null) next = next.trim();                return next;            }        };    }    /* -------------------------------------------------------------- */    /**     * Set a field.     *      * @param name the name of the field     * @param value the value of the field. If null the field is cleared.     */    public void put(String name, String value)    {        Buffer n = HttpHeaders.CACHE.lookup(name);        Buffer v = null;        if (value != null)            v = HttpHeaderValues.CACHE.lookup(value);        put(n, v, -1);    }    /* -------------------------------------------------------------- */    /**     * Set a field.     *      * @param name the name of the field     * @param value the value of the field. If null the field is cleared.     */    public void put(Buffer name, String value)    {        Buffer v = HttpHeaderValues.CACHE.lookup(value);        put(name, v, -1);    }    /* -------------------------------------------------------------- */    /**     * Set a field.     *      * @param name the name of the field     * @param value the value of the field. If null the field is cleared.     */    public void put(Buffer name, Buffer value)    {        put(name, value, -1);    }    /* -------------------------------------------------------------- */    /**     * Set a field.     *      * @param name the name of the field     * @param value the value of the field. If null the field is cleared.     * @param numValue the numeric value of the field (must match value) or -1     */    public void put(Buffer name, Buffer value, long numValue)    {        if (value == null)        {            remove(name);            return;        }        if (!(name instanceof BufferCache.CachedBuffer)) name = HttpHeaders.CACHE.lookup(name);        Field field = (Field) _bufferMap.get(name);        // Look for value to replace.        if (field != null)        {            field.reset(value, numValue, _revision);            field = field._next;            while (field != null)            {                field.clear();                field = field._next;            }            return;        }        else        {            // new value;            field = new Field(name, value, numValue, _revision);            _fields.add(field);            _bufferMap.put(field.getNameBuffer(), field);        }    }    /* -------------------------------------------------------------- */    /**     * Set a field.     *      * @param name the name of the field     * @param list the List value of the field. If null the field is cleared.     */    public void put(String name, List list)    {        if (list == null || list.size() == 0)        {            remove(name);            return;        }        Buffer n = HttpHeaders.CACHE.lookup(name);        Object v = list.get(0);        if (v != null)            put(n, HttpHeaderValues.CACHE.lookup(v.toString()));        else            remove(n);        if (list.size() > 1)        {            java.util.Iterator iter = list.iterator();            iter.next();            while (iter.hasNext())            {                v = iter.next();                if (v != null) put(n, HttpHeaderValues.CACHE.lookup(v.toString()));            }        }    }    /* -------------------------------------------------------------- */    /**     * Add to or set a field. If the field is allowed to have multiple values, add will add multiple     * headers of the same name.     *      * @param name the name of the field     * @param value the value of the field.     * @exception IllegalArgumentException If the name is a single valued field and already has a     *                value.     */    public void add(String name, String value) throws IllegalArgumentException    {        Buffer n = HttpHeaders.CACHE.lookup(name);        Buffer v = HttpHeaderValues.CACHE.lookup(value);        add(n, v, -1);    }    /* -------------------------------------------------------------- */    /**     * Add to or set a field. If the field is allowed to have multiple values, add will add multiple     * headers of the same name.     *      * @param name the name of the field     * @param value the value of the field.     * @exception IllegalArgumentException If the name is a single valued field and already has a     *                value.     */    public void add(Buffer name, Buffer value) throws IllegalArgumentException    {        add(name, value, -1);    }    /* -------------------------------------------------------------- */    /**     * Add to or set a field. If the field is allowed to have multiple values, add will add multiple     * headers of the same name.     *      * @param name the name of the field     * @param value the value of the field.     * @exception IllegalArgumentException If the name is a single valued field and already has a     *                value.     */    private void add(Buffer name, Buffer value, long numValue) throws IllegalArgumentException    {        if (value == null) throw new IllegalArgumentException("null value");        if (!(name instanceof BufferCache.CachedBuffer)) name = HttpHeaders.CACHE.lookup(name);                Field field = (Field) _bufferMap.get(name);        Field last = null;        if (field != null)        {            while (field != null && field._revision == _revision)            {                last = field;                field = field._next;            }        }        if (field != null)            field.reset(value, numValue, _revision);        else        {            // create the field            field = new Field(name, value, numValue, _revision);            // look for chain to add too            if (last != null)            {                field._prev = last;                last._next = field;            }            else                _bufferMap.put(field.getNameBuffer(), field);            _fields.add(field);        }    }    /* ------------------------------------------------------------ */    /**     * Remove a field.     *      * @param name     */    public void remove(String name)    {        remove(HttpHeaders.CACHE.lookup(name));    }    /* ------------------------------------------------------------ */    /**     * Remove a field.     *      * @param name     */    public void remove(Buffer name)    {        Field field = (Field) _bufferMap.get(name);        if (field != null)        {            while (field != null)            {                field.clear();                field = field._next;            }        }    }    /* -------------------------------------------------------------- */    /**     * Get a header as an long value. Returns the value of an integer field or -1 if not found. The     * case of the field name is ignored.     *      * @param name the case-insensitive field name     * @exception NumberFormatException If bad long found     */    public long getLongField(String name) throws NumberFormatException    {        Field field = getField(name);        if (field != null && field._revision == _revision) return field.getLongValue();        return -1L;    }    /* -------------------------------------------------------------- */    /**     * Get a header as an long value. Returns the value of an integer field or -1 if not found. The     * case of the field name is ignored.     *      * @param name the case-insensitive field name     * @exception NumberFormatException If bad long found     */    public long getLongField(Buffer name) throws NumberFormatException    {        Field field = getField(name);        if (field != null && field._revision == _revision) return field.getLongValue();

⌨️ 快捷键说明

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