当前位置: 首页>>代码示例>>Java>>正文


Java WriterInterceptorContext.getOutputStream方法代码示例

本文整理汇总了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();
        }
    }
}
 
开发者ID:polarsys,项目名称:eplmp,代码行数:32,代码来源:GZIPWriterInterceptor.java

示例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;
}
 
开发者ID:McFoggy,项目名称:xhub4j,代码行数:12,代码来源:XHubWriterInterceptor.java

示例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);
   }
}
 
开发者ID:resteasy,项目名称:resteasy-examples,代码行数:34,代码来源:ContentMD5Writer.java

示例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();
}
 
开发者ID:KorAP,项目名称:Krill,代码行数:8,代码来源:Resource.java

示例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();
}
 
开发者ID:axibase,项目名称:atsd-api-java,代码行数:12,代码来源:GZipWriterInterceptor.java

示例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();
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:8,代码来源:SnappyWriterInterceptor.java

示例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();
}
 
开发者ID:cloudskol,项目名称:restskol,代码行数:10,代码来源:RestSkolWriterInterceptor.java

示例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();
}
 
开发者ID:Codingpedia,项目名称:demo-rest-jersey-spring,代码行数:12,代码来源:GZIPWriterInterceptor.java

示例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();
  }
 
开发者ID:cloudstore,项目名称:cloudstore,代码行数:8,代码来源:GZIPWriterInterceptor.java

示例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");
}
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:7,代码来源:LoggingFilter.java

示例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");
}
 
开发者ID:nince-wyj,项目名称:jahhan,代码行数:7,代码来源:LoggingFilter.java


注:本文中的javax.ws.rs.ext.WriterInterceptorContext.getOutputStream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。