本文整理汇总了Java中org.apache.http.entity.BasicHttpEntity.setContentLength方法的典型用法代码示例。如果您正苦于以下问题:Java BasicHttpEntity.setContentLength方法的具体用法?Java BasicHttpEntity.setContentLength怎么用?Java BasicHttpEntity.setContentLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.entity.BasicHttpEntity
的用法示例。
在下文中一共展示了BasicHttpEntity.setContentLength方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: entityFromConnection
import org.apache.http.entity.BasicHttpEntity; //导入方法依赖的package包/类
/**
* Initializes an {@link HttpEntity} from the given {@link HttpURLConnection}.
* @param connection
* @return an HttpEntity populated with data from <code>connection</code>.
*/
private static HttpEntity entityFromConnection(HttpURLConnection connection) {
BasicHttpEntity entity = new BasicHttpEntity();
InputStream inputStream;
try {
inputStream = connection.getInputStream();
} catch (IOException ioe) {
inputStream = connection.getErrorStream();
}
entity.setContent(inputStream);
entity.setContentLength(connection.getContentLength());
entity.setContentEncoding(connection.getContentEncoding());
entity.setContentType(connection.getContentType());
return entity;
}
示例2: pushContent
import org.apache.http.entity.BasicHttpEntity; //导入方法依赖的package包/类
private void pushContent(HttpUriRequest request, String contentType, String contentEncoding, byte[] content) {
// TODO: check other preconditions?
if (contentType != null && content != null && request instanceof HttpEntityEnclosingRequest) {
BasicHttpEntity entity = new BasicHttpEntity();
entity.setContent(new ByteArrayInputStream(content));
entity.setContentLength(content.length);
entity.setChunked(false);
if (contentEncoding != null)
entity.setContentEncoding(contentEncoding);
entity.setContentType(contentType);
HttpEntityEnclosingRequest rr = (HttpEntityEnclosingRequest) request;
rr.setEntity(entity);
}
}
示例3: buildFakeResponse
import org.apache.http.entity.BasicHttpEntity; //导入方法依赖的package包/类
private HttpResponse buildFakeResponse(final String errorMessage) {
ByteArrayInputStream bais = new ByteArrayInputStream(new byte[0]);
BasicHttpEntity entity = new BasicHttpEntity();
entity.setContent(bais);
entity.setContentLength(0);
entity.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
BasicHttpResponse response = new BasicHttpResponse(
new ProtocolVersion("HTTP", 1, 1), 400,
"Exception: " + errorMessage);
response.setEntity(entity);
response.addHeader("Content-Disposition", "attachment; filename=error");
return response;
}
示例4: convertEntityNewToOld
import org.apache.http.entity.BasicHttpEntity; //导入方法依赖的package包/类
private org.apache.http.HttpEntity convertEntityNewToOld(HttpEntity ent) throws IllegalStateException, IOException
{
BasicHttpEntity ret = new BasicHttpEntity();
if (ent != null)
{
ret.setContent(ent.getContent());
ret.setContentLength(ent.getContentLength());
Header h;
h = ent.getContentEncoding();
if (h != null)
{
ret.setContentEncoding(convertheaderNewToOld(h));
}
h = ent.getContentType();
if (h != null)
{
ret.setContentType(convertheaderNewToOld(h));
}
}
return ret;
}
示例5: entityFromConnection
import org.apache.http.entity.BasicHttpEntity; //导入方法依赖的package包/类
/**
* Initializes an {@link HttpEntity} from the given
* {@link HttpURLConnection}.
*
* @param connection
* @return an HttpEntity populated with data from <code>connection</code>.
*/
private static HttpEntity entityFromConnection(HttpURLConnection connection)
{
BasicHttpEntity entity = new BasicHttpEntity();
InputStream inputStream;
try
{
inputStream = connection.getInputStream();
}
catch (IOException ioe)
{
inputStream = connection.getErrorStream();
}
entity.setContent(inputStream);
entity.setContentLength(connection.getContentLength());
entity.setContentEncoding(connection.getContentEncoding());
entity.setContentType(connection.getContentType());
return entity;
}
示例6: entityFromConnection
import org.apache.http.entity.BasicHttpEntity; //导入方法依赖的package包/类
/**
* Get response
*
* @return
* @throws IOException
*/
private HttpEntity entityFromConnection() throws IOException {
BasicHttpEntity entity = new BasicHttpEntity();
InputStream inputStream;
try {
inputStream = connection.getInputStream();
} catch (IOException ioe) {
inputStream = connection.getErrorStream();
}
if (GZIP.equals(getResponseheader(ResponseHeader.HEADER_CONTENT_ENCODING))) {
entity.setContent(new GZIPInputStream(inputStream));
} else {
entity.setContent(inputStream);
}
entity.setContentLength(connection.getContentLength());
entity.setContentEncoding(connection.getContentEncoding());
entity.setContentType(connection.getContentType());
return entity;
}
示例7: entityFromConnection
import org.apache.http.entity.BasicHttpEntity; //导入方法依赖的package包/类
/**
* Initializes an {@link HttpEntity} from the given {@link HttpURLConnection}.
*
* @return an HttpEntity populated with data from <code>connection</code>.
*/
/*
* 通过一个 HttpURLConnection 获取其对应的 HttpEntity ( 这里就 HttpEntity 而言,耦合了 Apache )
*/
private static HttpEntity entityFromConnection(HttpURLConnection connection) {
BasicHttpEntity entity = new BasicHttpEntity();
InputStream inputStream;
try {
inputStream = connection.getInputStream();
} catch (IOException ioe) {
inputStream = connection.getErrorStream();
}
// 设置 HttpEntity 的内容
entity.setContent(inputStream);
// 设置 HttpEntity 的长度
entity.setContentLength(connection.getContentLength());
// 设置 HttpEntity 的编码
entity.setContentEncoding(connection.getContentEncoding());
// 设置 HttpEntity Content-Type
entity.setContentType(connection.getContentType());
return entity;
}
示例8: getEntityFromConnection
import org.apache.http.entity.BasicHttpEntity; //导入方法依赖的package包/类
private HttpEntity getEntityFromConnection(HttpURLConnection connection) {
BasicHttpEntity entity = new BasicHttpEntity();
InputStream inputStream;
try {
inputStream = connection.getInputStream();
} catch (IOException e) {
inputStream = connection.getErrorStream();
}
entity.setContent(inputStream);
entity.setContentLength(connection.getContentLength());
entity.setContentEncoding(connection.getContentEncoding());
entity.setContentType(connection.getContentType());
return entity;
}
示例9: entityFromConnection
import org.apache.http.entity.BasicHttpEntity; //导入方法依赖的package包/类
/**
* Initializes an {@link HttpEntity} from the given
* {@link HttpURLConnection}.
*
* @param connection
* @return an HttpEntity populated with data from <code>connection</code>.
*/
private static HttpEntity entityFromConnection(HttpURLConnection connection) {
BasicHttpEntity entity = new BasicHttpEntity();
InputStream inputStream;
try {
inputStream = connection.getInputStream();
} catch (IOException ioe) {
inputStream = connection.getErrorStream();
}
entity.setContent(inputStream);
entity.setContentLength(connection.getContentLength());
entity.setContentEncoding(connection.getContentEncoding());
entity.setContentType(connection.getContentType());
return entity;
}
示例10: convertEntityNewToOld
import org.apache.http.entity.BasicHttpEntity; //导入方法依赖的package包/类
private org.apache.http.HttpEntity convertEntityNewToOld(HttpEntity ent)
throws IllegalStateException, IOException {
BasicHttpEntity ret = new BasicHttpEntity();
if (ent != null) {
ret.setContent(ent.getContent());
ret.setContentLength(ent.getContentLength());
Header h;
h = ent.getContentEncoding();
if (h != null) {
ret.setContentEncoding(convertheaderNewToOld(h));
}
h = ent.getContentType();
if (h != null) {
ret.setContentType(convertheaderNewToOld(h));
}
}
return ret;
}
示例11: entityFromOkHttpResponse
import org.apache.http.entity.BasicHttpEntity; //导入方法依赖的package包/类
private static HttpEntity entityFromOkHttpResponse(Response r) throws IOException {
BasicHttpEntity entity = new BasicHttpEntity();
ResponseBody body = r.body();
entity.setContent(body.byteStream());
entity.setContentLength(body.contentLength());
entity.setContentEncoding(r.header("Content-Encoding"));
if (body.contentType() != null) {
entity.setContentType(body.contentType().type());
}
return entity;
}
示例12: entityFromConnection
import org.apache.http.entity.BasicHttpEntity; //导入方法依赖的package包/类
/**
* Initializes an {@link HttpEntity} from the given {@link HttpURLConnection}.
*
* @param connection
* @return an HttpEntity populated with data from <code>connection</code>.
*/
private static HttpEntity entityFromConnection(HttpURLConnection connection) {
BasicHttpEntity entity = new BasicHttpEntity();
InputStream inputStream;
try {
inputStream = connection.getInputStream();
} catch (IOException ioe) {
inputStream = connection.getErrorStream();
}
entity.setContent(inputStream);
entity.setContentLength(connection.getContentLength());
entity.setContentEncoding(connection.getContentEncoding());
entity.setContentType(connection.getContentType());
return entity;
}
示例13: doDeserialize
import org.apache.http.entity.BasicHttpEntity; //导入方法依赖的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;
}
示例14: entityFromConnection
import org.apache.http.entity.BasicHttpEntity; //导入方法依赖的package包/类
private static HttpEntity entityFromConnection(HttpURLConnection connection) {
BasicHttpEntity entity = new BasicHttpEntity();
InputStream inputStream;
try {
inputStream = connection.getInputStream();
} catch (IOException ioe) {
inputStream = connection.getErrorStream();
}
entity.setContent(inputStream);
entity.setContentLength(connection.getContentLength());
entity.setContentEncoding(connection.getContentEncoding());
entity.setContentType(connection.getContentType());
return entity;
}
示例15: entityFromConnection
import org.apache.http.entity.BasicHttpEntity; //导入方法依赖的package包/类
private static HttpEntity entityFromConnection(HttpURLConnection connection) {
InputStream inputStream;
BasicHttpEntity entity = new BasicHttpEntity();
try {
inputStream = connection.getInputStream();
} catch (IOException e) {
inputStream = connection.getErrorStream();
}
entity.setContent(inputStream);
entity.setContentLength((long) connection.getContentLength());
entity.setContentEncoding(connection.getContentEncoding());
entity.setContentType(connection.getContentType());
return entity;
}