use of org.apache.cxf.interceptor.StaxInEndingInterceptor in project cxf by apache.
the class XMLStreamDataReader method resetForStreaming.
private XMLStreamReader resetForStreaming(XMLStreamReader input) throws XMLStreamException {
// is not closed and additional parts are not read and such
if (message != null) {
if (message.getInterceptorChain() != null) {
message.getInterceptorChain().remove(StaxInEndingInterceptor.INSTANCE);
message.getInterceptorChain().add(new StaxInEndingInterceptor(Phase.POST_INVOKE));
}
message.removeContent(XMLStreamReader.class);
final InputStream ins = message.getContent(InputStream.class);
message.removeContent(InputStream.class);
return new FragmentStreamReader(input, true) {
boolean closed;
public boolean hasNext() throws XMLStreamException {
boolean b = super.hasNext();
if (!b && !closed) {
close();
}
return b;
}
public void close() throws XMLStreamException {
closed = true;
try {
super.close();
} catch (XMLStreamException e) {
// ignore
}
if (ins != null) {
try {
ins.close();
} catch (IOException e) {
// ignore
}
}
}
};
}
return input;
}
Aggregations