當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。