當前位置: 首頁>>代碼示例>>Java>>正文


Java AbstractHttpEntity類代碼示例

本文整理匯總了Java中org.apache.http.entity.AbstractHttpEntity的典型用法代碼示例。如果您正苦於以下問題:Java AbstractHttpEntity類的具體用法?Java AbstractHttpEntity怎麽用?Java AbstractHttpEntity使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


AbstractHttpEntity類屬於org.apache.http.entity包,在下文中一共展示了AbstractHttpEntity類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getCompressedEntity

import org.apache.http.entity.AbstractHttpEntity; //導入依賴的package包/類
/**
 * Compress data to send to server.
 * Creates a Http Entity holding the gzipped data.
 * The data will not be compressed if it is too short.
 * @param data The bytes to compress
 * @return Entity holding the data
 */
public static AbstractHttpEntity getCompressedEntity(byte data[], ContentResolver resolver)
        throws IOException {
    AbstractHttpEntity entity;
    if (data.length < getMinGzipSize(resolver)) {
        entity = new ByteArrayEntity(data);
    } else {
        ByteArrayOutputStream arr = new ByteArrayOutputStream();
        OutputStream zipper = new GZIPOutputStream(arr);
        zipper.write(data);
        zipper.close();
        entity = new ByteArrayEntity(arr.toByteArray());
        entity.setContentEncoding("gzip");
    }
    return entity;
}
 
開發者ID:thomasuster,項目名稱:android-expansion,代碼行數:23,代碼來源:AndroidHttpClient.java

示例2: sendPost

import org.apache.http.entity.AbstractHttpEntity; //導入依賴的package包/類
private String sendPost(String url, AbstractHttpEntity body, HashMap<String, String> headers)
        throws ClientProtocolException, IOException {
    throttle();

    HttpPost postRequest = new HttpPost(url);
    if (headers != null) {
        for (Entry<String, String> e : headers.entrySet()) {
            postRequest.addHeader(e.getKey(), e.getValue());
        }
    }

    postRequest.setEntity(body);

    CloseableHttpResponse closeableHttpResponse = HttpClients.createDefault().execute(postRequest);
    String response = Helpers.convertInputStreamToString(closeableHttpResponse.getEntity().getContent());

    return response;
}
 
開發者ID:bitsoex,項目名稱:bitso-java,代碼行數:19,代碼來源:BlockingHttpClient.java

示例3: getCompressedEntity

import org.apache.http.entity.AbstractHttpEntity; //導入依賴的package包/類
/**
 * Compress data to send to server.
 * Creates a Http Entity holding the gzipped data.
 * The data will not be compressed if it is too short.
 *
 * @param data The bytes to compress
 * @return Entity holding the data
 */
public static AbstractHttpEntity getCompressedEntity(byte data[], ContentResolver resolver)
        throws IOException {
    AbstractHttpEntity entity;
    if (data.length < getMinGzipSize(resolver)) {
        entity = new ByteArrayEntity(data);
    } else {
        ByteArrayOutputStream arr = new ByteArrayOutputStream();
        OutputStream zipper = new GZIPOutputStream(arr);
        zipper.write(data);
        zipper.close();
        entity = new ByteArrayEntity(arr.toByteArray());
        entity.setContentEncoding("gzip");
    }
    return entity;
}
 
開發者ID:islamsamak,項目名稱:janadroid,代碼行數:24,代碼來源:AndroidHttpClient.java

示例4: getCompressedEntity

import org.apache.http.entity.AbstractHttpEntity; //導入依賴的package包/類
/**
 * Compress data to send to server. Creates a Http Entity holding the
 * gzipped data. The data will not be compressed if it is too short.
 *
 * @param data The bytes to compress
 * @return Entity holding the data
 */
public static AbstractHttpEntity getCompressedEntity(byte data[],
                                                     ContentResolver resolver) throws IOException {
    AbstractHttpEntity entity;
    if (data.length < getMinGzipSize(resolver)) {
        entity = new ByteArrayEntity(data);
    } else {
        ByteArrayOutputStream arr = new ByteArrayOutputStream();
        OutputStream zipper = new GZIPOutputStream(arr);
        zipper.write(data);
        zipper.close();
        entity = new ByteArrayEntity(arr.toByteArray());
        entity.setContentEncoding("gzip");
    }
    return entity;
}
 
開發者ID:islamsamak,項目名稱:janadroid,代碼行數:23,代碼來源:DefaultHttpClient.java

示例5: insert

import org.apache.http.entity.AbstractHttpEntity; //導入依賴的package包/類
@Override
public boolean insert(Page page) {
    TargetModelElasticSearch document = new TargetModelElasticSearch(page);
    String docId = encodeUrl(page.getURL().toString());
    // We use upsert to avoid overriding existing fields in previously indexed documents
    String endpoint = String.format("/%s/%s/%s/_update", indexName, typeName, docId);
    Map<String, ?> body = ImmutableMap.of(
        "doc", document,
        "doc_as_upsert", true
    );
    AbstractHttpEntity entity = createJsonEntity(serializeAsJson(body));
    try {
        Response response = client.performRequest("POST", endpoint, EMPTY_MAP, entity);
        return response.getStatusLine().getStatusCode() == 201;
    } catch (IOException e) {
        throw new RuntimeException("Failed to index page.", e);
    }
}
 
開發者ID:ViDA-NYU,項目名稱:ache,代碼行數:19,代碼來源:ElasticSearchRestTargetRepository.java

示例6: uploadPart

import org.apache.http.entity.AbstractHttpEntity; //導入依賴的package包/類
@Override
public UploadPartResult uploadPart(String bucketName, String objectName,
    String uploadId, int partNumber, InputStream in)
    throws GalaxyFDSClientException {
  URI uri = formatUri(fdsConfig.getBaseUri(), bucketName + "/" + objectName,
      null);
  ContentType contentType = ContentType.APPLICATION_OCTET_STREAM;
  HashMap<String, String> params = new HashMap<String, String>();
  params.put("uploadId", uploadId);
  params.put("partNumber", String.valueOf(partNumber));
  AbstractHttpEntity requestEntity = getRequestEntity(in, contentType);
  HttpUriRequest httpRequest = prepareRequestMethod(uri,
      HttpMethod.PUT, contentType, null, params, null, requestEntity);

  HttpResponse response = executeHttpRequest(httpRequest, Action.UploadPart);

  UploadPartResult uploadPartResult = (UploadPartResult) processResponse(response,
      UploadPartResult.class,
      "upload part of object [" + objectName +
          "] to bucket [" + bucketName + "]" + "; part number [" +
          partNumber + "], upload id [" + uploadId + "]");

  return uploadPartResult;
}
 
開發者ID:XiaoMi,項目名稱:galaxy-fds-sdk-java,代碼行數:25,代碼來源:GalaxyFDSClient.java

示例7: getRequestEntity

import org.apache.http.entity.AbstractHttpEntity; //導入依賴的package包/類
private AbstractHttpEntity getRequestEntity(InputStream input,
    ContentType contentType, long inputStreamLength) throws GalaxyFDSClientException {

  if (input instanceof ByteArrayInputStream) {
    try {
      if (inputStreamLength > Integer.MAX_VALUE ||
          // -1 means length unknown, use all data
          (inputStreamLength < 0 && inputStreamLength != -1)) {
        throw new GalaxyFDSClientException("Invalid length [" +
            inputStreamLength + "] for byteArrayInputStream");
      }
      byte[] data = IOUtils.toByteArray(input);
      int len = inputStreamLength >= 0 ? (int)inputStreamLength : data.length;
      return new ByteArrayEntity(data, 0, len, contentType);
    } catch (IOException e) {
      throw new GalaxyFDSClientException("Failed to get content of input stream", e);
    }
  } else {
    BufferedInputStream bufferedInputStream = new BufferedInputStream(input);
    InputStreamEntity entity = new InputStreamEntity(bufferedInputStream,
        inputStreamLength, contentType);
    return entity;
  }
}
 
開發者ID:XiaoMi,項目名稱:galaxy-fds-sdk-java,代碼行數:25,代碼來源:GalaxyFDSClient.java

示例8: createEntity

