Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AsyncXMLStreamReader#getLocationInfo().getEndingCharOffset() always -1 #57

Closed
sco0ter opened this issue Mar 28, 2018 · 3 comments
Closed

Comments

@sco0ter
Copy link

sco0ter commented Mar 28, 2018

The following is always -1:

AsyncXMLStreamReader#getLocationInfo().getEndingCharOffset() == -1
AsyncXMLStreamReader#getLocationInfo().getStartingCharOffset() == -1

although there are definitively characters, the byte offset is correct:

AsyncXMLStreamReader#getLocationInfo().getEndingByteOffset() == 686

Please note that character offset may be different from byte offset, e.g. when using Emojis in the XML (surrogate pairs)

(version 1.0.0)

@cowtowncoder
Copy link
Member

That is expected behavior since only one of char/byte variants will ever provide actual information.
Type depends on input source itself: when given byte source like InputStream, only byte offsets are available; when char source like Reader, char offsets.
Async readers are always byte-based so only byte offsets are available.

The reason for this is because of costs involved in keeping accurate offsets -- native offset (byte or char) is needed for decoding, with little to no additional, but the "other" offset is either expensive to obtain (re-encoding to go from char to byte), or would need to be kept track on unit-by-unit basis (since decoding of char from byte is not separate step but integral part of processing from byte stream to tokens).

In case of async parsing, then, the only way to find character offsets would be for caller to keep track of buffers and then decode on as-needed basis.

@sco0ter
Copy link
Author

sco0ter commented Mar 30, 2018

Thanks for your explanation. You are right, probably to costly to have that feature by default.

@cowtowncoder
Copy link
Member

@sco0ter Processing overhead is part of it, but keeping track would add a lot to complexity unfortunately. If there was a modular way to do it that'd be possible but... unfortunately no, at least the way implementation works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants