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


Java ReaderInterceptorContext.getInputStream方法代码示例

本文整理汇总了Java中javax.ws.rs.ext.ReaderInterceptorContext.getInputStream方法的典型用法代码示例。如果您正苦于以下问题:Java ReaderInterceptorContext.getInputStream方法的具体用法?Java ReaderInterceptorContext.getInputStream怎么用?Java ReaderInterceptorContext.getInputStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.ws.rs.ext.ReaderInterceptorContext的用法示例。


在下文中一共展示了ReaderInterceptorContext.getInputStream方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: aroundReadFrom

import javax.ws.rs.ext.ReaderInterceptorContext; //导入方法依赖的package包/类
@Override
public Object aroundReadFrom(ReaderInterceptorContext ric) throws IOException, WebApplicationException {
    
    System.out.println("MyClientReaderInterceptor");
    final InputStream old = ric.getInputStream();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    int c;
    while ((c = old.read()) != -1) {
        baos.write(c);
    }
    System.out.println("MyClientReaderInterceptor --> " + baos.toString());
    
    ric.setInputStream(new ByteArrayInputStream(baos.toByteArray()));
    
    return ric.proceed();
}
 
开发者ID:ftomassetti,项目名称:JavaIncrementalParser,代码行数:17,代码来源:MyClientReaderInterceptor.java

示例2: aroundReadFrom

import javax.ws.rs.ext.ReaderInterceptorContext; //导入方法依赖的package包/类
@Override
public Object aroundReadFrom(ReaderInterceptorContext readerInterceptorContext) throws IOException, WebApplicationException {
    final InputStream originalInputStream = readerInterceptorContext.getInputStream();
    readerInterceptorContext.setInputStream(new InputStream() {

        @Override
        public int read() throws IOException {
            boolean isOk;
            int b;
            do {
                b = originalInputStream.read();
                isOk = b == -1 || Character.isLetterOrDigit(b) || Character.isWhitespace(b) || b == ((int) '.');
            } while (!isOk);

            return b;
        }
    });
    try {
        return readerInterceptorContext.proceed();
    } finally {
        readerInterceptorContext.setInputStream(originalInputStream);
    }
}
 
开发者ID:osmanpub,项目名称:oracle-samples,代码行数:24,代码来源:ValidCharacterInterceptor.java

示例3: aroundReadFrom

import javax.ws.rs.ext.ReaderInterceptorContext; //导入方法依赖的package包/类
@Override
   public Object aroundReadFrom(ReaderInterceptorContext context) throws IOException, WebApplicationException {
	InputStream originalInputStream = context.getInputStream();

       if (!originalInputStream.markSupported())
       	originalInputStream = new BufferedInputStream(originalInputStream);

       // Test, if it contains data. We only try to unzip, if it is not empty.
       originalInputStream.mark(5);
       int read = originalInputStream.read();
       originalInputStream.reset();

       if (read > -1)
       	context.setInputStream(new GZIPInputStream(originalInputStream));
       else {
       	context.setInputStream(originalInputStream); // We might have wrapped it with our BufferedInputStream!
       	logger.debug("aroundReadFrom: originalInputStream is empty! Skipping GZIP.");
       }
       return context.proceed();
}
 
开发者ID:cloudstore,项目名称:cloudstore,代码行数:21,代码来源:GZIPReaderInterceptor.java

示例4: aroundReadFrom

