Search in sources :

Example 1 with BAAInputStream

use of org.apache.axiom.attachments.utils.BAAInputStream in project webservices-axiom by apache.

the class DetachableInputStream method detach.

/**
 * Consume the input stream and close it.
 * The bytes in the input stream are buffered.
 * (Thus the original input stream can release its
 * resources, but the consumer of the stream can
 * still receive data).
 * @throws IOException
 */
public void detach() throws IOException {
    if (localStream == null && !isClosed) {
        BAAOutputStream baaos = new BAAOutputStream();
        try {
            // It is possible that the underlying stream was closed
            BufferUtils.inputStream2OutputStream(in, baaos);
            super.close();
        } catch (Throwable t) {
            if (log.isDebugEnabled()) {
                log.debug("detach caught exception.  Processing continues:" + t);
                log.debug("  " + stackToString(t));
            }
        } finally {
            // GC the incoming stream
            in = null;
        }
        localStream = new BAAInputStream(baaos.buffers(), baaos.length());
        if (log.isDebugEnabled()) {
            log.debug("The local stream built from the detached " + "stream has a length of:" + baaos.length());
        }
        count = count + baaos.length();
    }
}
Also used : BAAInputStream(org.apache.axiom.attachments.utils.BAAInputStream) BAAOutputStream(org.apache.axiom.attachments.utils.BAAOutputStream)

Example 2 with BAAInputStream

use of org.apache.axiom.attachments.utils.BAAInputStream in project webservices-axiom by apache.

the class ParserInputStreamDataSource method copy.

/**
 * Return a InputStreamDataSource backed by a ByteArrayInputStream
 */
@Override
public OMDataSourceExt copy() {
    if (log.isDebugEnabled()) {
        log.debug("Enter ParserInputStreamDataSource.copy()");
    }
    try {
        BAAOutputStream baaos = new BAAOutputStream();
        BufferUtils.inputStream2OutputStream(data.readParserInputStream(), baaos);
        BAAInputStream baais = new BAAInputStream(baaos.buffers(), baaos.length());
        if (log.isDebugEnabled()) {
            log.debug("Exit ParserInputStreamDataSource.copy()");
        }
        return new ParserInputStreamDataSource(baais, data.encoding, data.behavior);
    } catch (Throwable t) {
        if (log.isDebugEnabled()) {
            log.debug("Error ParserInputStreamDataSource.copy(): ", t);
        }
        throw new OMException(t);
    }
}
Also used : BAAInputStream(org.apache.axiom.attachments.utils.BAAInputStream) OMException(org.apache.axiom.om.OMException) BAAOutputStream(org.apache.axiom.attachments.utils.BAAOutputStream)

Aggregations

BAAInputStream (org.apache.axiom.attachments.utils.BAAInputStream)2 BAAOutputStream (org.apache.axiom.attachments.utils.BAAOutputStream)2 OMException (org.apache.axiom.om.OMException)1