本文整理匯總了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());
}