Skip to content
This repository has been archived by the owner on Jan 22, 2019. It is now read-only.

Commit

Permalink
Merge pull request #19 from philipa/master
Browse files Browse the repository at this point in the history
Fix reported location after non-stream input has been parsed.
  • Loading branch information
cowtowncoder committed Feb 1, 2016
2 parents a1432ca + 584bc92 commit 341869d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2841,9 +2841,9 @@ private final int _decodeChunkedUTF8_4(int c) throws IOException

protected final boolean loadMore() throws IOException
{
_currInputProcessed += _inputEnd;

if (_inputStream != null) {
_currInputProcessed += _inputEnd;

int count = _inputStream.read(_inputBuffer, 0, _inputBuffer.length);
if (count > 0) {
_inputPtr = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,34 @@ private void _testMedium(int len) throws Exception
p.close();
}

public void testCurrentLocationByteOffset() throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
CBORGenerator gen = cborGenerator(out);
gen.writeString("1234567890");
gen.writeString("1234567890");
gen.close();

final byte[] b = out.toByteArray();

JsonParser p = cborParser(b);

assertToken(JsonToken.VALUE_STRING, p.nextToken());
assertEquals(1, p.getCurrentLocation().getByteOffset());
p.getText(); // fully read token.
assertEquals(11, p.getCurrentLocation().getByteOffset());

assertToken(JsonToken.VALUE_STRING, p.nextToken());
assertEquals(12, p.getCurrentLocation().getByteOffset());
p.getText();
assertEquals(22, p.getCurrentLocation().getByteOffset());

assertNull(p.nextToken());
assertEquals(22, p.getCurrentLocation().getByteOffset());

p.close();
assertEquals(22, p.getCurrentLocation().getByteOffset());
}

public void testLongNonChunkedText() throws Exception
{
ByteArrayOutputStream out = new ByteArrayOutputStream();
Expand Down

0 comments on commit 341869d

Please sign in to comment.