本文整理汇总了Java中org.apache.http.nio.util.HeapByteBufferAllocator类的典型用法代码示例。如果您正苦于以下问题:Java HeapByteBufferAllocator类的具体用法?Java HeapByteBufferAllocator怎么用?Java HeapByteBufferAllocator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HeapByteBufferAllocator类属于org.apache.http.nio.util包,在下文中一共展示了HeapByteBufferAllocator类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: onEntityEnclosed
import org.apache.http.nio.util.HeapByteBufferAllocator; //导入依赖的package包/类
@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));
}
开发者ID:aliyun,项目名称:aliyun-tablestore-java-sdk,代码行数:16,代码来源:OTSAsyncResponseConsumer.java
示例2: onEntityEnclosed
import org.apache.http.nio.util.HeapByteBufferAllocator; //导入依赖的package包/类
@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 = 4096;
}
this.buf = new SimpleInputBuffer((int) len, new HeapByteBufferAllocator());
this.response.setEntity(new ContentBufferEntity(entity, this.buf));
}
开发者ID:algorithmiaio,项目名称:algorithmia-java,代码行数:13,代码来源:HttpClientHelpers.java
示例3: buildAsyncClient
import org.apache.http.nio.util.HeapByteBufferAllocator; //导入依赖的package包/类
protected ExecCallbackAsyncREST<HttpResponse> buildAsyncClient(RESTPool pool) throws IOException {
SSLContext sslContext;
try {
sslContext = SSLContext.getDefault();
} catch (NoSuchAlgorithmException e) {
throw new IOException(e);
}
Registry<SchemeIOSessionStrategy> socketRegistry = RegistryBuilder.<SchemeIOSessionStrategy>create()
.register("http", NoopIOSessionStrategy.INSTANCE)
.register("https", new SSLIOSessionStrategy(sslContext, NoopHostnameVerifier.INSTANCE))
.build();
IOReactorConfig socketConfig = IOReactorConfig.custom()
.setIoThreadCount(pool.getReactorThreadCount())
.setSoTimeout(new Long(pool.getSocketTimeout()).intValue())
.setTcpNoDelay(true)
.setSoKeepAlive(true)
.setSelectInterval(REACTOR_SELECT_INTERVAL)
.build();
ConnectionConfig connectionConfig = ConnectionConfig.custom()
.setCharset(StandardCharsets.UTF_8)
.setMalformedInputAction(CodingErrorAction.IGNORE)
.setUnmappableInputAction(CodingErrorAction.IGNORE)
.build();
RequestConfig requestConfig = RequestConfig.custom()
.setConnectionRequestTimeout(new Long(pool.getMaxPoolWait()).intValue())
.setConnectTimeout(new Long(pool.getConnectionTimeout()).intValue())
.setExpectContinueEnabled(pool.expectContinue())
.setRedirectsEnabled(false)
.setStaleConnectionCheckEnabled(pool.getValidationOnInactivity() >= 0)
.build();
NHttpConnectionFactory<ManagedNHttpClientConnection> connFactory = new ManagedNHttpClientConnectionFactory(
new org.apache.http.impl.nio.codecs.DefaultHttpRequestWriterFactory(),
new org.apache.http.impl.nio.codecs.DefaultHttpResponseParserFactory(),
HeapByteBufferAllocator.INSTANCE
);
//TODO set validateAfterInactivity when supported
PoolingNHttpClientConnectionManager ccm = new PoolingNHttpClientConnectionManager(
new DefaultConnectingIOReactor(socketConfig),
connFactory,
socketRegistry,
new SystemDefaultDnsResolver()
);
ccm.setMaxTotal(pool.getMaxTotal());
ccm.setDefaultMaxPerRoute(pool.getMaxPerRoute());
ccm.setDefaultConnectionConfig(connectionConfig);
HttpAsyncClientBuilder builder = HttpAsyncClients.custom()
.setConnectionManager(ccm)
.setDefaultRequestConfig(requestConfig)
.setKeepAliveStrategy(DefaultConnectionKeepAliveStrategy.INSTANCE)
.disableCookieManagement();
IdleAsyncConnectionEvictor evictor = new IdleAsyncConnectionEvictor(ccm, pool.getEvictorSleep(), TimeUnit.MILLISECONDS, pool.getMaxIdleTime(), TimeUnit.MILLISECONDS);
addProxy(pool, builder);
handleRedirects(pool, builder);
CloseableHttpAsyncClient servClient = builder.build();
servClient.start();
HTTPCClientMonitor monitor = pool.hasConnectionMetrics() ? new HTTPCAsyncClientMonitor(pool.getName(), ccm) : null;
return new HTTPCAsyncClient(servClient, evictor, monitor);
}
开发者ID:mercadolibre,项目名称:java-restclient,代码行数:74,代码来源:HTTPCBuilder.java
示例4: getByteBufferAllocator
import org.apache.http.nio.util.HeapByteBufferAllocator; //导入依赖的package包/类
/**
* Returns the instance of {@link ByteBufferAllocator} to use for content buffering.
* Allows to plug in any {@link ByteBufferAllocator} implementation.
*/
protected ByteBufferAllocator getByteBufferAllocator() {
return HeapByteBufferAllocator.INSTANCE;
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:8,代码来源:HeapBufferedAsyncResponseConsumer.java
注:本文中的org.apache.http.nio.util.HeapByteBufferAllocator类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论