`
zhang_xzhi_xjtu
  • 浏览: 526989 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

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());
        }
    }
0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics