当前位置: 首页>>代码示例>>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;未经允许,请勿转载。