import org.apache.http.entity.AbstractHttpEntity; //導入依賴的package包/類
public static AbstractHttpEntity createEntity(String paramString, Boolean paramBoolean)
  throws IOException
{
  if (paramBoolean.booleanValue())
  {
    byte[] arrayOfByte = paramString.getBytes("UTF-8");
    ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream(arrayOfByte.length);
    GZIPOutputStream localGZIPOutputStream = new GZIPOutputStream(localByteArrayOutputStream);
    localGZIPOutputStream.write(arrayOfByte);
    localGZIPOutputStream.finish();
    localGZIPOutputStream.flush();
    localGZIPOutputStream.close();
    return new ByteArrayEntity(localByteArrayOutputStream.toByteArray());
  }
  return new StringEntity(paramString);
}
 
開發者ID:zhangjianying,項目名稱:12306-android-Decompile,代碼行數:17,代碼來源:HTTPUtil.java

示例9: getHttpEntity

import org.apache.http.entity.AbstractHttpEntity; //導入依賴的package包/類
private HttpEntity getHttpEntity(final ClientRequest clientRequest) {
    final Object entity = clientRequest.getEntity();
    if(entity == null) {
        return null;
    }
    return new AbstractHttpEntity() {
        @Override
        public boolean isRepeatable() {
            return false;
        }

        @Override
        public long getContentLength() {
            return -1;
        }

        @Override
        public InputStream getContent() throws IOException, IllegalStateException {
            return null;
        }

        @Override
        public void writeTo(final OutputStream outputStream) throws IOException {
            clientRequest.setStreamProvider(new OutboundMessageContext.StreamProvider() {
                @Override
                public OutputStream getOutputStream(final int contentLength) throws IOException {
                    return outputStream;
                }
            });
            clientRequest.writeEntity();
        }

        @Override
        public boolean isStreaming() {
            return false;
        }
    };
}
 
開發者ID:iterate-ch,項目名稱:cyberduck,代碼行數:39,代碼來源:HttpComponentsConnector.java

示例10: write

