下面列出了javax.ws.rs.ext.ReaderInterceptorContext#getInputStream ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public Object aroundReadFrom(final ReaderInterceptorContext readerInterceptorCtx) throws IOException {
final InputStream old = readerInterceptorCtx.getInputStream();
readerInterceptorCtx.setInputStream(new UpperCaseInputStream(old));
try {
return readerInterceptorCtx.proceed();
} finally {
readerInterceptorCtx.setInputStream(old);
}
}
@Override
public Object aroundReadFrom(ReaderInterceptorContext context) throws IOException, WebApplicationException {
final List<String> header = context.getHeaders().get(HttpHeaders.CONTENT_ENCODING);
if (header != null && header.contains("gzip")) {
// DO NOT CLOSE STREAMS
final InputStream contentInputSteam = context.getInputStream();
final GZIPInputStream gzipInputStream = new GZIPInputStream(contentInputSteam);
context.setInputStream(gzipInputStream);
}
return context.proceed();
}
@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();
}
@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();
}
@Override
public Object aroundReadFrom(ReaderInterceptorContext context)
throws IOException, WebApplicationException {
final InputStream originalInputStream = context.getInputStream();
context.setInputStream(new GZIPInputStream(originalInputStream));
return context.proceed();
}
@Override
public Object aroundReadFrom(ReaderInterceptorContext ctx) throws IOException, WebApplicationException {
BufferedReader br = new BufferedReader(new InputStreamReader(ctx.getInputStream()));
String line;
while ((line = br.readLine()) != null) {
LOG.info("readLine: " + line);
}
ByteArrayInputStream bais = new ByteArrayInputStream("value=MODIFIED".getBytes());
LOG.info("set value=MODIFIED");
ctx.setInputStream(bais);
return ctx.proceed();
}
@Override
public Object aroundReadFrom(ReaderInterceptorContext context) throws IOException,
WebApplicationException {
if (context.getInputStream() != null) {
context.getHeaders().add("ClientReaderInterceptor", "clientRead");
}
return context.proceed();
}
@Override
public Object aroundReadFrom(ReaderInterceptorContext context) throws IOException, WebApplicationException {
LOG.info("Request reader interceptor in the server side");
InputStream is = context.getInputStream();
String body = new BufferedReader(new InputStreamReader(is)).lines()
.collect(Collectors.joining("\n"));
context.setInputStream(new ByteArrayInputStream((body + " message added in server reader interceptor").getBytes()));
return context.proceed();
}
@Override
public Object aroundReadFrom(ReaderInterceptorContext context)
throws IOException, WebApplicationException {
List<String> ce = context.getHeaders().get("content-encoding");
if (ce != null && ce.contains("gzip")) {
final InputStream originalInputStream = context.getInputStream();
context.setInputStream(new GZIPInputStream(originalInputStream));
}
return context.proceed();
}