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


Java ReaderInterceptorContext.setInputStream方法代码示例

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


在下文中一共展示了ReaderInterceptorContext.setInputStream方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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 List<String> header = context.getHeaders().get(HttpHeaders.CONTENT_ENCODING);
    if (header != null && header.contains("gzip")) {
        context.setInputStream(new GZIPInputStream(context.getInputStream()));
    }
    return context.proceed();
}
 
开发者ID:stevespringett,项目名称:Alpine,代码行数:9,代码来源:GZipInterceptor.java

示例8: aroundReadFrom

import javax.ws.rs.ext.ReaderInterceptorContext; //导入方法依赖的package包/类
@Override
public final Object aroundReadFrom(ReaderInterceptorContext context) throws IOException {
	if (isBase64(context)) {
		context.setInputStream(Base64.getDecoder().wrap(context.getInputStream()));
	}
	return context.proceed();
}
 
开发者ID:bbilger,项目名称:jrestless,代码行数:8,代码来源:ConditionalBase64ReadInterceptor.java

示例9: 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

示例10: aroundReadFrom

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

    String json = JsonStrings.inputStreamToString(context.getInputStream());
    JsonStrings.isNotNullOrEmpty(json);
    context.setInputStream(new ByteArrayInputStream(json.getBytes(Charset.forName("UTF-8"))));

    String jobId = uriInfo.getPathParameters().getFirst("jobId");
    Job job = jobManager.getJob(jobId).orElseThrow(NotFoundException::new);
    Class<? extends JobConfigurationModel> configurationModelType = getJobConfigurationModelClass(job.getJobConfiguration());
    context.setType(configurationModelType);
    context.setGenericType(configurationModelType);
    return context.proceed();

}
 
开发者ID:projectomakase,项目名称:omakase,代码行数:16,代码来源:PutJobConfigInterceptor.java

示例11: aroundReadFrom

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

    String json = JsonStrings.inputStreamToString(context.getInputStream());
    JsonStrings.isNotNullOrEmpty(json);
    context.setInputStream(new ByteArrayInputStream(json.getBytes(Charset.forName("UTF-8"))));

    String repositoryId = uriInfo.getPathParameters().getFirst("repositoryId");
    Class<? extends RepositoryConfiguration> configurationType = repositoryManager.getRepositoryConfigurationType(repositoryId);
    context.setType(configurationType);
    context.setGenericType(configurationType);
    return context.proceed();

}
 
开发者ID:projectomakase,项目名称:omakase,代码行数:15,代码来源:PutRepositoryConfigInterceptor.java

示例12: aroundReadFrom

import javax.ws.rs.ext.ReaderInterceptorContext; //导入方法依赖的package包/类
@Override
public Object aroundReadFrom(ReaderInterceptorContext context) throws IOException {
    Optional<Object> optionalBean = getCurrentObject();

    if (optionalBean.isPresent()) {
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

        // Currently assume the bean is of type BuiltResponse, this may need to change in the future
        Object bean = ((BuiltResponse) optionalBean.get()).getEntity();

        MessageBodyWriter<? super Object> bodyWriter = providers.getMessageBodyWriter(Object.class, bean.getClass(), new Annotation[0], MediaType.APPLICATION_JSON_TYPE);
        bodyWriter.writeTo(bean, bean.getClass(), bean.getClass(), new Annotation[0], MediaType.APPLICATION_JSON_TYPE, new MultivaluedHashMap<>(), outputStream);

        // Use the Jackson 2.x classes to convert both the incoming patch and the current state of the object into a JsonNode / JsonPatch
        ObjectMapper mapper = new ObjectMapper();
        JsonNode serverState = mapper.readValue(outputStream.toByteArray(), JsonNode.class);
        JsonNode patchAsNode = mapper.readValue(context.getInputStream(), JsonNode.class);
        JsonPatch patch = JsonPatch.fromJson(patchAsNode);

        try {
            JsonNode result = patch.apply(serverState);
            // Stream the result & modify the stream on the readerInterceptor
            ByteArrayOutputStream resultAsByteArray = new ByteArrayOutputStream();
            mapper.writeValue(resultAsByteArray, result);
            context.setInputStream(new ByteArrayInputStream(resultAsByteArray.toByteArray()));

            return context.proceed();

        } catch (JsonPatchException | JsonMappingException e) {
            throw new WebApplicationException(e.getMessage(), e, Response.status(Response.Status.BAD_REQUEST).build());
        }

    } else {
        throw new IllegalArgumentException("No matching GET method on resource");
    }
}
 
开发者ID:projectomakase,项目名称:omakase,代码行数:37,代码来源:JsonPatchInterceptor.java

示例13: aroundReadFrom

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

    String json = JsonStrings.inputStreamToString(context.getInputStream());
    JsonStrings.isNotNullOrEmpty(json);
    context.setInputStream(new ByteArrayInputStream(json.getBytes(Charset.forName("UTF-8"))));

    String locationId = uriInfo.getPathParameters().getFirst("locationId");
    Class<? extends LocationConfiguration> configurationType = locationManager.getLocationConfigurationType(locationId);
    context.setType(configurationType);
    context.setGenericType(configurationType);
    return context.proceed();

}
 
开发者ID:projectomakase,项目名称:omakase,代码行数:15,代码来源:PutLocationConfigInterceptor.java

示例14: 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

示例15: 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


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