import org.apache.http.entity.AbstractHttpEntity; //導入依賴的package包/類
@Override
public HttpResponseOutputStream<StorageObject> write(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException {
    final S3Object object = this.getDetails(file, status);
    final DelayedHttpEntityCallable<StorageObject> command = new DelayedHttpEntityCallable<StorageObject>() {
        @Override
        public StorageObject call(final AbstractHttpEntity entity) throws BackgroundException {
            try {
                final RequestEntityRestStorageService client = session.getClient();
                client.putObjectWithRequestEntityImpl(
                        containerService.getContainer(file).getName(), object, entity, status.getParameters());
                if(log.isDebugEnabled()) {
                    log.debug(String.format("Saved object %s with checksum %s", file, object.getETag()));
                }
            }
            catch(ServiceException e) {
                throw new S3ExceptionMappingService().map("Upload {0} failed", e, file);
            }
            return object;
        }

        @Override
        public long getContentLength() {
            return status.getLength();
        }
    };
    return this.write(file, status, command);
}
 
開發者ID:iterate-ch,項目名稱:cyberduck,代碼行數:28,代碼來源:S3WriteFeature.java

示例11: a

import org.apache.http.entity.AbstractHttpEntity; //導入依賴的package包/類
public static AbstractHttpEntity a(byte[] bArr) {
    if (((long) bArr.length) < a) {
        return new ByteArrayEntity(bArr);
    }
    OutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    OutputStream gZIPOutputStream = new GZIPOutputStream(byteArrayOutputStream);
    gZIPOutputStream.write(bArr);
    gZIPOutputStream.close();
    AbstractHttpEntity byteArrayEntity = new ByteArrayEntity(byteArrayOutputStream.toByteArray());
    byteArrayEntity.setContentEncoding(AsyncHttpClient.ENCODING_GZIP);
    new StringBuilder("gzip size:").append(bArr.length).append("->").append(byteArrayEntity.getContentLength());
    return byteArrayEntity;
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:14,代碼來源:b.java

示例12: createEntityForEntry

import org.apache.http.entity.AbstractHttpEntity; //導入依賴的package包/類
private HttpEntity createEntityForEntry(GDataSerializer entry, int format)
    throws IOException {
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  try {
    entry.serialize(baos, format);
  } catch (IOException ioe) {
    Log.e(TAG, "Unable to serialize entry.", ioe);
    throw ioe;
  } catch (ParseException pe) {
    Log.e(TAG, "Unable to serialize entry.", pe);
    throw new IOException("Unable to serialize entry: " + pe.getMessage());
  }

  byte[] entryBytes = baos.toByteArray();

  if (entryBytes != null && Log.isLoggable(TAG, Log.DEBUG)) {
    try {
      Log.d(TAG, "Serialized entry: " + new String(entryBytes, "UTF-8"));
    } catch (UnsupportedEncodingException uee) {
      // should not happen
      throw new IllegalStateException("UTF-8 should be supported!", uee);
    }
  }

  AbstractHttpEntity entity = new ByteArrayEntity(entryBytes);
  entity.setContentType(entry.getContentType());
  return entity;
}
 
開發者ID:Plonk42,項目名稱:mytracks,代碼行數:29,代碼來源:AndroidGDataClient.java

示例13: doHttpRequest

import org.apache.http.entity.AbstractHttpEntity; //導入依賴的package包/類
void doHttpRequest(String jsonString, HttpPost httpPost) throws UnsupportedEncodingException, IOException {
    HttpResponse httpResponse = null;
    
    String line = "";
    StringBuffer resultBuffer = new StringBuffer();
    List <NameValuePair> valuePair = new ArrayList <NameValuePair>();
    
    valuePair.add(new BasicNameValuePair("Content-Type", "application/x-www-form-urlencoded"));
    
    AbstractHttpEntity httpEntity = new UrlEncodedFormEntity(valuePair, HTTP.UTF_8);
    httpEntity.setContentType("application/x-www-form-urlencoded; charset=UTF-8");
    httpEntity.setContentEncoding("UTF-8");
    
    // httpPost.setEntity(new StringEntity(jsonString));
    // httpPost.setEntity(new UrlEncodedFormEntity(valuePair, HTTP.UTF_8));
    
    HttpClient httpClient = HttpClientBuilder.create().build();
    httpResponse = httpClient.execute(httpPost);
    
    System.out.println("Request parameters from my device : " + jsonString);
    System.out.println("Response code from the API server : " + httpResponse.getStatusLine().getStatusCode());
    
    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent()));
    
    while((line = bufferedReader.readLine()) != null) {
        resultBuffer.append(line);
    }
    
    System.out.println(resultBuffer.toString());
}
 
開發者ID:ravivendra,項目名稱:tmoney-dilofestival-Java-SDK,代碼行數:31,代碼來源:HttpSimpleCurlPost.java

示例14: createRequest

import org.apache.http.entity.AbstractHttpEntity; //導入依賴的package包/類
@NotNull
@Override
public HttpUriRequest createRequest(@NotNull ObjectMapper mapper, @NotNull String url) throws IOException {
  final HttpPost req = new HttpPost(url);
  req.addHeader(HEADER_ACCEPT, MIME_LFS_JSON);
  final byte[] content = mapper.writeValueAsBytes(meta);
  final AbstractHttpEntity entity = new ByteArrayEntity(content);
  entity.setContentType(MIME_LFS_JSON);
  req.setEntity(entity);
  return req;
}
 
開發者ID:bozaro,項目名稱:git-lfs-java,代碼行數:12,代碼來源:ObjectVerify.java

示例15: createRequest

import org.apache.http.entity.AbstractHttpEntity; //導入依賴的package包/類
@NotNull
@Override
public HttpUriRequest createRequest(@NotNull ObjectMapper mapper, @NotNull String url) throws IOException {
  final HttpPut req = new HttpPut(url);
  final AbstractHttpEntity entity = new InputStreamEntity(streamProvider.getStream(), size);
  entity.setContentType(MIME_BINARY);
  req.setEntity(entity);
  return req;
}
 
開發者ID:bozaro,項目名稱:git-lfs-java,代碼行數:10,代碼來源:ObjectPut.java


注:本文中的org.apache.http.entity.AbstractHttpEntity類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。