本文整理汇总了Java中javax.ws.rs.ext.WriterInterceptorContext.getOutputStream方法的典型用法代码示例。如果您正苦于以下问题:Java WriterInterceptorContext.getOutputStream方法的具体用法?Java WriterInterceptorContext.getOutputStream怎么用?Java WriterInterceptorContext.getOutputStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.ws.rs.ext.WriterInterceptorContext
的用法示例。
在下文中一共展示了WriterInterceptorContext.getOutputStream方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: aroundWriteTo
import javax.ws.rs.ext.WriterInterceptorContext; //导入方法依赖的package包/类
@Override
public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException {
MessageDigest digest = null;
try {
digest = getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
throw new IllegalArgumentException(e);
}
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
DigestOutputStream digestStream = new DigestOutputStream(buffer, digest);
OutputStream old = context.getOutputStream();
context.setOutputStream(digestStream);
try {
context.proceed();
byte[] hash = digest.digest();
String encodedHash = getEncoder().encodeToString(hash);
context.getHeaders().putSingle(CONTENT_MD5_STRING, encodedHash);
byte[] content = buffer.toByteArray();
old.write(content);
} finally {
context.setOutputStream(old);
}
}
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:27,代码来源:ContentMD5Writer.java
示例2: aroundWriteTo
import javax.ws.rs.ext.WriterInterceptorContext; //导入方法依赖的package包/类
@Override
public void aroundWriteTo(WriterInterceptorContext context) throws IOException {
MultivaluedMap<String, Object> headers = context.getHeaders();
headers.add("Content-Encoding", "gzip");
final OutputStream outputStream = context.getOutputStream();
context.setOutputStream(new GZIPOutputStream(outputStream));
context.proceed();
}
开发者ID:durimkryeziu,项目名称:jersey-2.x-webapp-for-servlet-container,代码行数:11,代码来源:GZIPWriterInterceptor.java
示例3: aroundWriteTo
import javax.ws.rs.ext.WriterInterceptorContext; //导入方法依赖的package包/类
@Override
public void aroundWriteTo(WriterInterceptorContext context) throws IOException {
MultivaluedMap<String, Object> responseHeaders = context.getHeaders();
Object rangeHeader = responseHeaders.getFirst("Content-Range");
// Use a custom header here
// Some clients needs to know the content length in response headers in order to display a loading state
// Browsers don't let programmers to change the default "Accept-Encoding" header, then we use a custom one.
String acceptEncoding = requestHeaders.getHeaderString("x-accept-encoding");
GZIPOutputStream gzipOutputStream = null;
if (acceptEncoding != null && acceptEncoding.equals("identity")) {
responseHeaders.add("Content-Encoding", "identity");
} else if (rangeHeader == null) {
responseHeaders.add("Content-Encoding", "gzip");
responseHeaders.remove("Content-Length");
gzipOutputStream = new GZIPOutputStream(context.getOutputStream(), DEFAULT_BUFFER_SIZE);
context.setOutputStream(gzipOutputStream);
}
try {
context.proceed();
} finally {
if (gzipOutputStream != null) {
gzipOutputStream.finish();
}
}
}
示例4: aroundWriteTo
import javax.ws.rs.ext.WriterInterceptorContext; //导入方法依赖的package包/类
public void aroundWriteTo(WriterInterceptorContext ctx) throws IOException, WebApplicationException {
ByteArrayInterceptingOutputStream interceptOS = new ByteArrayInterceptingOutputStream(ctx.getOutputStream());
ctx.setOutputStream(interceptOS);
ctx.proceed();
if (!ctx.getHeaders().containsKey(header)) {
String xhubHeaderValue = XHub.generateHeaderXHubToken(getEncoder(), getHash(), Objects.requireNonNull(token, "cannot encode with a null token"), interceptOS.interceptedContent());
ctx.getHeaders().putSingle(header, xhubHeaderValue);
}
return;
}
示例5: aroundWriteTo
import javax.ws.rs.ext.WriterInterceptorContext; //导入方法依赖的package包/类
@Override
public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException
{
MessageDigest digest = null;
try
{
digest = MessageDigest.getInstance("MD5");
}
catch (NoSuchAlgorithmException e)
{
throw new IllegalArgumentException(e);
}
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
DigestOutputStream digestStream = new DigestOutputStream(buffer, digest);
OutputStream old = context.getOutputStream();
context.setOutputStream(digestStream);
try
{
context.proceed();
byte[] hash = digest.digest();
String encodedHash = Base64.encodeBytes(hash);
context.getHeaders().putSingle("Content-MD5", encodedHash);
byte[] content = buffer.toByteArray();
old.write(content);
}
finally
{
context.setOutputStream(old);
}
}
示例6: aroundWriteTo
import javax.ws.rs.ext.WriterInterceptorContext; //导入方法依赖的package包/类
@Override
public void aroundWriteTo (WriterInterceptorContext context)
throws IOException, WebApplicationException {
final OutputStream outputStream = context.getOutputStream();
context.setOutputStream(new GZIPOutputStream(outputStream));
context.proceed();
}
示例7: aroundWriteTo
import javax.ws.rs.ext.WriterInterceptorContext; //导入方法依赖的package包/类
@Override
public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException {
String acceptEncodings = getAcceptEncodingHeader(context.getHeaders());
if (acceptEncodings.contains("gzip")) {
final OutputStream outputStream = context.getOutputStream();
context.setOutputStream(new GZIPOutputStream(outputStream));
}
context.proceed();
}
示例8: aroundWriteTo
import javax.ws.rs.ext.WriterInterceptorContext; //导入方法依赖的package包/类
@Override
public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException {
context.getHeaders().add(CONTENT_ENCODING, SNAPPY);
final OutputStream outputStream = context.getOutputStream();
context.setOutputStream(new SnappyFramedOutputStream(outputStream));
context.proceed();
}
示例9: aroundWriteTo
import javax.ws.rs.ext.WriterInterceptorContext; //导入方法依赖的package包/类
@Override
public void aroundWriteTo(WriterInterceptorContext writerInterceptorContext)
throws IOException, WebApplicationException {
logger.info("Enters RestSkolWriterInterceptor.aroundWriterTo()");
final OutputStream outputStream = writerInterceptorContext.getOutputStream();
writerInterceptorContext.setOutputStream(new GZIPOutputStream(outputStream));
writerInterceptorContext.proceed();
}
示例10: aroundWriteTo
import javax.ws.rs.ext.WriterInterceptorContext; //导入方法依赖的package包/类
@Override
public void aroundWriteTo(WriterInterceptorContext context)
throws IOException, WebApplicationException {
MultivaluedMap<String,Object> headers = context.getHeaders();
headers.add("Content-Encoding", "gzip");
final OutputStream outputStream = context.getOutputStream();
context.setOutputStream(new GZIPOutputStream(outputStream));
context.proceed();
}
示例11: aroundWriteTo
import javax.ws.rs.ext.WriterInterceptorContext; //导入方法依赖的package包/类
@Override
public void aroundWriteTo(WriterInterceptorContext context)
throws IOException, WebApplicationException {
final OutputStream outputStream = context.getOutputStream();
context.setOutputStream(new GZIPOutputStream(outputStream));
context.proceed();
}
示例12: aroundWriteTo
import javax.ws.rs.ext.WriterInterceptorContext; //导入方法依赖的package包/类
public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException {
OutputStreamWrapper wrapper = new OutputStreamWrapper(context.getOutputStream());
context.setOutputStream(wrapper);
context.proceed();
logger.info("The contents of response body is: \n" + new String(wrapper.getBytes(), "UTF-8") + "\n");
}
示例13: aroundWriteTo
import javax.ws.rs.ext.WriterInterceptorContext; //导入方法依赖的package包/类
public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException {
OutputStreamWrapper wrapper = new OutputStreamWrapper(context.getOutputStream());
context.setOutputStream(wrapper);
context.proceed();
log.info("The contents of response body is: \n" + new String(wrapper.getBytes(), "UTF-8") + "\n");
}