下面列出了org.apache.http.ContentTooLongException#org.apache.http.nio.entity.ContentBufferEntity 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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);
}
}