本文主要是介绍Jetty Client IllegalArgumentException: Buffering capacity 2097152 exceeded,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
使用Jetty Http Client 接收较大数据时发生异常
Request request = client.POST(api_url)
.timeout(TIMEOUT, TimeUnit.SECONDS)
.content(new BytesContentProvider(imageData), "image/*");ContentResponse resp = request.send();
if(resp.getStatus()==200){
request.getContent();
}
send 函数抛出如下异常:
java.lang.IllegalArgumentException: Buffering capacity 2097152 exceeded
后分析发现,再接收较大数据时,超出内部buffer,进而产生异常,解决方法,使用InputStreamResponseListener 来读取数据。
Request request = client.POST(api_url)
.timeout(TIMEOUT, TimeUnit.SECONDS)
.content(new BytesContentProvider(imageData), "image/*");InputStreamResponseListener listener = new InputStreamResponseListener();
request.send(listener);
HttpResponse resp = (HttpResponse) listener.get(12,TimeUnit.SECONDS);if(resp.getStatus()==200){
InputStream input = listener.getInputStream()
// read data from input.
}
这篇关于Jetty Client IllegalArgumentException: Buffering capacity 2097152 exceeded的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!