本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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;
}
}
示例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);
}
示例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;
}
};
}
示例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);
}
示例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;
}
示例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;
}
示例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());
}
示例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;
}
示例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;
}