当前位置: 首页>>代码示例>>Java>>正文


Java InputStreamEntity.setContentEncoding方法代码示例

本文整理汇总了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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:OkApacheClient.java

示例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;
}
 
开发者ID:lizhangqu,项目名称:PriorityOkHttp,代码行数:24,代码来源:OkApacheClient.java

示例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;
}
 
开发者ID:NannanZ,项目名称:spdymcsclient,代码行数:24,代码来源:UTILS.java

示例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;
}
 
开发者ID:NannanZ,项目名称:spdymcsclient,代码行数:24,代码来源:OkApacheClient.java

示例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;
}
 
开发者ID:edgehosting,项目名称:jira-dvcs-connector,代码行数:16,代码来源:EtagCachingHttpClient.java

示例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);
}
 
开发者ID:timezra,项目名称:dropbox-java-sdk,代码行数:44,代码来源:DropboxAPI.java

示例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;
}
 
开发者ID:centic9,项目名称:CommonCrawlDocumentDownload,代码行数:62,代码来源:ArcRecord.java

示例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!");
}
 
开发者ID:dvorka,项目名称:mindraider,代码行数:56,代码来源:MindForgerClient.java


注:本文中的org.apache.http.entity.InputStreamEntity.setContentEncoding方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。