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

Commit 341869d

Browse files
committed
Merge pull request #19 from philipa/master
Fix reported location after non-stream input has been parsed.
2 parents a1432ca + 584bc92 commit 341869d

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/main/java/com/fasterxml/jackson/dataformat/cbor/CBORParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2841,9 +2841,9 @@ private final int _decodeChunkedUTF8_4(int c) throws IOException
28412841

28422842
protected final boolean loadMore() throws IOException
28432843
{
2844-
_currInputProcessed += _inputEnd;
2845-
28462844
if (_inputStream != null) {
2845+
_currInputProcessed += _inputEnd;
2846+
28472847
int count = _inputStream.read(_inputBuffer, 0, _inputBuffer.length);
28482848
if (count > 0) {
28492849
_inputPtr = 0;

src/test/java/com/fasterxml/jackson/dataformat/cbor/ParserSimpleTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,34 @@ private void _testMedium(int len) throws Exception
240240
p.close();
241241
}
242242

243+
public void testCurrentLocationByteOffset() throws Exception {
244+
ByteArrayOutputStream out = new ByteArrayOutputStream();
245+
CBORGenerator gen = cborGenerator(out);
246+
gen.writeString("1234567890");
247+
gen.writeString("1234567890");
248+
gen.close();
249+
250+
final byte[] b = out.toByteArray();
251+
252+
JsonParser p = cborParser(b);
253+
254+
assertToken(JsonToken.VALUE_STRING, p.nextToken());
255+
assertEquals(1, p.getCurrentLocation().getByteOffset());
256+
p.getText(); // fully read token.
257+
assertEquals(11, p.getCurrentLocation().getByteOffset());
258+
259+
assertToken(JsonToken.VALUE_STRING, p.nextToken());
260+
assertEquals(12, p.getCurrentLocation().getByteOffset());
261+
p.getText();
262+
assertEquals(22, p.getCurrentLocation().getByteOffset());
263+
264+
assertNull(p.nextToken());
265+
assertEquals(22, p.getCurrentLocation().getByteOffset());
266+
267+
p.close();
268+
assertEquals(22, p.getCurrentLocation().getByteOffset());
269+
}
270+
243271
public void testLongNonChunkedText() throws Exception
244272
{
245273
ByteArrayOutputStream out = new ByteArrayOutputStream();

0 commit comments

Comments
 (0)