本文整理匯總了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;
}