本文整理汇总了Java中org.apache.http.impl.io.ChunkedInputStream类的典型用法代码示例。如果您正苦于以下问题:Java ChunkedInputStream类的具体用法?Java ChunkedInputStream怎么用?Java ChunkedInputStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ChunkedInputStream类属于org.apache.http.impl.io包,在下文中一共展示了ChunkedInputStream类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: receiveRequest
import org.apache.http.impl.io.ChunkedInputStream; //导入依赖的package包/类
public HttpRequest receiveRequest() throws HttpException, IOException {
HttpRequest request = (HttpRequest) this.requestParser.parse();
if (HEADERLOG.isDebugEnabled()) {
HEADERLOG.debug(">> " + request.getRequestLine().toString());
for (HeaderIterator it = request.headerIterator(); it.hasNext(); ) {
HEADERLOG.debug(">> " + it.nextHeader().toString());
}
}
// Prepare input stream
this.in = null;
if (request instanceof HttpEntityEnclosingRequest) {
long len = this.contentLenStrategy.determineLength(request);
if (len == ContentLengthStrategy.CHUNKED) {
this.in = new ChunkedInputStream(this.inbuffer);
} else if (len == ContentLengthStrategy.IDENTITY) {
this.in = new IdentityInputStream(this.inbuffer);
} else {
this.in = new ContentLengthInputStream(inbuffer, len);
}
}
return request;
}
示例2: doDeserialize
import org.apache.http.impl.io.ChunkedInputStream; //导入依赖的package包/类
/**
* Creates a {@link BasicHttpEntity} based on properties of the given
* message. The content of the entity is created by wrapping
* {@link SessionInputBuffer} with a content decoder depending on the
* transfer mechanism used by the message.
* <p>
* This method is called by the public
* {@link #deserialize(SessionInputBuffer, HttpMessage)}.
*
* @param inbuffer the session input buffer.
* @param message the message.
* @return HTTP entity.
* @throws HttpException in case of HTTP protocol violation.
* @throws IOException in case of an I/O error.
*/
protected BasicHttpEntity doDeserialize(
final SessionInputBuffer inbuffer,
final HttpMessage message) throws HttpException, IOException {
BasicHttpEntity entity = new BasicHttpEntity();
long len = this.lenStrategy.determineLength(message);
if (len == ContentLengthStrategy.CHUNKED) {
entity.setChunked(true);
entity.setContentLength(-1);
entity.setContent(new ChunkedInputStream(inbuffer));
} else if (len == ContentLengthStrategy.IDENTITY) {
entity.setChunked(false);
entity.setContentLength(-1);
entity.setContent(new IdentityInputStream(inbuffer));
} else {
entity.setChunked(false);
entity.setContentLength(len);
entity.setContent(new ContentLengthInputStream(inbuffer, len));
}
Header contentTypeHeader = message.getFirstHeader(HTTP.CONTENT_TYPE);
if (contentTypeHeader != null) {
entity.setContentType(contentTypeHeader);
}
Header contentEncodingHeader = message.getFirstHeader(HTTP.CONTENT_ENCODING);
if (contentEncodingHeader != null) {
entity.setContentEncoding(contentEncodingHeader);
}
return entity;
}
示例3: unchunkResponse
import org.apache.http.impl.io.ChunkedInputStream; //导入依赖的package包/类
/**
* Converts chunked response data (returned by in the request body) <br>
* into a single piece, regular byte array.
*
* @param content Chunked data byte array
* @return Unchunked (regular) byte array
*/
public byte[] unchunkResponse(byte[] content) {
SessionInputBufferImpl buffer =
new SessionInputBufferImpl(new HttpTransportMetricsImpl(), 1024);
buffer.bind(new ByteArrayInputStream(content));
try {
if (content != null && content.length > 0) {
return IOUtils.toByteArray(new ChunkedInputStream(buffer));
}
} catch (IOException e) {
LOG.error("Cannot write chunked input stream to byte array!", e);
}
return content;
}