[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: XML parsing problems

From: Per Bothner
Subject: Re: XML parsing problems
Date: Sun, 25 Dec 2005 07:54:04 -0800
User-agent: Mozilla Thunderbird 1.0.6-1.1.fc4 (X11/20050720)

Chris Burdess wrote:
As I understand it, the problem can occur when the position in the buffer is
near the end. If the mark is set at position 2047 in the buffer, then we read
2 bytes and reset, then refill() will have been called and the position is
actually reset to position 2047 in the new buffer, 2K further along in the
original stream.
If anyone has a robust solution to this problem please apply it; I will try
to address it but may not have much free time before the new year/release.

Three choices, assuming the mark is active and at position M
in a buffer of size S:
(1) Move S-M bytes to the start of the buffer and read upto M bytes.
Advantage: doesn't need to grow the buffer.
Disadvantage: we lose buffer alignment, which probably doesn't matter
except with a highly tuned (an nio-based?) implementation.
Also, can fail if the readAheadLimit > S.
(2) Grow the buffer to S+(S-M).
Disadvantage: Same alignment issue as (1).
(3) Use two buffers, one old and a new buffer.  The old buffer doesn't
need to be full-size, as long as it can handle the readAheadLimit
(in the general case) or at least S-M in this case.
Advantage: Preserves alignment.
Disadvantage: More complex.  After a reset, then a read(byte[],int, int)
will only get S-M bytes.

Assuming buffer alignment isn't an issue, then I'd say use a combination
of (1) if possible and (2) if needed.
        --Per Bothner

reply via email to

[Prev in Thread] Current Thread [Next in Thread]