Search in sources :

Example 1 with StaxInEndingInterceptor

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;
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) InputStream(java.io.InputStream) StaxInEndingInterceptor(org.apache.cxf.interceptor.StaxInEndingInterceptor) FragmentStreamReader(org.apache.cxf.staxutils.FragmentStreamReader) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 StaxInEndingInterceptor (org.apache.cxf.interceptor.StaxInEndingInterceptor)1 FragmentStreamReader (org.apache.cxf.staxutils.FragmentStreamReader)1