import javax.ws.rs.ext.ReaderInterceptorContext; //导入方法依赖的package包/类
@Override
public Object aroundReadFrom(ReaderInterceptorContext interceptorContext)
		throws IOException, WebApplicationException {
	logger.info("ServerReaderInterceptor invoked");
	InputStream inputStream = interceptorContext.getInputStream();
	byte[] bytes = new byte[inputStream.available()];
	inputStream.read(bytes);
	String requestContent = new String(bytes);
	requestContent = requestContent + ".Request changed in ServerReaderInterceptor.";
	interceptorContext.setInputStream(new ByteArrayInputStream(requestContent.getBytes()));
	return interceptorContext.proceed();
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:13,代码来源:ServerReaderInterceptor.java

示例5: aroundReadFrom

import javax.ws.rs.ext.ReaderInterceptorContext; //导入方法依赖的package包/类
@Override
public Object aroundReadFrom(ReaderInterceptorContext interceptorContext)
		throws IOException, WebApplicationException {
	logger.info("ClientSecondReaderInterceptor invoked.");
	InputStream inputStream = interceptorContext.getInputStream();
	byte[] bytes = new byte[inputStream.available()];
	inputStream.read(bytes);
	String requestContent = new String(bytes);
	requestContent = requestContent + " Request changed in ClientSecondReaderInterceptor.";
	interceptorContext.setInputStream(new ByteArrayInputStream(requestContent.getBytes()));
	return interceptorContext.proceed();
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:13,代码来源:ClientSecondReaderInterceptor.java

示例6: aroundReadFrom

import javax.ws.rs.ext.ReaderInterceptorContext; //导入方法依赖的package包/类
@Override
public Object aroundReadFrom(ReaderInterceptorContext interceptorContext)
		throws IOException, WebApplicationException {
	logger.info("ClientFirstReaderInterceptor invoked");
	InputStream inputStream = interceptorContext.getInputStream();
	byte[] bytes = new byte[inputStream.available()];
	inputStream.read(bytes);
	String requestContent = new String(bytes);
	requestContent = requestContent + ".Request changed in ClientFirstReaderInterceptor.";
	interceptorContext.setInputStream(new ByteArrayInputStream(requestContent.getBytes()));
	return interceptorContext.proceed();
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:13,代码来源:ClientFirstReaderInterceptor.java

示例7: aroundReadFrom

import javax.ws.rs.ext.ReaderInterceptorContext; //导入方法依赖的package包/类
@Override
public Object aroundReadFrom (ReaderInterceptorContext context)
        throws IOException, WebApplicationException {
    final InputStream originalInputStream = context.getInputStream();
    context.setInputStream(new GZIPInputStream(originalInputStream));
    return context.proceed();
}
 
开发者ID:KorAP,项目名称:Krill,代码行数:8,代码来源:Resource.java

示例8: aroundReadFrom

import javax.ws.rs.ext.ReaderInterceptorContext; //导入方法依赖的package包/类
@Override
public Object aroundReadFrom(ReaderInterceptorContext context)  throws IOException, WebApplicationException {
  if (context.getHeaders().containsKey("Content-Encoding") &&
    context.getHeaders().get("Content-Encoding").contains("snappy")) {
    InputStream originalInputStream = context.getInputStream();
    context.setInputStream(new SnappyFramedInputStream(originalInputStream, true));
  }
  return context.proceed();
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:10,代码来源:TestHttpTarget.java

示例9: aroundReadFrom

import javax.ws.rs.ext.ReaderInterceptorContext; //导入方法依赖的package包/类
@Override
public Object aroundReadFrom(ReaderInterceptorContext context)  throws IOException, WebApplicationException {
  if (context.getHeaders().containsKey(CONTENT_ENCODING) &&
    context.getHeaders().get(CONTENT_ENCODING).contains(SNAPPY)) {
    InputStream originalInputStream = context.getInputStream();
    context.setInputStream(new SnappyFramedInputStream(originalInputStream, true));
  }
  return context.proceed();
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:10,代码来源:SnappyReaderInterceptor.java

示例10: aroundReadFrom

import javax.ws.rs.ext.ReaderInterceptorContext; //导入方法依赖的package包/类
@Override
public Object aroundReadFrom(ReaderInterceptorContext readerInterceptorContext)
        throws IOException, WebApplicationException {
    logger.info("Enters RestSkolReaderInterceptor.aroundReadFrom()");

    final InputStream inputStream = readerInterceptorContext.getInputStream();
    readerInterceptorContext.setInputStream(new GZIPInputStream(inputStream));

    return readerInterceptorContext.proceed();
}
 
开发者ID:cloudskol,项目名称:restskol,代码行数:11,代码来源:RestSkolReaderInterceptor.java

示例11: aroundReadFrom

import javax.ws.rs.ext.ReaderInterceptorContext; //导入方法依赖的package包/类
@Override
    public Object aroundReadFrom(ReaderInterceptorContext ric) throws IOException, WebApplicationException {
        
        System.out.println("MyClientReaderInterceptor");
//        ric.setInputStream(new FilterInputStream(ric.getInputStream()) {
//
//            final ByteArrayOutputStream baos = new ByteArrayOutputStream();
//
//            @Override
//            public int read(byte[] b, int off, int len) throws IOException {
//                baos.write(b, off, len);
////                System.out.println("@@@@@@ " + b);
//                return super.read(b, off, len);
//            }
//
//            @Override
//            public void close() throws IOException {
//                System.out.println("### " + baos.toString());
//                super.close();
//            }
//        });
        final InputStream old = ric.getInputStream();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        int c;
        while ((c = old.read()) != -1) {
            baos.write(c);
        }
        System.out.println("MyClientReaderInterceptor --> " + baos.toString());
        
        ric.setInputStream(new ByteArrayInputStream(baos.toByteArray()));
        
        return ric.proceed();
    }
 
开发者ID:ftomassetti,项目名称:JavaIncrementalParser,代码行数:34,代码来源:MyClientReaderInterceptor.java

示例12: aroundReadFrom

import javax.ws.rs.ext.ReaderInterceptorContext; //导入方法依赖的package包/类
@Override
public Object aroundReadFrom(ReaderInterceptorContext ric) throws IOException, WebApplicationException {
    System.out.println("MyServerReaderInterceptor");
    final InputStream old = ric.getInputStream();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    int c;
    while ((c = old.read()) != -1) {
        baos.write(c);
    }
    System.out.println("MyClientReaderInterceptor --> " + baos.toString());
    
    ric.setInputStream(new ByteArrayInputStream(baos.toByteArray()));
    
    return ric.proceed();
}
 
开发者ID:ftomassetti,项目名称:JavaIncrementalParser,代码行数:16,代码来源:MyServerReaderInterceptor.java

示例13: aroundReadFrom

import javax.ws.rs.ext.ReaderInterceptorContext; //导入方法依赖的package包/类
@Override
public Object aroundReadFrom(ReaderInterceptorContext context)
        throws IOException, WebApplicationException {
    final InputStream originalInputStream = context.getInputStream();
    context.setInputStream(new GZIPInputStream(originalInputStream));
    return context.proceed();
}
 
开发者ID:williamwebb,项目名称:divide,代码行数:8,代码来源:GZIPReaderInterceptor.java

示例14: aroundReadFrom

import javax.ws.rs.ext.ReaderInterceptorContext; //导入方法依赖的package包/类
@Override
public Object aroundReadFrom(ReaderInterceptorContext context) throws IOException, WebApplicationException {
    // Validate if name bound or if CSRF property enabled and a POST
    final Method controller = resourceInfo.getResourceMethod();
    if (needsValidation(controller)) {

        CsrfToken token = csrfTokenManager.getToken()
                .orElseThrow(() -> new CsrfValidationException(messages.get("CsrfFailed", "missing token")));

        // First check if CSRF token is in header
        final String csrfToken = context.getHeaders().getFirst(token.getHeaderName());
        if (token.getValue().equals(csrfToken)) {
            return context.proceed();
        }

        // Otherwise, it must be a form parameter
        final MediaType contentType = context.getMediaType();
        if (!isSupportedMediaType(contentType)) {
            throw new CsrfValidationException(messages.get("UnableValidateCsrf", context.getMediaType()));
        }

        // Ensure stream can be restored for next interceptor
        ByteArrayInputStream bais;
        final InputStream is = context.getInputStream();
        if (is instanceof ByteArrayInputStream) {
            bais = (ByteArrayInputStream) is;
        } else {
            bais = copyStream(is);
        }

        // Validate CSRF
        boolean validated = false;
        final String charset = contentType.getParameters().get("charset");
        final String entity = toString(bais, charset != null ? charset : DEFAULT_CHARSET);
        final String[] pairs = entity.split("\\&");
        for (int i = 0; i < pairs.length; i++) {
            final String[] fields = pairs[i].split("=");
            final String nn = URLDecoder.decode(fields[0], DEFAULT_CHARSET);
            // Is this the CSRF field?
            if (token.getParamName().equals(nn)) {
                final String vv = URLDecoder.decode(fields[1], DEFAULT_CHARSET);
                // If so then check the token
                if (token.getValue().equals(vv)) {
                    validated = true;
                    break;
                }
                throw new CsrfValidationException(messages.get("CsrfFailed", "mismatching tokens"));
            }
        }
        if (!validated) {
            throw new CsrfValidationException(messages.get("CsrfFailed", "missing field"));
        }

        // Restore stream and proceed
        bais.reset();
        context.setInputStream(bais);
    }
    return context.proceed();
}
 
开发者ID:mvc-spec,项目名称:ozark,代码行数:60,代码来源:CsrfValidateInterceptor.java


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