首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 互联网 >

http core 4.2.2 StringEntity 的一个疑义

2013-01-23 
http core 4.2.2 StringEntity 的一个疑问代码在org.apache.http.entity.StringEntity中。版本4.2.2。感觉代

http core 4.2.2 StringEntity 的一个疑问
代码在org.apache.http.entity.StringEntity中。版本4.2.2。
感觉代码和注释不匹配。
同时,没有处理好contentType为null的情况。
4.2.3中无该问题。已经修复。

    /**     * Creates a StringEntity with the specified content and content type.     *     * @param string content to be used. Not {@code null}.     * @param contentType content type to be used. May be {@code null}, in which case the default     *   MIME type {@link ContentType#TEXT_PLAIN} is assumed.     *     * @throws IllegalArgumentException if the string parameter is null     *     * @since 4.2     */    public StringEntity(final String string, final ContentType contentType) {        super();        if (string == null) {            throw new IllegalArgumentException("Source string may not be null");        }        Charset charset = contentType != null ? contentType.getCharset() : null;        try {            this.content = string.getBytes(charset.name());        } catch (UnsupportedEncodingException ex) {            // should never happen            throw new UnsupportedCharsetException(charset.name());        }        if (contentType != null) {            setContentType(contentType.toString());        }    }

热点排行