本文整理汇总了Java中org.apache.http.util.EntityUtils.toByteArray方法的典型用法代码示例。如果您正苦于以下问题:Java EntityUtils.toByteArray方法的具体用法?Java EntityUtils.toByteArray怎么用?Java EntityUtils.toByteArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.util.EntityUtils
的用法示例。
在下文中一共展示了EntityUtils.toByteArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ClientYamlTestResponse
import org.apache.http.util.EntityUtils; //导入方法依赖的package包/类
ClientYamlTestResponse(Response response) throws IOException {
this.response = response;
if (response.getEntity() != null) {
String contentType = response.getHeader("Content-Type");
this.bodyContentType = XContentType.fromMediaTypeOrFormat(contentType);
try {
byte[] bytes = EntityUtils.toByteArray(response.getEntity());
//skip parsing if we got text back (e.g. if we called _cat apis)
if (bodyContentType != null) {
this.parsedResponse = ObjectPath.createFromXContent(bodyContentType.xContent(), new BytesArray(bytes));
}
this.body = bytes;
} catch (IOException e) {
EntityUtils.consumeQuietly(response.getEntity());
throw e;
}
} else {
this.body = null;
this.bodyContentType = null;
}
}
示例2: captchaImage
import org.apache.http.util.EntityUtils; //导入方法依赖的package包/类
private static byte[] captchaImage(String url) {
Objects.requireNonNull(url);
CloseableHttpClient httpClient = buildHttpClient();
HttpGet httpGet = new HttpGet(url);
httpGet.addHeader(CookieManager.cookieHeader());
byte[] result = new byte[0];
try (CloseableHttpResponse response = httpClient.execute(httpGet)) {
CookieManager.touch(response);
result = EntityUtils.toByteArray(response.getEntity());
} catch (IOException e) {
logger.error("captchaImage error", e);
}
return result;
}
示例3: HttpResult
import org.apache.http.util.EntityUtils; //导入方法依赖的package包/类
public HttpResult(HttpResponse httpResponse, CookieStore cookieStore) {
if (cookieStore != null) {
this.cookies = cookieStore.getCookies().toArray(new Cookie[0]);
}
if (httpResponse != null) {
this.headers = httpResponse.getAllHeaders();
this.statuCode = httpResponse.getStatusLine().getStatusCode();
if(d)System.out.println(this.statuCode);
try {
this.response = EntityUtils.toByteArray(httpResponse
.getEntity());
} catch (IOException e) {
e.printStackTrace();
}
}
}
示例4: Response
import org.apache.http.util.EntityUtils; //导入方法依赖的package包/类
/**
* Constructor
*
* @param response the http response
*/
public Response( final HttpResponse response )
{
this.status = response.getStatusLine( );
this.headers = response.getAllHeaders( );
try
{
this.entityContent = EntityUtils.toByteArray( response.getEntity( ) );
// EntityUtils.consume( response.getEntity( ) );
}
catch ( IllegalArgumentException | IOException e )
{
// ok
}
}
示例5: execute
import org.apache.http.util.EntityUtils; //导入方法依赖的package包/类
private <U> U execute(URISupplier<URI> uriSupplier, MappingFunction<byte[], U> responseMapper, Supplier<U> notFoundMapper) {
try {
URI uri = uriSupplier.get();
Request request = Request.Get(uri);
HttpResponse response = request.execute().returnResponse();
if (response.getStatusLine().getStatusCode() == 200) {
byte[] returnJson = EntityUtils.toByteArray(response.getEntity());
return responseMapper.apply(returnJson);
} else if (response.getStatusLine().getStatusCode() == 404) {
return notFoundMapper.get();
} else if (response.getStatusLine().getStatusCode() == 400) {
throw new IllegalArgumentException("Bad Request");
} else {
throw new QueryExecutionException("Something went wrong, status code: " + response.getStatusLine().getStatusCode());
}
} catch (URISyntaxException | IOException e) {
throw new ConnectionException("Error creating connection", e);
}
}
示例6: getFile
import org.apache.http.util.EntityUtils; //导入方法依赖的package包/类
/**
* 下载文件
*
* @param url URL
* @return 文件的二进制流,客户端使用outputStream输出为文件
*/
public static byte[] getFile(String url) {
try {
Request request = Request.Get(url);
HttpEntity resEntity = request.execute().returnResponse().getEntity();
return EntityUtils.toByteArray(resEntity);
} catch (Exception e) {
logger.error("postFile请求异常," + e.getMessage() + "\n post url:" + url);
e.printStackTrace();
}
return null;
}
示例7: decryptHttpEntity
import org.apache.http.util.EntityUtils; //导入方法依赖的package包/类
/**
*
* @param entity
* @return
*/
public static byte[] decryptHttpEntity(HttpEntity entity) {
byte[] buffer = null;
try {
buffer = EntityUtils.toByteArray(entity);
} catch (IOException e) {
e.printStackTrace();
}
if (buffer != null) {
return new Crypter().decrypt(buffer, SECRET_KEY_HTTP);
}
return buffer;
}
示例8: signWithoutSettingParameterOrder
import org.apache.http.util.EntityUtils; //导入方法依赖的package包/类
private byte[] signWithoutSettingParameterOrder(Map<String, String> map, HttpEntity entity){
// TODO signature length should be constant. currently signature length is proportional to number of parameters.
ByteArrayOutputStream signature = new ByteArrayOutputStream();
try{
MessageDigest md = MessageDigest.getInstance(HASHING_ALGORITHM);
for(Entry<String,String> entry : map.entrySet()){
String parameterName = entry.getKey();
if(parameterName.equals(SecurityParameters.SIGNATURE) || "submitAction".equals(parameterName)){
continue;
}
String value = entry.getValue();
String keyValue = parameterName.concat(value == null ? "" : value);
String keyValueSalt = keyValue.concat(salt);
md.update(keyValueSalt.getBytes(StandardCharsets.UTF_8));
signature.write(md.digest());
}
if(entity != null){
byte[] bytes = EntityUtils.toByteArray(entity);
md.update(bytes);
md.update(salt.getBytes(StandardCharsets.UTF_8));
signature.write(md.digest());
}
}catch(IOException | NoSuchAlgorithmException e){
throw new RuntimeException(e);
}
return signature.toByteArray();
}
示例9: getContent
import org.apache.http.util.EntityUtils; //导入方法依赖的package包/类
public byte[] getContent() throws IOException{
if(content != null){
return content;
}
// don't close stream
content = EntityUtils.toByteArray(new InputStreamEntity(super.getInputStream()));
return content;
}
示例10: BufferedHttpEntity
import org.apache.http.util.EntityUtils; //导入方法依赖的package包/类
/**
* Creates a new buffered entity wrapper.
*
* @param entity the entity to wrap, not null
* @throws IllegalArgumentException if wrapped is null
*/
public BufferedHttpEntity(final HttpEntity entity) throws IOException {
super(entity);
if (!entity.isRepeatable() || entity.getContentLength() < 0) {
this.buffer = EntityUtils.toByteArray(entity);
} else {
this.buffer = null;
}
}
示例11: getByteArray
import org.apache.http.util.EntityUtils; //导入方法依赖的package包/类
/**
* 获取响应内容为字节数组
*
*
* @date 2015年7月17日
* @return
*/
public byte[] getByteArray() {
try {
return EntityUtils.toByteArray(entity);
} catch (ParseException | IOException e) {
logger.error(e.getMessage(), e);
throw new RuntimeException(e.getMessage(), e);
}
}
示例12: bytes
import org.apache.http.util.EntityUtils; //导入方法依赖的package包/类
private byte[] bytes(HttpEntity entity){
try {
return EntityUtils.toByteArray(entity);
} catch (IOException e) {
error(e);
}
return null;
}
示例13: handleResponse
import org.apache.http.util.EntityUtils; //导入方法依赖的package包/类
public static byte[] handleResponse(HttpResponse response) throws IOException {
HttpEntity entity = response.getEntity();
if (entity == null) return null;
byte[] output = EntityUtils.toByteArray(entity);
EntityUtils.consume(entity);
return output;
}
示例14: parseRequestBody
import org.apache.http.util.EntityUtils; //导入方法依赖的package包/类
private byte[] parseRequestBody(HttpRequest request) throws IOException {
HttpEntity entity = null;
if (request instanceof HttpEntityEnclosingRequest)
entity = ((HttpEntityEnclosingRequest) request).getEntity();
return entity != null ? EntityUtils.toByteArray(entity) : null;
}
示例15: ResponseInfo
import org.apache.http.util.EntityUtils; //导入方法依赖的package包/类
private ResponseInfo(HttpResponse response) throws IOException {
this.status = response.getStatusLine().getStatusCode();
this.payload = EntityUtils.toByteArray(response.getEntity());
}