Search in sources :

Example 1 with CloseShieldReader

use of org.apache.commons.io.input.CloseShieldReader in project exist by eXist-db.

the class MutableCollection method closeShieldInputSource.

/**
 * Creates a new InputSource that prevents the streams
 * and readers of the InputSource from being closed.
 *
 * @param source the input source
 *
 * @return a new input source
 */
private InputSource closeShieldInputSource(final InputSource source) {
    final InputSource protectedInputSource = new InputSource();
    protectedInputSource.setEncoding(source.getEncoding());
    protectedInputSource.setSystemId(source.getSystemId());
    protectedInputSource.setPublicId(source.getPublicId());
    if (source.getByteStream() != null) {
        // TODO(AR) consider AutoCloseInputStream
        final InputStream closeShieldByteStream = CloseShieldInputStream.wrap(source.getByteStream());
        protectedInputSource.setByteStream(closeShieldByteStream);
    }
    if (source.getCharacterStream() != null) {
        // TODO(AR) consider AutoCloseReader
        final Reader closeShieldReader = CloseShieldReader.wrap(source.getCharacterStream());
        protectedInputSource.setCharacterStream(closeShieldReader);
    }
    return protectedInputSource;
}
Also used : InputSource(org.xml.sax.InputSource) CloseShieldInputStream(org.apache.commons.io.input.CloseShieldInputStream) UnsynchronizedByteArrayInputStream(org.apache.commons.io.input.UnsynchronizedByteArrayInputStream) CloseShieldReader(org.apache.commons.io.input.CloseShieldReader) XMLReader(org.xml.sax.XMLReader)

Aggregations

CloseShieldInputStream (org.apache.commons.io.input.CloseShieldInputStream)1 CloseShieldReader (org.apache.commons.io.input.CloseShieldReader)1 UnsynchronizedByteArrayInputStream (org.apache.commons.io.input.UnsynchronizedByteArrayInputStream)1 InputSource (org.xml.sax.InputSource)1 XMLReader (org.xml.sax.XMLReader)1