类org.apache.http.nio.entity.ContentBufferEntity源码实例Demo

下面列出了怎么用org.apache.http.nio.entity.ContentBufferEntity的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: fc-java-sdk   文件: AbstractResponseConsumer.java
protected void onEntityEnclosed(HttpEntity entity, ContentType contentType) throws IOException {
    long len = entity.getContentLength();
    if (len > 2147483647L) {
        throw new ContentTooLongException("Entity content is too long: " + len);
    } else {
        if (len < 0L) {
            len = 4096L;
        }

        this.buf = new SimpleInputBuffer((int)len, new HeapByteBufferAllocator());
        this.httpResponse.setEntity(new ContentBufferEntity(entity, this.buf));
    }
}
 
@Override
protected void onEntityEnclosed(final HttpEntity entity,
        final ContentType contentType) throws IOException {
    long len = entity.getContentLength();
    if (len > Integer.MAX_VALUE) {
        throw new ContentTooLongException("Entity content is too long: "
                + len);
    }
    if (len < 0) {
        len = BUFFER_SIZE;
    }
    this.buf = new SimpleInputBuffer((int) len,
            new HeapByteBufferAllocator());
    this.httpResponse.setEntity(new ContentBufferEntity(entity, this.buf));
}
 
/**
 * Writes content of given {@code org.apache.http.HttpEntity} to pooled buffer
 *
 * @param entity response entity
 * @param contentType content type of given entity
 * @throws IOException
 */
@Override
protected void onEntityEnclosed(
        final HttpEntity entity, final ContentType contentType) throws IOException {

    // TODO: add entity.getContentLength() to metrics

    if (buffer == null) {

        buffer = getPooled();

        // SimpleInputBuffer passed just to satisfy the constructor
        ContentBufferEntity bufferedEntity = new ContentBufferEntity(entity, buffer.getSource());

        // override the content here (see ContentBufferEntity constructor)
        bufferedEntity.setContent(new ItemSourceContentInputStream(buffer));

        this.response.setEntity(bufferedEntity);

    }

}
 
 类所在包
 同包方法