本文整理汇总了Java中ch.boye.httpclientandroidlib.HttpEntity.isRepeatable方法的典型用法代码示例。如果您正苦于以下问题:Java HttpEntity.isRepeatable方法的具体用法?Java HttpEntity.isRepeatable怎么用?Java HttpEntity.isRepeatable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ch.boye.httpclientandroidlib.HttpEntity
的用法示例。
在下文中一共展示了HttpEntity.isRepeatable方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPayloadHash
import ch.boye.httpclientandroidlib.HttpEntity; //导入方法依赖的package包/类
/**
* Generate the SHA-256 hash of a normalized Hawk payload generated from an
* HTTP entity.
* <p>
* <b>Warning:</b> the entity <b>must</b> be repeatable. If it is not, this
* code throws an <code>IllegalArgumentException</code>.
* <p>
* This is under-specified; the code here was reverse engineered from the code
* at
* <a href="https://github.com/hueniverse/hawk/blob/871cc597973110900467bd3dfb84a3c892f678fb/lib/crypto.js#L81">https://github.com/hueniverse/hawk/blob/871cc597973110900467bd3dfb84a3c892f678fb/lib/crypto.js#L81</a>.
* @param entity to normalize and hash.
* @return hash.
* @throws IllegalArgumentException if entity is not repeatable.
*/
protected static byte[] getPayloadHash(HttpEntity entity) throws UnsupportedEncodingException, IOException, NoSuchAlgorithmException {
if (!entity.isRepeatable()) {
throw new IllegalArgumentException("entity must be repeatable");
}
final MessageDigest digest = MessageDigest.getInstance("SHA-256");
digest.update(("hawk." + HAWK_HEADER_VERSION + ".payload\n").getBytes("UTF-8"));
digest.update(getBaseContentType(entity.getContentType()).getBytes("UTF-8"));
digest.update("\n".getBytes("UTF-8"));
InputStream stream = entity.getContent();
try {
int numRead;
byte[] buffer = new byte[4096];
while (-1 != (numRead = stream.read(buffer))) {
if (numRead > 0) {
digest.update(buffer, 0, numRead);
}
}
digest.update("\n".getBytes("UTF-8")); // Trailing newline is specified by Hawk.
return digest.digest();
} finally {
stream.close();
}
}
示例2: BufferedHttpEntity
import ch.boye.httpclientandroidlib.HttpEntity; //导入方法依赖的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;
}
}
示例3: isRepeatable
import ch.boye.httpclientandroidlib.HttpEntity; //导入方法依赖的package包/类
static boolean isRepeatable(final HttpRequest request) {
if (request instanceof HttpEntityEnclosingRequest) {
final HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity();
if (entity != null) {
if (isEnhanced(entity)) {
final RequestEntityProxy proxy = (RequestEntityProxy) entity;
if (!proxy.isConsumed()) {
return true;
}
}
return entity.isRepeatable();
}
}
return true;
}
示例4: enhance
import ch.boye.httpclientandroidlib.HttpEntity; //导入方法依赖的package包/类
static void enhance(final HttpEntityEnclosingRequest request) {
final HttpEntity entity = request.getEntity();
if (entity != null && !entity.isRepeatable() && !isEnhanced(entity)) {
request.setEntity(new RequestEntityProxy(entity));
}
}