下面列出了怎么用org.apache.http.ContentTooLongException的API类实例代码及写法,或者点击链接到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
public InputStream getContent() throws IOException {
if (this.getContentLength() < 0) { throw new ContentTooLongException("Content length is unknown"); }
// else if (this.contentLength > 25 * 1024) {
// throw new ContentTooLongException("Content length is too long: " + this.contentLength);
// }
final ByteArrayOutputStream outstream = new ByteArrayOutputStream();
writeTo(outstream);
outstream.flush();
return new ByteArrayInputStream(outstream.toByteArray());
}
@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));
}