On 05/13/2011 12:10 AM, Asankha C. Perera wrote:
I'm seeing the exception being thrown from the decoder and being handled, and being thrown and somehow not getting caught properly - intermittently.. Have been trying to nail the exact issue, but I need a bit more time. Any ideas?
Hi Oleg

The problem seems to be like this.. I have a ContentListener implementation, and from its contentAvailable() the following gets invoked.

                transferred = fileChannel.transferFrom(
new ContentDecoderChannel(decoder), idx, Integer.MAX_VALUE);

Looking at the Java source below, it seems like the IOException is propagated only when "tw" is > 0 .. I do not understand why they do that..

regards
asankha

private static final int TRANSFER_SIZE = 8192;

    private long transferFromArbitraryChannel(ReadableByteChannel src,
                                              long position, long count)
        throws IOException
    {
        // Untrusted target: Use a newly-erased buffer
        int c = (int)Math.min(count, TRANSFER_SIZE);
        ByteBuffer bb = Util.getTemporaryDirectBuffer(c);
        long tw = 0;                    // Total bytes written
        long pos = position;
        try {
            Util.erase(bb);
            while (tw < count) {
                bb.limit(Math.min((int)(count - tw), TRANSFER_SIZE));
                // ## Bug: Will block reading src if this channel
                // ##      is asynchronously closed
                int nr = src.read(bb);
                if (nr <= 0)
                    break;
                bb.flip();
                int nw = write(bb, pos);
                tw += nw;
                if (nw != nr)
                    break;
                pos += nw;
                bb.clear();
            }
            return tw;
        } catch (IOException x) {
            if (tw > 0)
                return tw;
            throw x;
        } finally {
            Util.releaseTemporaryDirectBuffer(bb);
        }
    }

--

Asankha C. Perera
AdroitLogic, http://adroitlogic.org

http://esbmagic.blogspot.com





---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to