本文整理汇总了Java中org.apache.http.entity.InputStreamEntity.setContentEncoding方法的典型用法代码示例。如果您正苦于以下问题:Java InputStreamEntity.setContentEncoding方法的具体用法?Java InputStreamEntity.setContentEncoding怎么用?Java InputStreamEntity.setContentEncoding使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.entity.InputStreamEntity
的用法示例。
在下文中一共展示了InputStreamEntity.setContentEncoding方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: transformResponse
import org.apache.http.entity.InputStreamEntity; //导入方法依赖的package包/类
private static HttpResponse transformResponse(Response response) {
int code = response.code();
String message = response.message();
BasicHttpResponse httpResponse = new BasicHttpResponse(HTTP_1_1, code, message);
ResponseBody body = response.body();
InputStreamEntity entity = new InputStreamEntity(body.byteStream(), body.contentLength());
httpResponse.setEntity(entity);
Headers headers = response.headers();
for (int i = 0, size = headers.size(); i < size; i++) {
String name = headers.name(i);
String value = headers.value(i);
httpResponse.addHeader(name, value);
if ("Content-Type".equalsIgnoreCase(name)) {
entity.setContentType(value);
} else if ("Content-Encoding".equalsIgnoreCase(name)) {
entity.setContentEncoding(value);
}
}
return httpResponse;
}
示例2: transformResponse
import org.apache.http.entity.InputStreamEntity; //导入方法依赖的package包/类
private static HttpResponse transformResponse(Response response) throws IOException {
int code = response.code();
String message = response.message();
BasicHttpResponse httpResponse = new BasicHttpResponse(HTTP_1_1, code, message);
ResponseBody body = response.body();
InputStreamEntity entity = new InputStreamEntity(body.byteStream(), body.contentLength());
httpResponse.setEntity(entity);
Headers headers = response.headers();
for (int i = 0, size = headers.size(); i < size; i++) {
String name = headers.name(i);
String value = headers.value(i);
httpResponse.addHeader(name, value);
if ("Content-Type".equalsIgnoreCase(name)) {
entity.setContentType(value);
} else if ("Content-Encoding".equalsIgnoreCase(name)) {
entity.setContentEncoding(value);
}
}
return httpResponse;
}
示例3: transformResponse
import org.apache.http.entity.InputStreamEntity; //导入方法依赖的package包/类
public static HttpResponse transformResponse(Response response) {
int code = response.code();
String message = response.message();
BasicHttpResponse httpResponse = new BasicHttpResponse(HTTP_1_1, code, message);
ResponseBody body = response.body();
InputStreamEntity entity = new InputStreamEntity(body.byteStream(), body.contentLength());
httpResponse.setEntity(entity);
Headers headers = response.headers();
for (int i = 0; i < headers.size(); i++) {
String name = headers.name(i);
String value = headers.value(i);
httpResponse.addHeader(name, value);
if ("Content-Type".equalsIgnoreCase(name)) {
entity.setContentType(value);
} else if ("Content-Encoding".equalsIgnoreCase(name)) {
entity.setContentEncoding(value);
}
}
return httpResponse;
}
示例4: transformResponse
import org.apache.http.entity.InputStreamEntity; //导入方法依赖的package包/类
private static HttpResponse transformResponse(Response response) {
int code = response.code();
String message = response.message();
BasicHttpResponse httpResponse = new BasicHttpResponse(HTTP_1_1, code, message);
ResponseBody body = response.body();
InputStreamEntity entity = new InputStreamEntity(body.byteStream(), body.contentLength());
httpResponse.setEntity(entity);
Headers headers = response.headers();
for (int i = 0; i < headers.size(); i++) {
String name = headers.name(i);
String value = headers.value(i);
httpResponse.addHeader(name, value);
if ("Content-Type".equalsIgnoreCase(name)) {
entity.setContentType(value);
} else if ("Content-Encoding".equalsIgnoreCase(name)) {
entity.setContentEncoding(value);
}
}
return httpResponse;
}
示例5: generateResponse
import org.apache.http.entity.InputStreamEntity; //导入方法依赖的package包/类
private HttpResponse generateResponse(HttpCacheEntry entry) throws IOException
{
HttpResponse response = new BasicHttpResponse(entry.getProtocolVersion(), entry
.getStatusCode(), entry.getReasonPhrase());
Resource resource = entry.getResource();
InputStreamEntity entity = new InputStreamEntity(resource.getInputStream(), resource.length());
entity.setContentType(entry.getFirstHeader(HTTP.CONTENT_TYPE));
entity.setContentEncoding(entry.getFirstHeader(HTTP.CONTENT_ENCODING));
response.setHeaders(entry.getAllHeaders());
response.setEntity(entity);
return response;
}
示例6: chunkedUploadRequest
import org.apache.http.entity.InputStreamEntity; //导入方法依赖的package包/类
/**
* Creates a request that can upload a single chunk of data to the server via the
* chunked upload protocol. This request reads the InputStream and advances it by
* an amount equal to the number of bytes uploaded. For most users, the {@link ChunkedUploader}
* object provides an easier interface to use and should provide most of the
* functionality needed. If offset is 0 and uploadId is null, a new chunked upload is
* created on the server.
*
* @param is A stream containing the data to be uploaded.
* @param length The number of bytes to upload.
* @param listener A ProgressListener (can be {@code null}) that will be notified of upload
* progress. The progress will be for this individual file chunk (starting
* at zero bytes and ending at {@code length} bytes).
* @param offset The offset into the file that the contents of the these bytes belongs to.
* @param uploadId The unique ID identifying this upload to the server.
* @return A ChunkedUploadRequest which can be used to upload a single chunk of data to Dropbox.
*/
public ChunkedUploadRequest chunkedUploadRequest(InputStream is, long length,
ProgressListener listener,
long offset, String uploadId) {
String[] params;
if (offset == 0) {
params = new String[0];
} else {
params = new String[]{"upload_id", uploadId, "offset", ""+offset};
}
String url = RESTUtility.buildURL(session.getContentServer(), VERSION, "/chunked_upload/", params);
HttpPut req = new HttpPut(url);
session.sign(req);
InputStreamEntity ise = new InputStreamEntity(is, length);
ise.setContentEncoding("application/octet-stream");
ise.setChunked(false);
HttpEntity entity = ise;
if (listener != null) {
entity = new ProgressHttpEntity(entity, listener);
}
req.setEntity(entity);
return new ChunkedUploadRequest(req, session);
}
示例7: getHttpResponse
import org.apache.http.entity.InputStreamEntity; //导入方法依赖的package包/类
/**
* <p>Returns an HTTP response object parsed from the ARC record payload.<p>
* <p>Note: The payload is parsed on-demand, but is only parsed once. The
* parsed data is saved for subsequent calls.</p>
*
* @return The ARC record payload as an HTTP response object. See the Apache
* HttpComponents project.
*/
public HttpResponse getHttpResponse()
throws IOException, HttpException {
if (this._httpResponse != null) {
return this._httpResponse;
}
if (this._payload == null) {
LOG.error("Unable to parse HTTP response: Payload has not been set"); return null;
}
if (this._url != null && !this._url.startsWith("http://") && !this._url.startsWith("https://")) {
LOG.error("Unable to parse HTTP response: URL protocol is not HTTP"); return null;
}
this._httpResponse = null;
// Find where the HTTP headers stop
int end = this._searchForCRLFCRLF(this._payload);
if (end == -1) {
LOG.error("Unable to parse HTTP response: End of HTTP headers not found"); return null;
}
// Parse the HTTP status line and headers
DefaultHttpResponseParser parser =
new DefaultHttpResponseParser(
new ByteArraySessionInputBuffer(this._payload, 0, end),
new BasicLineParser(),
new DefaultHttpResponseFactory(),
new BasicHttpParams()
);
this._httpResponse = parser.parse();
if (this._httpResponse == null) {
LOG.error("Unable to parse HTTP response"); return null;
}
// Set the reset of the payload as the HTTP entity. Use an InputStreamEntity
// to avoid a memory copy.
//trim trailing '\n' if it exists
int entityLength = _payload.length-end;
if (_payload.length > 0 && _payload[_payload.length-1]=='\n') {
entityLength--;
}
InputStreamEntity entity = new InputStreamEntity(new ByteArrayInputStream(this._payload, end, entityLength), entityLength);
entity.setContentType(this._httpResponse.getFirstHeader("Content-Type"));
entity.setContentEncoding(this._httpResponse.getFirstHeader("Content-Encoding"));
this._httpResponse.setEntity(entity);
return this._httpResponse;
}
示例8: importMindRaiderAtomFeeds
import org.apache.http.entity.InputStreamEntity; //导入方法依赖的package包/类
private void importMindRaiderAtomFeeds(String feedDirectoryString, String fileMask) throws Exception {
logger.debug("Importing Atom feeds from: "+feedDirectoryString);
File feedDirectory=new File(feedDirectoryString);
String importUrl=baseUrl+"/user/outlines";
logger.debug(" from: "+feedDirectory.getAbsolutePath()+" to "+importUrl);
if(feedDirectory.exists()) {
String[] atomFeeds = feedDirectory.list();
if(atomFeeds!=null && atomFeeds.length>0) {
for (int j = 0; j < atomFeeds.length; j++) {
if(atomFeeds[j]!=null && atomFeeds[j].endsWith("atom.xml")) {
if(fileMask!=null && !atomFeeds[j].startsWith(fileMask)) {
StatusBar.show("Skipping "+atomFeeds[j]);
continue;
}
String stringPage = feedDirectory+File.separator+atomFeeds[j];
logger.debug(" "+stringPage);
logger.debug(" POST");
StatusBar.show("Uploading Outline...");
HttpResponse response;
HttpClient httpClient = new DefaultHttpClient();
HttpPost post = new HttpPost(importUrl);
post.addHeader("Cookie", authenticationCookie);
// OK stream-based version
File file = new File(stringPage);
FileInputStream fileInputStream = new FileInputStream(file);
// set file length to avoid chunked encoding (use -1 to enforce it) > GAE doens't like -1
InputStreamEntity inputStreamEntity = new InputStreamEntity(fileInputStream, file.length());
inputStreamEntity.setContentEncoding(ENCODING_UTF_8);
inputStreamEntity.setContentType(CONTENT_TYPE_ATOM);
post.setEntity(inputStreamEntity);
response = httpClient.execute(post);
StatusLine statusLine = response.getStatusLine();
StatusBar.show("Outline uploaded! (finished with "+statusLine+")");
if(statusLine!=null && statusLine.getStatusCode()==409) {
JOptionPane.showMessageDialog(OutlineJPanel.getInstance().getComponent(0),
"Outline already exists in MindForger. Delete it there before upload please.",
"Conflict",
JOptionPane.ERROR_MESSAGE);
}
if(fileMask!=null) {
return;
}
} else {
StatusBar.show("Skipping '"+atomFeeds[j]+"' - wrong extension.");
}
}
} else {
StatusBar.show(" No pages!");
}
} else {
throw new RuntimeException(feedDirectory.getAbsolutePath()+" doesn't exist!");
}
StatusBar.show("Import finished!");
}