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


Java EntityUtils.toByteArray方法代碼示例

本文整理匯總了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;
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:22,代碼來源:ClientYamlTestResponse.java

示例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;
}
 
開發者ID:justice-code,項目名稱:Thrush,代碼行數:19,代碼來源:HttpRequest.java

示例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();
		}
	}

}
 
開發者ID:Evan-Galvin,項目名稱:FreeStreams-TVLauncher,代碼行數:19,代碼來源:HttpResult.java

示例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
	}
}
 
開發者ID:ApinautenGmbH,項目名稱:integration-test-helper,代碼行數:21,代碼來源:Response.java

示例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);
    }

}
 
開發者ID:ftrossbach,項目名稱:kiqr,代碼行數:27,代碼來源:GenericBlockingRestKiqrClientImpl.java

示例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;
}
 
開發者ID:funtl,項目名稱:framework,代碼行數:18,代碼來源:HttpUtils.java

示例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;
}
 
開發者ID:SavorGit,項目名稱:Hotspot-master-devp,代碼行數:18,代碼來源:SecurityUtil.java

示例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();
}
 
開發者ID:hotpads,項目名稱:datarouter,代碼行數:29,代碼來源:DefaultSignatureValidator.java

示例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;
}
 
開發者ID:hotpads,項目名稱:datarouter,代碼行數:10,代碼來源:CachingHttpServletRequest.java

示例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;
    }
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:15,代碼來源:BufferedHttpEntity.java

示例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);
	}
}
 
開發者ID:swxiao,項目名稱:bubble2,代碼行數:16,代碼來源:ResponseWrap.java

示例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;
}
 
開發者ID:fcibook,項目名稱:QuickHttp,代碼行數:9,代碼來源:HttpResponseBody.java

示例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;
}
 
開發者ID:mercadolibre,項目名稱:java-restclient,代碼行數:10,代碼來源:HTTPCUtil.java

示例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;
}
 
開發者ID:mercadolibre,項目名稱:java-restclient,代碼行數:8,代碼來源:HTTPCMockHandler.java

示例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());
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:5,代碼來源:IntegrationTestUtils.java


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