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