我能够通过使用
Flux#collect和使它工作
SequenceInputStream
@Overridepublic Mono<T> extract(ClientHttpResponse response, BodyExtractor.Context context) { Flux<DataBuffer> body = response.getBody(); return body.collect(InputStreamCollector::new, (t, dataBuffer)-> t.collectInputStream(dataBuffer.asInputStream)) .map(inputStream -> { try { JaxBContext jc = JaxBContext.newInstance(SomeClass.class); Unmarshaller unmarshaller = jc.createUnmarshaller(); return (T) unmarshaller.unmarshal(inputStream); } catch(Exception e){ return null; } }).next();}
InputStreamCollector.java
public class InputStreamCollector { private InputStream is; public void collectInputStream(InputStream is) { if (this.is == null) this.is = is; this.is = new SequenceInputStream(this.is, is); } public InputStream getInputStream() { return this.is; }}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)