本文整理了Java中com.vmware.xenon.common.Utils.decodeBody()
方法的一些代码示例,展示了Utils.decodeBody()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils.decodeBody()
方法的具体详情如下:
包路径:com.vmware.xenon.common.Utils
类名称:Utils
方法名:decodeBody
[英]Decodes the byte buffer, using the content type as a hint. It sets the operation body to the decoded instance. It does not complete the operation.
[中]使用内容类型作为提示对字节缓冲区进行解码。它将操作体设置为已解码的实例。它无法完成操作。
代码示例来源:origin: vmware/xenon
private void decodeRequestBody(ChannelHandlerContext ctx, Operation request,
ByteBuf content, Integer streamId, String originalPath, double startTime) throws Exception {
if (!content.isReadable()) {
// skip body decode, request had no body
request.setContentLength(0);
submitRequest(ctx, request, streamId, originalPath, startTime);
return;
}
Utils.decodeBody(request, content.nioBuffer(), true);
submitRequest(ctx, request, streamId, originalPath, startTime);
}
代码示例来源:origin: vmware/xenon
/**
* Decodes the byte buffer, using the content type as a hint. It sets the operation body
* to the decoded instance. It does not complete the operation.
*/
public static void decodeBody(Operation op, ByteBuffer buffer, boolean isRequest)
throws Exception {
String contentEncodingHeader = null;
if (!isRequest) {
contentEncodingHeader = op.getResponseHeaderAsIs(Operation.CONTENT_ENCODING_HEADER);
} else if (!op.isFromReplication()) {
contentEncodingHeader = op.getRequestHeaderAsIs(Operation.CONTENT_ENCODING_HEADER);
}
boolean compressed = false;
if (contentEncodingHeader != null) {
compressed = Operation.CONTENT_ENCODING_GZIP.equals(contentEncodingHeader);
}
decodeBody(op, buffer, isRequest, compressed);
}
代码示例来源:origin: vmware/xenon
private void decodeResponseBody(Operation request, ByteBuf content) {
if (!content.isReadable()) {
if (checkResponseForError(request)) {
return;
}
// skip body decode, request had no body
request.setContentLength(0).setBodyNoCloning(null).complete();
return;
}
try {
Utils.decodeBody(request, content.nioBuffer(), false);
if (checkResponseForError(request)) {
return;
}
completeRequest(request);
} catch (Exception e) {
request.fail(e);
return;
}
}
代码示例来源:origin: vmware/xenon
@Test
public void testFailsDecodeGzipedBodyWithoutContentEncoding() throws Exception {
byte[] gzippedBody = compress("test");
Operation op = Operation
.createGet(null)
.setContentLength(gzippedBody.length)
.addResponseHeader(Operation.CONTENT_TYPE_HEADER, Operation.MEDIA_TYPE_TEXT_PLAIN);
try {
Utils.decodeBody(op, ByteBuffer.wrap(gzippedBody), false);
throw new IllegalStateException("should have failed");
} catch (MalformedInputException e) {
}
}
代码示例来源:origin: com.vmware.xenon/xenon-common
@Test
public void testFailsDecodeGzipedBodyWithoutContentEncoding() throws Exception {
byte[] gzippedBody = compress("test");
Operation op = Operation
.createGet(null)
.setContentLength(gzippedBody.length)
.addResponseHeader(Operation.CONTENT_TYPE_HEADER, Operation.MEDIA_TYPE_TEXT_PLAIN);
try {
Utils.decodeBody(op, ByteBuffer.wrap(gzippedBody), false);
throw new IllegalStateException("should have failed");
} catch (MalformedInputException e) {
}
}
代码示例来源:origin: vmware/xenon
@Test
public void testDecodeGzipedResponseBody() throws Exception {
String body = "This is the original body content, but gzipped";
byte[] gzippedBody = compress(body);
Operation op = Operation
.createGet(null)
.setContentLength(gzippedBody.length)
.addResponseHeader(Operation.CONTENT_ENCODING_HEADER,
Operation.CONTENT_ENCODING_GZIP)
.addResponseHeader(Operation.CONTENT_TYPE_HEADER, Operation.MEDIA_TYPE_TEXT_PLAIN);
Utils.decodeBody(op, ByteBuffer.wrap(gzippedBody), false);
assertEquals(body, op.getBody(String.class));
// Content encoding header is removed as the body is already decoded
assertNull(op.getResponseHeader(Operation.CONTENT_ENCODING_HEADER));
}
代码示例来源:origin: vmware/xenon
@Test
public void testDecodeGzipedRequestBody() throws Exception {
String body = "This is the original body content, but gzipped";
byte[] gzippedBody = compress(body);
Operation op = Operation
.createGet(null)
.setContentLength(gzippedBody.length)
.addRequestHeader(Operation.CONTENT_ENCODING_HEADER,
Operation.CONTENT_ENCODING_GZIP)
.addRequestHeader(Operation.CONTENT_TYPE_HEADER, Operation.MEDIA_TYPE_TEXT_PLAIN);
Utils.decodeBody(op, ByteBuffer.wrap(gzippedBody), true);
assertEquals(body, op.getBody(String.class));
// Content encoding header is removed as the body is already decoded
assertNull(op.getRequestHeader(Operation.CONTENT_ENCODING_HEADER));
}
代码示例来源:origin: com.vmware.xenon/xenon-common
@Test
public void testDecodeGzipedResponseBody() throws Exception {
String body = "This is the original body content, but gzipped";
byte[] gzippedBody = compress(body);
Operation op = Operation
.createGet(null)
.setContentLength(gzippedBody.length)
.addResponseHeader(Operation.CONTENT_ENCODING_HEADER,
Operation.CONTENT_ENCODING_GZIP)
.addResponseHeader(Operation.CONTENT_TYPE_HEADER, Operation.MEDIA_TYPE_TEXT_PLAIN);
Utils.decodeBody(op, ByteBuffer.wrap(gzippedBody), false);
assertEquals(body, op.getBody(String.class));
// Content encoding header is removed as the body is already decoded
assertNull(op.getResponseHeader(Operation.CONTENT_ENCODING_HEADER));
}
代码示例来源:origin: com.vmware.xenon/xenon-common
@Test
public void testDecodeGzipedRequestBody() throws Exception {
String body = "This is the original body content, but gzipped";
byte[] gzippedBody = compress(body);
Operation op = Operation
.createGet(null)
.setContentLength(gzippedBody.length)
.addRequestHeader(Operation.CONTENT_ENCODING_HEADER,
Operation.CONTENT_ENCODING_GZIP)
.addRequestHeader(Operation.CONTENT_TYPE_HEADER, Operation.MEDIA_TYPE_TEXT_PLAIN);
Utils.decodeBody(op, ByteBuffer.wrap(gzippedBody), true);
assertEquals(body, op.getBody(String.class));
// Content encoding header is removed as the body is already decoded
assertNull(op.getRequestHeader(Operation.CONTENT_ENCODING_HEADER));
}
内容来源于网络,如有侵权,请联系作者删除!